【springboot集成各类大模型】支持讯飞星火、通义千问、ChatGPT、和DeepSeek等

AI大模型SDK,支持多种大模型服务的统一接入,包括讯飞星火、通义千问、ChatGPT、和DeepSeek等。

GitHub地址:https://github.com/jeesoul/jeesoul-ai-model

xml 复制代码
<!--建议引入中央仓库地址-->
<repositories>
    <repository>
        <id>central</id>
        <url>https://repo.maven.apache.org/maven2/</url>
    </repository>
</repositories>

<dependencies>
<!--已发布到 maven 中央仓库 目前最新版: 1.0.3-->
<dependency>
    <groupId>com.jeesoul</groupId>
    <artifactId>jeesoul-ai-model</artifactId>
    <version>1.0.3</version>
</dependency>

<!--集成响应式编程-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
</dependencies>

功能特性

  • 支持多种大模型服务统一接入
  • 提供同步和流式两种对话模式
  • 支持参数透传和自定义配置
  • 统一的异常处理和日志记录
  • 支持系统提示词和思考模式
  • 基于Spring Boot的自动配置

模型支持

模型名称 枚举值
讯飞星火 spark
ChatGPT chatgpt
通义千问 qWen
DeepSeek deepSeek

application.yml中添加配置:

yml 复制代码
ai:
  qwen:
    api-key: your-api-key
    endpoint: https://api.qwen.com/v1/chat/completions
  spark:
    api-key: your-api-key
    endpoint: https://api.spark.com/v1/chat/completions
  deep-seek:
    api-key: your-api-key
    endpoint: https://api.deepseek.com/v1/chat/completions

使用

同步对话

参数说明

ModelRequestVO

参数名 类型 是否必填 说明
modelName String 模型名称(qWen/chatgpt/spark/deepSeek)
model String 具体模型版本
systemPrompt String 系统提示词
prompt String 用户提示词
enableThinking boolean 是否开启思考模式 (支持QWen系列快、慢思考)
params Map<String,Object> 自定义参数

ModelResponseVO

参数名 类型 说明
result String 返回结果
thinking Boolean 思考过程(如果启用)
model String 模型名称
java 复制代码
public void chat() {
    // 非必填参数 创建请求对象(使用链式调用)
    Map<String, Object> params = new HashMap<>();
    params.put("temperature", 0.7);
    params.put("top_p", 0.9);
    params.put("max_tokens", 2000);
    
    ModelRequestVO request = new ModelRequestVO()
        .setModelName("qWen")  // 或 "spark", "deepSeek"
        .setModel("qwen-turbo")  // 具体模型版本
        .setPrompt("你好,请介绍一下自己")
        .setParams(params);
    
    // 获取服务实例并调用
    AiService aiService = FactoryModelService.create(request.getModelName());
    ModelResponseVO response = aiService.httpChat(request);
    System.out.println(response.getResult());
}

流式对话

java 复制代码
public void streamChat() {
    // 使用链式调用创建请求对象
    ModelRequestVO request = new ModelRequestVO()
        .setModelName("spark")
        .setModel("x1")
        .setPrompt("写一首诗");
    
    AiService aiService = FactoryModelService.create(request.getModelName());
    
    // 方式1:获取ModelResponseVO流
    Flux<ModelResponseVO> responseFlux = aiService.streamChat(request);
    responseFlux.subscribe(response -> {
        System.out.println(response.getResult());
        if (response.getThinking() != null) {
            System.out.println("思考过程:" + response.getThinking());
        }
    });
    
    // 方式2:获取原始文本流
    Flux<String> textFlux = aiService.streamChatStr(request);
    textFlux.subscribe(System.out::println);
}
相关推荐
AI科技星几秒前
全域数学视角下N维广义数系的推广与本源恒等式构建【乖乖数学】
人工智能·机器学习·数学建模·数据挖掘
qcx232 分钟前
拆解 Warp AI Agent(二):风险分级执行——Agent 如何做到安全并行、危险排队
人工智能·安全·ai·agent·源码解析·warp
小白蒋博客3 分钟前
【ai开发段永平投资理财的知识图谱网站】第一天:搭 Vite + Vue 项目,跑通 Hello World
vue.js·人工智能·trae
MediaTea4 分钟前
人工智能通识课:Scikit-learn 机器学习工具库
人工智能·python·机器学习·scikit-learn
AI木马人6 分钟前
13.人工智能实战:RAG 多轮对话越问越偏?Query Rewrite、历史压缩与会话记忆的工程化方案
人工智能·搜索引擎
a1117767 分钟前
QQ 宠物(怀旧 开源)前端electron项目
前端·开源·html
郝学胜-神的一滴8 分钟前
二分类任务核心:BCE 损失函数从原理到 PyTorch 实战
人工智能·pytorch·python·算法·机器学习·分类·数据挖掘
财经资讯数据_灵砚智能12 分钟前
基于全球经济类多源新闻的NLP情感分析与数据可视化(日间)2026年5月2日
人工智能·python·信息可视化·自然语言处理·ai编程
sali-tec13 分钟前
C# 基于OpenCv的视觉工作流-章58-相机标定
图像处理·人工智能·数码相机·opencv·算法·计算机视觉
一水鉴天14 分钟前
同构异质三表总装体系确立与入表机制闭环验证 20260502(腾讯元宝)
人工智能·算法·机器学习