阿里云模型服务灵积(Dashscope)Spring AI 集成模型
客户端/模型版本 | Spring AI 版本 |
---|---|
1.1.x |
0.8.1 |
>= 1.3.x |
1.0.0 |
需要阿里云模型服务灵积的 API Key,设置为环境变量
DASHSCOPE_API_KEY
。
添加 Maven 依赖
<dependency>
<groupId>io.github.alexcheng1982</groupId>
<artifactId>spring-ai-dashscope-client</artifactId>
<version>VERSION</version>
</dependency>
使用:
var model = DashscopeChatModel.createDefault();
var response = model.call("hello");
ChatModel
StreamingChatModel
EmbeddingModel
- 方法调用
- 多模态输入,图片和音频
添加 Spring Boot Starter 的依赖:
<dependency>
<groupId>io.github.alexcheng1982</groupId>
<artifactId>spring-ai-dashscope-spring-boot-starter</artifactId>
<version>VERSION</version>
</dependency>
会自动创建一个 ChatModel
类型的 Bean 和一个 EmbeddingModel
类型的 Bean。默认的 ChatOptions
可以通过配置项 spring.ai.dashscope.chat.options
来配置。默认的 EmbeddingOptions
可以通过配置项
spring.ai.dashscope.embedding.options
来配置。
spring:
ai:
dashscope:
chat:
options:
model: qwen-plus
temperature: 0.2
embedding:
options:
model: text-embedding-v2
可以参考代码示例。