Integrate Cohere language models into your application using Vercel's AI SDK. Supports text generation with Cohere's command models for natural language tasks.
Integrate Cohere's language models into your application using the Vercel AI SDK Cohere provider. This skill enables you to use Cohere's command models for text generation and natural language processing tasks.
This skill helps you set up and use the Cohere provider with Vercel's AI SDK, enabling access to Cohere's language models like command-r-plus for tasks such as text generation, question answering, and content creation.
Install the Cohere provider package:
```bash
npm install @ai-sdk/cohere
```
If not already installed, install the core AI SDK:
```bash
npm install ai
```
Add your Cohere API key to your environment variables:
```bash
COHERE_API_KEY=your_cohere_api_key_here
```
In your TypeScript/JavaScript file, import the Cohere provider:
```typescript
import { cohere } from '@ai-sdk/cohere';
import { generateText } from 'ai';
```
Generate text using Cohere models:
```typescript
const { text } = await generateText({
model: cohere('command-r-plus'),
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});
console.log(text);
```
Common Cohere models you can use:
Specify the model in the `cohere()` function:
```typescript
const model = cohere('command-r-plus');
```
Stream responses for real-time output:
```typescript
import { streamText } from 'ai';
const { textStream } = await streamText({
model: cohere('command-r-plus'),
prompt: 'Explain quantum computing in simple terms.',
});
for await (const chunk of textStream) {
process.stdout.write(chunk);
}
```
Configure additional parameters:
```typescript
const { text } = await generateText({
model: cohere('command-r-plus'),
prompt: 'Your prompt here',
temperature: 0.7,
maxTokens: 500,
});
```
**Simple Text Generation:**
```typescript
import { cohere } from '@ai-sdk/cohere';
import { generateText } from 'ai';
const { text } = await generateText({
model: cohere('command-r'),
prompt: 'List 5 benefits of regular exercise.',
});
```
**Chat Completion:**
```typescript
import { generateText } from 'ai';
const { text } = await generateText({
model: cohere('command-r-plus'),
messages: [
{ role: 'user', content: 'What is the capital of France?' },
{ role: 'assistant', content: 'The capital of France is Paris.' },
{ role: 'user', content: 'What is its population?' }
],
});
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/ai-sdk-cohere-provider-integration/raw