mirror of
https://gitee.com/zhijiantianya/ruoyi-vue-pro.git
synced 2025-12-26 08:26:44 +08:00
feat:【ai】增加 Grok 接入
This commit is contained in:
parent
ea8f532f5a
commit
9f9366f158
@ -255,6 +255,28 @@ public class AiAutoConfiguration {
|
||||
return new SunoApi(yudaoAiProperties.getSuno().getBaseUrl());
|
||||
}
|
||||
|
||||
public ChatModel buildGrokChatClient(YudaoAiProperties.Grok properties) {
|
||||
if (StrUtil.isEmpty(properties.getModel())) {
|
||||
properties.setModel(GrokChatModel.MODEL_DEFAULT);
|
||||
}
|
||||
OpenAiChatModel openAiChatModel = OpenAiChatModel.builder()
|
||||
.openAiApi(OpenAiApi.builder()
|
||||
.baseUrl(Optional.ofNullable(properties.getBaseUrl())
|
||||
.orElse(GrokChatModel.BASE_URL))
|
||||
.completionsPath(GrokChatModel.COMPLETE_PATH)
|
||||
.apiKey(properties.getApiKey())
|
||||
.build())
|
||||
.defaultOptions(OpenAiChatOptions.builder()
|
||||
.model(properties.getModel())
|
||||
.temperature(properties.getTemperature())
|
||||
.maxTokens(properties.getMaxTokens())
|
||||
.topP(properties.getTopP())
|
||||
.build())
|
||||
.toolCallingManager(getToolCallingManager())
|
||||
.build();
|
||||
return new DouBaoChatModel(openAiChatModel);
|
||||
}
|
||||
|
||||
// ========== RAG 相关 ==========
|
||||
|
||||
@Bean
|
||||
@ -289,25 +311,4 @@ public class AiAutoConfiguration {
|
||||
return List.of(ToolCallbacks.from(personService));
|
||||
}
|
||||
|
||||
public ChatModel buildGrokChatClient(YudaoAiProperties.Grok properties) {
|
||||
if (StrUtil.isEmpty(properties.getModel())) {
|
||||
properties.setModel(GrokChatModel.MODEL_DEFAULT);
|
||||
}
|
||||
OpenAiChatModel openAiChatModel = OpenAiChatModel.builder()
|
||||
.openAiApi(OpenAiApi.builder()
|
||||
.baseUrl(Optional.ofNullable(properties.getBaseUrl())
|
||||
.orElse(GrokChatModel.BASE_URL))
|
||||
.completionsPath(GrokChatModel.COMPLETE_PATH)
|
||||
.apiKey(properties.getApiKey())
|
||||
.build())
|
||||
.defaultOptions(OpenAiChatOptions.builder()
|
||||
.model(properties.getModel())
|
||||
.temperature(properties.getTemperature())
|
||||
.maxTokens(properties.getMaxTokens())
|
||||
.topP(properties.getTopP())
|
||||
.build())
|
||||
.toolCallingManager(getToolCallingManager())
|
||||
.build();
|
||||
return new DouBaoChatModel(openAiChatModel);
|
||||
}
|
||||
}
|
||||
@ -407,12 +407,6 @@ public class AiModelFactoryImpl implements AiModelFactory {
|
||||
.build();
|
||||
}
|
||||
|
||||
private ChatModel buildGrokChatModel(String apiKey,String url) {
|
||||
YudaoAiProperties.Grok properties = new YudaoAiProperties.Grok()
|
||||
.setBaseUrl(url)
|
||||
.setApiKey(apiKey);
|
||||
return new AiAutoConfiguration().buildGrokChatClient(properties);
|
||||
}
|
||||
/**
|
||||
* 可参考 {@link AiAutoConfiguration#douBaoChatClient(YudaoAiProperties)}
|
||||
*/
|
||||
@ -596,6 +590,13 @@ public class AiModelFactoryImpl implements AiModelFactory {
|
||||
return new StabilityAiImageModel(stabilityAiApi);
|
||||
}
|
||||
|
||||
private ChatModel buildGrokChatModel(String apiKey,String url) {
|
||||
YudaoAiProperties.Grok properties = new YudaoAiProperties.Grok()
|
||||
.setBaseUrl(url)
|
||||
.setApiKey(apiKey);
|
||||
return new AiAutoConfiguration().buildGrokChatClient(properties);
|
||||
}
|
||||
|
||||
// ========== 各种创建 EmbeddingModel 的方法 ==========
|
||||
|
||||
/**
|
||||
|
||||
@ -68,6 +68,7 @@ public class AiUtils {
|
||||
case OPENAI:
|
||||
case GEMINI: // 复用 OpenAI 客户端
|
||||
case BAI_CHUAN: // 复用 OpenAI 客户端
|
||||
case GROK: // 复用 OpenAI 客户端
|
||||
return OpenAiChatOptions.builder().model(model).temperature(temperature).maxTokens(maxTokens)
|
||||
.toolCallbacks(toolCallbacks).toolContext(toolContext).build();
|
||||
case AZURE_OPENAI:
|
||||
@ -79,9 +80,6 @@ public class AiUtils {
|
||||
case OLLAMA:
|
||||
return OllamaChatOptions.builder().model(model).temperature(temperature).numPredict(maxTokens)
|
||||
.toolCallbacks(toolCallbacks).toolContext(toolContext).build();
|
||||
case GROK:
|
||||
return OpenAiChatOptions.builder().model(model).temperature(temperature).maxTokens(maxTokens)
|
||||
.toolCallbacks(toolCallbacks).toolContext(toolContext).build();
|
||||
default:
|
||||
throw new IllegalArgumentException(StrUtil.format("未知平台({})", platform));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user