【代码评审】AI:讯飞星火的接入调整

This commit is contained in:
YunaiV 2024-05-18 10:15:40 +08:00
parent 04021ce068
commit 645dfae003
18 changed files with 72 additions and 66 deletions

View File

@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum;
import org.springframework.ai.chat.ChatClient; import org.springframework.ai.chat.ChatClient;
import org.springframework.ai.chat.StreamingChatClient; import org.springframework.ai.chat.StreamingChatClient;
import org.springframework.ai.models.tongyi.QianWenChatClient; import org.springframework.ai.models.tongyi.QianWenChatClient;
import org.springframework.ai.models.xinghuo.XingHuoChatClient; import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoChatClient;
import cn.iocoder.yudao.framework.ai.core.model.yiyan.YiYanChatClient; import cn.iocoder.yudao.framework.ai.core.model.yiyan.YiYanChatClient;
import org.springframework.ai.ollama.OllamaChatClient; import org.springframework.ai.ollama.OllamaChatClient;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -27,7 +27,7 @@ public class AiChatClientFactory {
public ChatClient getChatClient(AiPlatformEnum platformEnum) { public ChatClient getChatClient(AiPlatformEnum platformEnum) {
if (AiPlatformEnum.QIAN_WEN == platformEnum) { if (AiPlatformEnum.QIAN_WEN == platformEnum) {
return applicationContext.getBean(QianWenChatClient.class); return applicationContext.getBean(QianWenChatClient.class);
} else if (AiPlatformEnum.YIYAN == platformEnum) { } else if (AiPlatformEnum.YI_YAN == platformEnum) {
return applicationContext.getBean(YiYanChatClient.class); return applicationContext.getBean(YiYanChatClient.class);
} else if (AiPlatformEnum.XING_HUO == platformEnum) { } else if (AiPlatformEnum.XING_HUO == platformEnum) {
return applicationContext.getBean(XingHuoChatClient.class); return applicationContext.getBean(XingHuoChatClient.class);
@ -42,7 +42,7 @@ public class AiChatClientFactory {
// } // }
if (AiPlatformEnum.QIAN_WEN == platformEnum) { if (AiPlatformEnum.QIAN_WEN == platformEnum) {
return applicationContext.getBean(QianWenChatClient.class); return applicationContext.getBean(QianWenChatClient.class);
} else if (AiPlatformEnum.YIYAN == platformEnum) { } else if (AiPlatformEnum.YI_YAN == platformEnum) {
return applicationContext.getBean(YiYanChatClient.class); return applicationContext.getBean(YiYanChatClient.class);
} else if (AiPlatformEnum.XING_HUO == platformEnum) { } else if (AiPlatformEnum.XING_HUO == platformEnum) {
return applicationContext.getBean(XingHuoChatClient.class); return applicationContext.getBean(XingHuoChatClient.class);

View File

@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.ai.dal.vo;
import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum; import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import org.springframework.ai.models.xinghuo.XingHuoChatModel; import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoChatModel;
import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanChatModel; import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanChatModel;
/** /**

View File

@ -5,9 +5,9 @@ import org.springframework.ai.models.tongyi.QianWenChatClient;
import org.springframework.ai.models.tongyi.QianWenChatModal; import org.springframework.ai.models.tongyi.QianWenChatModal;
import org.springframework.ai.models.tongyi.QianWenOptions; import org.springframework.ai.models.tongyi.QianWenOptions;
import org.springframework.ai.models.tongyi.api.QianWenApi; import org.springframework.ai.models.tongyi.api.QianWenApi;
import org.springframework.ai.models.xinghuo.XingHuoChatClient; import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoChatClient;
import org.springframework.ai.models.xinghuo.XingHuoOptions; import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoOptions;
import org.springframework.ai.models.xinghuo.api.XingHuoApi; import cn.iocoder.yudao.framework.ai.core.model.xinghuo.api.XingHuoApi;
import cn.iocoder.yudao.framework.ai.core.model.yiyan.YiYanChatClient; import cn.iocoder.yudao.framework.ai.core.model.yiyan.YiYanChatClient;
import cn.iocoder.yudao.framework.ai.core.model.yiyan.YiYanChatOptions; import cn.iocoder.yudao.framework.ai.core.model.yiyan.YiYanChatOptions;
import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanApi; import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanApi;

View File

@ -1,8 +1,8 @@
package cn.iocoder.yudao.framework.ai.config; package cn.iocoder.yudao.framework.ai.config;
import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum; import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum;
import org.springframework.ai.models.xinghuo.XingHuoChatModel; import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoChatModel;
import org.springframework.ai.models.xinghuo.XingHuoOptions; import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoOptions;
import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanChatModel; import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanChatModel;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.framework.ai.config; package cn.iocoder.yudao.framework.ai.config;
import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum; import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum;
import org.springframework.ai.models.xinghuo.XingHuoChatModel; import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoChatModel;
import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanChatModel; import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanChatModel;
import cn.iocoder.yudao.framework.ai.core.enums.OpenAiImageModelEnum; import cn.iocoder.yudao.framework.ai.core.enums.OpenAiImageModelEnum;
import cn.iocoder.yudao.framework.ai.core.enums.OpenAiImageStyleEnum; import cn.iocoder.yudao.framework.ai.core.enums.OpenAiImageStyleEnum;
@ -21,7 +21,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "yudao.ai") @ConfigurationProperties(prefix = "yudao.ai")
public class YudaoAiProperties { public class YudaoAiProperties {
private String initSource;
private QianWenProperties qianwen; private QianWenProperties qianwen;
private XingHuoProperties xinghuo; private XingHuoProperties xinghuo;
private YiYanProperties yiyan; private YiYanProperties yiyan;

View File

@ -16,16 +16,23 @@ public enum AiPlatformEnum {
OPENAI("OpenAI", "OpenAI"), OPENAI("OpenAI", "OpenAI"),
OLLAMA("Ollama", "Ollama"), OLLAMA("Ollama", "Ollama"),
YIYAN("YiYan", "文心一言"), YI_YAN("YiYan", "文心一言"), // 百度
XING_HUO("XingHuo", "星火"), // 讯飞
QIAN_WEN("qianwen", "千问"), // 阿里
QIAN_WEN("qianwen", "千问"),
XING_HUO("xinghuo", "星火"),
OPEN_AI_DALL("dall", "dall"), OPEN_AI_DALL("dall", "dall"),
MIDJOURNEY("midjourney", "midjourney"), MIDJOURNEY("midjourney", "midjourney"),
; ;
/**
* 平台
*/
private final String platform; private final String platform;
/**
* 平台名
*/
private final String name; private final String name;
// public static List<AiPlatformEnum> CHAT_PLATFORM_LIST = Lists.newArrayList( // public static List<AiPlatformEnum> CHAT_PLATFORM_LIST = Lists.newArrayList(

View File

@ -1,14 +1,14 @@
package org.springframework.ai.models.xinghuo; package cn.iocoder.yudao.framework.ai.core.model.xinghuo;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.exceptions.ExceptionUtil; import cn.hutool.core.exceptions.ExceptionUtil;
import cn.iocoder.yudao.framework.ai.core.exception.ChatException; import cn.iocoder.yudao.framework.ai.core.exception.ChatException;
import cn.iocoder.yudao.framework.ai.core.model.xinghuo.api.XingHuoApi;
import cn.iocoder.yudao.framework.ai.core.model.xinghuo.api.XingHuoChatCompletion;
import cn.iocoder.yudao.framework.ai.core.model.xinghuo.api.XingHuoChatCompletionRequest;
import org.springframework.ai.chat.*; import org.springframework.ai.chat.*;
import org.springframework.ai.chat.prompt.ChatOptions; import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.chat.prompt.Prompt; import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.models.xinghuo.api.XingHuoApi;
import org.springframework.ai.models.xinghuo.api.XingHuoChatCompletion;
import org.springframework.ai.models.xinghuo.api.XingHuoChatCompletionRequest;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.retry.RetryCallback; import org.springframework.retry.RetryCallback;
@ -21,6 +21,7 @@ import java.time.Duration;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
// TODO @fan参考 yiyan 的修改建议调整下 xinghuo 的实现可以等 yiyan 修改完建议然后我 review 再改这个哈
/** /**
* 讯飞星火 client * 讯飞星火 client
* <p> * <p>

View File

@ -1,4 +1,4 @@
package org.springframework.ai.models.xinghuo; package cn.iocoder.yudao.framework.ai.core.model.xinghuo;
import lombok.Getter; import lombok.Getter;

View File

@ -1,4 +1,4 @@
package org.springframework.ai.models.xinghuo; package cn.iocoder.yudao.framework.ai.core.model.xinghuo;
import org.springframework.ai.chat.prompt.ChatOptions; import org.springframework.ai.chat.prompt.ChatOptions;
import lombok.Data; import lombok.Data;

View File

@ -1,8 +1,8 @@
package org.springframework.ai.models.xinghuo.api; package cn.iocoder.yudao.framework.ai.core.model.xinghuo.api;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import org.springframework.ai.models.xinghuo.XingHuoChatModel; import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoChatModel;
import lombok.Data; import lombok.Data;
import org.springframework.http.HttpStatusCode; import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -21,6 +21,7 @@ import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
// TODO @fan讯飞使用 spring websocket 接入还是 okhttp确认了未使用的最好删除下反正 git 也能找回 history
/** /**
* 讯飞星火 属性api * 讯飞星火 属性api
* <p> * <p>

View File

@ -1,4 +1,4 @@
package org.springframework.ai.models.xinghuo.api; package cn.iocoder.yudao.framework.ai.core.model.xinghuo.api;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;

View File

@ -1,4 +1,4 @@
package org.springframework.ai.models.xinghuo.api; package cn.iocoder.yudao.framework.ai.core.model.xinghuo.api;
import lombok.Data; import lombok.Data;
import lombok.Getter; import lombok.Getter;

View File

@ -2,8 +2,8 @@ package cn.iocoder.yudao.framework.ai.chat;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import org.springframework.ai.models.xinghuo.api.XingHuoChatCompletion; import cn.iocoder.yudao.framework.ai.core.model.xinghuo.api.XingHuoChatCompletion;
import org.springframework.ai.models.xinghuo.api.XingHuoChatCompletionRequest; import cn.iocoder.yudao.framework.ai.core.model.xinghuo.api.XingHuoChatCompletionRequest;
import org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient; import org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient;
import org.springframework.web.reactive.socket.client.WebSocketClient; import org.springframework.web.reactive.socket.client.WebSocketClient;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;

View File

@ -5,10 +5,10 @@ import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.messages.SystemMessage; import org.springframework.ai.chat.messages.SystemMessage;
import org.springframework.ai.chat.messages.UserMessage; import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.prompt.Prompt; import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.models.xinghuo.XingHuoChatClient; import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoChatClient;
import org.springframework.ai.models.xinghuo.XingHuoChatModel; import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoChatModel;
import org.springframework.ai.models.xinghuo.XingHuoOptions; import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoOptions;
import org.springframework.ai.models.xinghuo.api.XingHuoApi; import cn.iocoder.yudao.framework.ai.core.model.xinghuo.api.XingHuoApi;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;

View File

@ -2,9 +2,9 @@ package cn.iocoder.yudao.framework.ai.chat;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import org.springframework.ai.models.xinghuo.XingHuoChatClient; import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoChatClient;
import org.springframework.ai.models.xinghuo.api.XingHuoChatCompletion; import cn.iocoder.yudao.framework.ai.core.model.xinghuo.api.XingHuoChatCompletion;
import org.springframework.ai.models.xinghuo.api.XingHuoChatCompletionRequest; import cn.iocoder.yudao.framework.ai.core.model.xinghuo.api.XingHuoChatCompletionRequest;
import okhttp3.*; import okhttp3.*;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@ -209,37 +209,6 @@ wx:
# 芋道配置项,设置当前项目所有自定义的配置 # 芋道配置项,设置当前项目所有自定义的配置
yudao: yudao:
ai:
initSource: yaml
qianwen:
enable: true
aiPlatform: QIAN_WEN
max-tokens: 1500
temperature: 0.85
topP: 0.8
topK: 0
api-key: sk-Zsd81gZYg7
xinghuo:
enable: true
aiPlatform: XING_HUO
max-tokens: 1500
temperature: 0.85
topP: 0.8
topK: 0
appId: 13c8cca6
appKey: cb6415c19d6162cda07b47316fcb0416
secretKey: Y2JiYTIxZjA3MDMxMjNjZjQzYzVmNzdh
model: XING_HUO_3_5
openAiImage:
enable: true
api-key: ${OPEN_AI_KEY}
model: dall_e_2
style: vivid
midjourney:
enable: true
token: MTE4MjE3MjY2MjkxNTY3ODIzOA.GEV1SG.c49F8lZoGCUHwsj8O0UdodmM6nyQHvuD2fXflw
guild-id: 1237948819677904956
channel-id: 1237948819677904960
captcha: captcha:
enable: false # 本地环境,暂时关闭图片验证码,方便登录等接口的测试; enable: false # 本地环境,暂时关闭图片验证码,方便登录等接口的测试;
security: security:

View File

@ -153,7 +153,7 @@ spring.ai:
yudao.ai: yudao.ai:
yiyan: yiyan:
enable: true enable: true
aiPlatform: YIYAN # TODO @fan建议每个都独立配置属性类 aiPlatform: YI_YAN # TODO @fan建议每个都独立配置属性类
max-tokens: 1500 max-tokens: 1500
temperature: 0.85 temperature: 0.85
topP: 0.8 topP: 0.8
@ -162,6 +162,35 @@ yudao.ai:
secretKey: R9mYF9dl9KASgi5RUq0FQt3wRisSnOcK secretKey: R9mYF9dl9KASgi5RUq0FQt3wRisSnOcK
refreshTokenSecondTime: 86400 refreshTokenSecondTime: 86400
model: ERNIE4_3_5_8K model: ERNIE4_3_5_8K
xinghuo:
enable: true
aiPlatform: XING_HUO # TODO @fan建议每个都独立配置属性类
max-tokens: 1500
temperature: 0.85
topP: 0.8
topK: 0
appId: 13c8cca6
appKey: cb6415c19d6162cda07b47316fcb0416
secretKey: Y2JiYTIxZjA3MDMxMjNjZjQzYzVmNzdh
model: XING_HUO_3_5
qianwen:
enable: true
aiPlatform: QIAN_WEN
max-tokens: 1500
temperature: 0.85
topP: 0.8
topK: 0
api-key: sk-Zsd81gZYg7
openAiImage:
enable: true
api-key: ${OPEN_AI_KEY}
model: dall_e_2
style: vivid
midjourney:
enable: true
token: MTE4MjE3MjY2MjkxNTY3ODIzOA.GEV1SG.c49F8lZoGCUHwsj8O0UdodmM6nyQHvuD2fXflw
guild-id: 1237948819677904956
channel-id: 1237948819677904960
--- #################### 芋道相关配置 #################### --- #################### 芋道相关配置 ####################