feat: 兼容多平台模型

This commit is contained in:
ageerle
2025-05-09 16:45:41 +08:00
parent 57b2f833f8
commit 1bddf5df3b
8 changed files with 54 additions and 5 deletions

View File

@@ -32,11 +32,12 @@ public class ChatConfig {
public OpenAiStreamClient openAiStreamClient() {
String apiHost = configService.getConfigValue("chat", "apiHost");
String apiKey = configService.getConfigValue("chat", "apiKey");
openAiStreamClient = createOpenAiStreamClient(apiHost,apiKey);
String url = configService.getConfigValue("chat", "apiUrl");
openAiStreamClient = createOpenAiStreamClient(apiHost,apiKey,url);
return openAiStreamClient;
}
public static OpenAiStreamClient createOpenAiStreamClient(String apiHost, String apiKey) {
public static OpenAiStreamClient createOpenAiStreamClient(String apiHost, String apiKey,String url) {
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(new OpenAILogger());
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
OkHttpClient okHttpClient = new OkHttpClient.Builder()
@@ -47,6 +48,7 @@ public class ChatConfig {
.build();
return OpenAiStreamClient.builder()
.apiHost(apiHost)
.apiUrl(url)
.apiKey(Collections.singletonList(apiKey))
.keyStrategy(new KeyRandomStrategy())
.okHttpClient(okHttpClient)

View File

@@ -47,7 +47,7 @@ public class OpenAIServiceImpl implements IChatService {
@Override
public SseEmitter chat(ChatRequest chatRequest,SseEmitter emitter) {
ChatModelVo chatModelVo = chatModelService.selectModelByName(chatRequest.getModel());
openAiStreamClient = ChatConfig.createOpenAiStreamClient(chatModelVo.getApiHost(), chatModelVo.getApiKey());
openAiStreamClient = ChatConfig.createOpenAiStreamClient(chatModelVo.getApiHost(), chatModelVo.getApiKey(),chatModelVo.getApiUrl());
List<Message> messages = chatRequest.getMessages();
if (enabled) {
String toolString = mcpChat(chatRequest.getPrompt());