aliyun-qwen-sdk
v1.0.5
Published
Alibaba Cloud Qwen SDK based on Vercel AI SDK
Readme
aliyun-qwen-sdk
Alibaba Cloud Qwen SDK based on Vercel AI SDK.
安装
npm install aliyun-qwen-sdk环境配置
在使用之前,需要设置阿里云 DashScope API Key:
export DASHSCOPE_API_KEY=your-api-key或者在代码中设置:
process.env.DASHSCOPE_API_KEY = 'your-api-key';获取 API Key: https://dashscope.console.aliyun.com/
快速开始
基础文本调用
import { callAI } from 'aliyun-qwen-sdk';
const result = await callAI('你好,请介绍一下你自己');
console.log(result.text);
console.log(result.meta);指定模型
import { callAI, textModels } from 'aliyun-qwen-sdk';
const result = await callAI('你好', {
model: 'qwen-max',
temperature: 0.7,
});多模态输入(图片)
import { callAI } from 'aliyun-qwen-sdk';
const result = await callAI({
prompt: '描述这张图片的内容',
images: ['https://example.com/image.jpg'],
});
console.log(result.text);结构化 JSON 输出
import { callAIJSON } from 'aliyun-qwen-sdk';
import { z } from 'zod';
const schema = z.object({
name: z.string(),
age: z.number(),
skills: z.array(z.string()),
});
const result = await callAIJSON(
schema,
'请生成一个名为张三、25岁、擅长 TypeScript 和 Python 的人物信息'
);
console.log(result.text.name); // "张三"
console.log(result.text.age); // 25
console.log(result.text.skills); // ["TypeScript", "Python"]API
callAI
纯文本或多模态调用。
function callAI<T extends AIInput = string>(
input: T,
options?: CallOptions
): Promise<CallResult<string>>参数:
input: 字符串或{ prompt: string; images: string[] }options: 可选配置model: 指定模型temperature: 温度参数 (0-1)maxTokens: 最大 token 数
返回:
{
text: string;
meta: {
model: string;
finishReason: string;
usage?: {
promptTokens: number;
completionTokens: number;
totalTokens: number;
};
};
}callAIJSON
结构化 JSON 输出。
function callAIJSON<T extends z.ZodType>(
schema: T,
input: AIInput,
options?: CallOptions
): Promise<CallResult<z.infer<T>>>可用模型
文本模型
| 模型 | 描述 |
|------|------|
| qwen-turbo | 快速响应 |
| qwen-plus | 平衡性能 |
| qwen-max | 最强性能 |
| qwen-max-longcontext | 长文本 |
| qwen3.6-plus | Qwen3 平衡性能 (默认) |
| qwen3.6-max | Qwen3 最强性能 |
多模态模型
| 模型 | 描述 |
|------|------|
| qwen-vl-plus | 视觉理解 |
| qwen-vl-max | 最强视觉 |
| qwen3-vl-plus | Qwen3 视觉理解 (默认) |
| qwen3-vl-max | Qwen3 最强视觉 |
类型导出
import {
callAI,
callAIJSON,
textModels,
multimodalModels,
defaults,
type TextModel,
type MultimodalModel,
type ModelName,
type CallOptions,
type CallResult,
type AIInput,
} from 'aliyun-qwen-sdk';许可证
MIT
