ali-dashscope-provider
v0.1.3
Published
Alibaba DashScope (Qwen) provider for Vercel AI SDK
Maintainers
Readme
ali-dashscope-provider
Alibaba DashScope (Qwen) provider for the Vercel AI SDK.
Installation
npm install ali-dashscope-providerSetup
The provider uses the Alibaba DashScope API. You can get an API key here.
Set the environment variable:
export API_KEY=your_api_keyUsage
import { qwen } from 'ali-dashscope-provider';
import { generateText } from 'ai';
const { text } = await generateText({
model: qwen('qwen-max'),
prompt: 'Hello, how can you help me today?',
});
console.log(text);Streaming
import { qwen } from 'ali-dashscope-provider';
import { streamText } from 'ai';
const result = await streamText({
model: qwen('qwen-plus'),
prompt: 'Write a short story about AI.',
});
for await (const textPart of result.textStream) {
process.stdout.write(textPart);
}Tool Calling
Supports Vercel AI SDK tool calling syntax:
import { qwen } from 'ali-dashscope-provider';
import { generateText, tool } from 'ai';
import { z } from 'zod';
const result = await generateText({
model: qwen('qwen-max'),
tools: {
getWeather: tool({
description: 'Get weather in a city',
parameters: z.object({ city: z.string() }),
execute: async ({ city }) => ({ city, temperature: 25 }),
}),
},
prompt: 'What is the weather in Shanghai?',
});Models
qwen-max(Recommended for complex tasks)qwen-plus(Balanced performance)qwen-turbo(Fast and cost-effective)- Or any other valid model ID from DashScope.
License
Apache-2.0
