Install and configure @langchain/cohere package for LangChain.js applications. Supports ChatCohere models, streaming, and CohereEmbeddings with proper dependency management.
Install and configure the @langchain/cohere package for integrating Cohere AI models with LangChain.js applications.
This skill helps you set up the @langchain/cohere package in your JavaScript/TypeScript project. It handles package installation, dependency resolution to avoid version conflicts, and provides code examples for:
1. Verify this is a Node.js/JavaScript project by looking for `package.json`
2. Read the `package.json` to understand the current dependency structure
3. Check if `@langchain/core` or `@langchain/cohere` is already installed
1. Install the required packages:
```bash
npm install @langchain/cohere @langchain/core
```
2. If other LangChain packages are present, add dependency resolution fields to `package.json` to ensure all packages use the same `@langchain/core` version:
- Add `resolutions` field (for yarn)
- Add `overrides` field (for npm)
- Add `pnpm.overrides` field (for pnpm)
Example structure:
```json
{
"resolutions": {
"@langchain/core": "0.3.0"
},
"overrides": {
"@langchain/core": "0.3.0"
},
"pnpm": {
"overrides": {
"@langchain/core": "0.3.0"
}
}
}
```
1. Check for `.env`, `.env.local`, or similar environment files
2. Add or verify the `COHERE_API_KEY` variable:
```
COHERE_API_KEY=your-api-key
```
3. If no env file exists, inform the user they need to set the environment variable
Offer the user code examples based on their needs:
**Chat Model Example:**
```typescript
import { HumanMessage } from "@langchain/core/messages";
import { ChatCohere } from "@langchain/cohere";
const model = new ChatCohere({
apiKey: process.env.COHERE_API_KEY,
});
const response = await model.invoke([new HumanMessage("Hello world!")]);
```
**Streaming Example:**
```typescript
import { HumanMessage } from "@langchain/core/messages";
import { ChatCohere } from "@langchain/cohere";
const model = new ChatCohere({
apiKey: process.env.COHERE_API_KEY,
});
const response = await model.stream([new HumanMessage("Hello world!")]);
```
**Embeddings Example:**
```typescript
import { CohereEmbeddings } from "@langchain/cohere";
const embeddings = new CohereEmbeddings({
apiKey: process.env.COHERE_API_KEY,
});
const res = await embeddings.embedQuery("Hello world");
```
1. After installation, check that the packages appear in `package.json` dependencies
2. Optionally run `npm list @langchain/cohere @langchain/core` to verify versions
3. Confirm the environment variable is properly configured
User: "Install @langchain/cohere for my project"
User: "Set up Cohere chat model with streaming"
User: "Add Cohere embeddings to my LangChain app"
User: "Help me integrate Cohere with LangChain"
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/langchaincohere-integration/raw