tycoding 1 tahun lalu
induk
melakukan
339bd65e6a

+ 5 - 0
langchat-core/pom.xml

@@ -59,6 +59,11 @@
             <artifactId>langchain4j-vertex-ai-gemini</artifactId>
             <version>${langchain4j.version}</version>
         </dependency>
+        <dependency>
+            <groupId>dev.langchain4j</groupId>
+            <artifactId>langchain4j-chatglm</artifactId>
+            <version>${langchain4j.version}</version>
+        </dependency>
 
         <dependency>
             <groupId>org.springframework</groupId>

+ 2 - 6
langchat-core/src/main/java/cn/tycoding/langchat/core/CoreAutoConfiguration.java

@@ -1,11 +1,6 @@
 package cn.tycoding.langchat.core;
 
-import cn.tycoding.langchat.core.properties.EmbedProps;
-import cn.tycoding.langchat.core.properties.LangChatProps;
-import cn.tycoding.langchat.core.properties.OllamaProps;
-import cn.tycoding.langchat.core.properties.OssProps;
-import cn.tycoding.langchat.core.properties.PgVectorProps;
-import cn.tycoding.langchat.core.properties.PineconeProps;
+import cn.tycoding.langchat.core.properties.*;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Configuration;
 
@@ -16,6 +11,7 @@ import org.springframework.context.annotation.Configuration;
 @Configuration
 @EnableConfigurationProperties({OssProps.class, LangChatProps.class, EmbedProps.class,
         OllamaProps.class,
+        GeminiProps.class,
         PgVectorProps.class, PineconeProps.class})
 public class CoreAutoConfiguration {
 

+ 21 - 0
langchat-core/src/main/java/cn/tycoding/langchat/core/properties/GeminiProps.java

@@ -0,0 +1,21 @@
+package cn.tycoding.langchat.core.properties;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * @author tycoding
+ * @since 2023/12/15
+ */
+@Data
+@ConfigurationProperties(prefix = "langchat.gemini")
+public class GeminiProps {
+
+    private String project;
+    private String location;
+    private String modelName;
+    private Float temperature;
+    private Integer maxOutputTokens;
+    private Integer topK;
+    private Float topP;
+}

+ 2 - 0
langchat-core/src/main/java/cn/tycoding/langchat/core/properties/LangChatProps.java

@@ -37,4 +37,6 @@ public class LangChatProps {
     private EmbedProps embedding;
 
     private OllamaProps ollama;
+
+    private GeminiProps gemini;
 }

+ 5 - 4
langchat-core/src/main/java/cn/tycoding/langchat/core/service/impl/LangChatServiceImpl.java

@@ -40,14 +40,14 @@ import org.springframework.stereotype.Service;
 @AllArgsConstructor
 public class LangChatServiceImpl implements LangChatService {
 
-    private final LangChatProps langChatProps;
+    private final LangChatProps props;
     private final OssProps ossProps;
 
     @Override
     public void chat(ChatReq req) {
         long startTime = System.currentTimeMillis();
         StreamingChatLanguageModel model = OpenAiStreamingChatModel.builder()
-                .apiKey(langChatProps.getApiKey())
+                .apiKey(props.getApiKey())
                 .modelName("gpt-4")
                 .proxy(new Proxy(HTTP, new InetSocketAddress("127.0.0.1", 7890)))
                 .build();
@@ -100,6 +100,7 @@ public class LangChatServiceImpl implements LangChatService {
 
                     @Override
                     public void onError(Throwable throwable) {
+                        throwable.printStackTrace();
                         req.getEmitter().complete();
                     }
 
@@ -115,7 +116,7 @@ public class LangChatServiceImpl implements LangChatService {
     @Override
     public String text(ChatReq req) {
         ChatLanguageModel model = OpenAiChatModel.builder()
-                .apiKey(langChatProps.getApiKey())
+                .apiKey(props.getApiKey())
                 .modelName("gpt-4")
                 .proxy(new Proxy(HTTP, new InetSocketAddress("127.0.0.1", 7890)))
                 .build();
@@ -129,7 +130,7 @@ public class LangChatServiceImpl implements LangChatService {
         OpenAiImageModel model = OpenAiImageModel
                 .builder()
                 .proxy(new Proxy(HTTP, new InetSocketAddress("127.0.0.1", 7890)))
-                .apiKey(langChatProps.getApiKey())
+                .apiKey(props.getApiKey())
                 .quality(DALL_E_QUALITY_HD)
                 .logRequests(true)
                 .logResponses(true)