|
1 | 1 | package io.quarkiverse.langchain4j.mistralai.runtime; |
2 | 2 |
|
| 3 | +import static io.quarkiverse.langchain4j.mistralai.runtime.config.LangChain4jMistralAiConfig.MistralAiConfig.DEFAULT_API_KEY; |
| 4 | +import static io.quarkiverse.langchain4j.mistralai.runtime.config.LangChain4jMistralAiConfig.MistralAiConfig.DEFAULT_BASE_URL; |
3 | 5 | import static io.quarkiverse.langchain4j.runtime.OptionalUtil.firstOrDefault; |
4 | 6 |
|
5 | 7 | import java.time.Duration; |
|
27 | 29 |
|
28 | 30 | @Recorder |
29 | 31 | public class MistralAiRecorder { |
30 | | - private static final String DUMMY_KEY = "dummy"; |
31 | 32 |
|
32 | 33 | public Supplier<ChatLanguageModel> chatModel(LangChain4jMistralAiConfig runtimeConfig, String configName) { |
33 | 34 | LangChain4jMistralAiConfig.MistralAiConfig mistralAiConfig = correspondingMistralAiConfig(runtimeConfig, |
34 | 35 | configName); |
35 | 36 |
|
36 | 37 | if (mistralAiConfig.enableIntegration()) { |
37 | | - String apiKey = mistralAiConfig.apiKey(); |
38 | 38 | ChatModelConfig chatModelConfig = mistralAiConfig.chatModel(); |
39 | 39 |
|
40 | | - if (DUMMY_KEY.equals(apiKey)) { |
| 40 | + String apiKey = mistralAiConfig.apiKey(); |
| 41 | + String baseUrl = mistralAiConfig.baseUrl(); |
| 42 | + if (DEFAULT_API_KEY.equals(apiKey) && DEFAULT_BASE_URL.equals(baseUrl)) { |
41 | 43 | throw new ConfigValidationException(createApiKeyConfigProblem(configName)); |
42 | 44 | } |
43 | 45 |
|
44 | 46 | var builder = MistralAiChatModel.builder() |
45 | | - .baseUrl(mistralAiConfig.baseUrl()) |
| 47 | + .baseUrl(baseUrl) |
46 | 48 | .apiKey(apiKey) |
47 | 49 | .modelName(chatModelConfig.modelName()) |
48 | 50 | .logRequests(firstOrDefault(false, chatModelConfig.logRequests(), mistralAiConfig.logRequests())) |
@@ -87,15 +89,16 @@ public Supplier<StreamingChatLanguageModel> streamingChatModel(LangChain4jMistra |
87 | 89 | configName); |
88 | 90 |
|
89 | 91 | if (mistralAiConfig.enableIntegration()) { |
90 | | - String apiKey = mistralAiConfig.apiKey(); |
91 | 92 | ChatModelConfig chatModelConfig = mistralAiConfig.chatModel(); |
92 | 93 |
|
93 | | - if (DUMMY_KEY.equals(apiKey)) { |
| 94 | + String apiKey = mistralAiConfig.apiKey(); |
| 95 | + String baseUrl = mistralAiConfig.baseUrl(); |
| 96 | + if (DEFAULT_API_KEY.equals(apiKey) && DEFAULT_BASE_URL.equals(baseUrl)) { |
94 | 97 | throw new ConfigValidationException(createApiKeyConfigProblem(configName)); |
95 | 98 | } |
96 | 99 |
|
97 | 100 | var builder = MistralAiStreamingChatModel.builder() |
98 | | - .baseUrl(mistralAiConfig.baseUrl()) |
| 101 | + .baseUrl(baseUrl) |
99 | 102 | .apiKey(apiKey) |
100 | 103 | .modelName(chatModelConfig.modelName()) |
101 | 104 | .logRequests(firstOrDefault(false, chatModelConfig.logRequests(), mistralAiConfig.logRequests())) |
@@ -139,10 +142,11 @@ public Supplier<EmbeddingModel> embeddingModel(LangChain4jMistralAiConfig runtim |
139 | 142 | configName); |
140 | 143 |
|
141 | 144 | if (mistralAiConfig.enableIntegration()) { |
142 | | - String apiKey = mistralAiConfig.apiKey(); |
143 | 145 | EmbeddingModelConfig embeddingModelConfig = mistralAiConfig.embeddingModel(); |
144 | 146 |
|
145 | | - if (DUMMY_KEY.equals(apiKey)) { |
| 147 | + String apiKey = mistralAiConfig.apiKey(); |
| 148 | + String baseUrl = mistralAiConfig.baseUrl(); |
| 149 | + if (DEFAULT_API_KEY.equals(apiKey) && DEFAULT_BASE_URL.equals(baseUrl)) { |
146 | 150 | throw new ConfigValidationException(createApiKeyConfigProblem(configName)); |
147 | 151 | } |
148 | 152 |
|
@@ -175,15 +179,16 @@ public Supplier<ModerationModel> moderationModel(LangChain4jMistralAiConfig runt |
175 | 179 | configName); |
176 | 180 |
|
177 | 181 | if (mistralAiConfig.enableIntegration()) { |
178 | | - String apiKey = mistralAiConfig.apiKey(); |
179 | 182 | ModerationModelConfig moderationModelConfig = mistralAiConfig.moderationModel(); |
180 | 183 |
|
181 | | - if (DUMMY_KEY.equals(apiKey)) { |
| 184 | + String apiKey = mistralAiConfig.apiKey(); |
| 185 | + String baseUrl = mistralAiConfig.baseUrl(); |
| 186 | + if (DEFAULT_API_KEY.equals(apiKey) && DEFAULT_BASE_URL.equals(baseUrl)) { |
182 | 187 | throw new ConfigValidationException(createApiKeyConfigProblem(configName)); |
183 | 188 | } |
184 | 189 |
|
185 | 190 | var builder = new MistralAiModerationModel.Builder() |
186 | | - .baseUrl(mistralAiConfig.baseUrl()) |
| 191 | + .baseUrl(baseUrl) |
187 | 192 | .apiKey(apiKey) |
188 | 193 | .modelName(moderationModelConfig.modelName()) |
189 | 194 | .logRequests(firstOrDefault(false, moderationModelConfig.logRequests(), mistralAiConfig.logRequests())) |
|
0 commit comments