Commit 546b522c4884b1f1574eee2ae4d331a1d96520ee
1 parent
10ca7a93
【添加todo】google gemini 初始化问题
Showing
1 changed file
with
15 additions
and
3 deletions
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/factory/AiClientFactoryImpl.java
| ... | ... | @@ -20,9 +20,12 @@ import cn.iocoder.yudao.framework.ai.core.model.xinghuo.api.XingHuoApi; |
| 20 | 20 | import cn.iocoder.yudao.framework.ai.core.model.yiyan.YiYanChatClient; |
| 21 | 21 | import cn.iocoder.yudao.framework.ai.core.model.yiyan.YiYanChatOptions; |
| 22 | 22 | import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanApi; |
| 23 | +import com.google.auth.oauth2.GoogleCredentials; | |
| 23 | 24 | import com.google.cloud.vertexai.VertexAI; |
| 24 | 25 | import org.springframework.ai.autoconfigure.ollama.OllamaAutoConfiguration; |
| 25 | 26 | import org.springframework.ai.autoconfigure.openai.OpenAiAutoConfiguration; |
| 27 | +import org.springframework.ai.autoconfigure.vertexai.gemini.VertexAiGeminiConnectionProperties; | |
| 28 | +import org.springframework.ai.autoconfigure.vertexai.palm2.VertexAiPalm2ConnectionProperties; | |
| 26 | 29 | import org.springframework.ai.chat.StreamingChatClient; |
| 27 | 30 | import org.springframework.ai.chat.prompt.ChatOptions; |
| 28 | 31 | import org.springframework.ai.ollama.OllamaChatClient; |
| ... | ... | @@ -35,6 +38,7 @@ import org.springframework.ai.openai.api.OpenAiApi; |
| 35 | 38 | import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatClient; |
| 36 | 39 | import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatOptions; |
| 37 | 40 | |
| 41 | +import java.io.IOException; | |
| 38 | 42 | import java.util.List; |
| 39 | 43 | |
| 40 | 44 | /** |
| ... | ... | @@ -169,15 +173,23 @@ public class AiClientFactoryImpl implements AiClientFactory { |
| 169 | 173 | return new QianWenChatClient(qianWenApi); |
| 170 | 174 | } |
| 171 | 175 | |
| 172 | - | |
| 173 | 176 | private static VertexAiGeminiChatClient buildGoogleGemir(String key) { |
| 174 | 177 | List<String> keys = StrUtil.split(key, '|'); |
| 175 | 178 | Assert.equals(keys.size(), 2, "VertexAiGeminiChatClient 的密钥需要 (projectId|location) 格式"); |
| 176 | - VertexAI vertexApi = new VertexAI(keys.get(0), keys.get(1)); | |
| 179 | +// VertexAiGeminiConnectionProperties connectionProperties = new VertexAiGeminiConnectionProperties(); | |
| 180 | +// connectionProperties.setApiKey("AIzaSyBpe376HTA8uPKJN_OJTh7MEO3v6LMqfXU"); | |
| 181 | +// | |
| 182 | +// GoogleCredentials credentials = GoogleCredentials.fromStream(connectionProperties.getCredentialsUri().getInputStream()); | |
| 183 | + // todo @芋艿 google gemini 没找到对于初始化 client 方式,文档中说是用过 GoogleCredentials 来初始化凭证 | |
| 184 | + // api-key: AIzaSyBpe376HTA8uPKJN_OJTh7MEO3v6LMqfXU | |
| 185 | + VertexAI vertexApi = new VertexAI( | |
| 186 | + "skilled-snow-409401", | |
| 187 | + "us-central1" | |
| 188 | + ); | |
| 177 | 189 | return new VertexAiGeminiChatClient(vertexApi, |
| 178 | 190 | VertexAiGeminiChatOptions.builder() |
| 179 | 191 | .withTemperature(0.4F) |
| 192 | + .withModel(VertexAiGeminiChatClient.ChatModel.GEMINI_PRO.getValue()) | |
| 180 | 193 | .build()); |
| 181 | 194 | } |
| 182 | - | |
| 183 | 195 | } | ... | ... |