tanlie 1 年之前
父节点
当前提交
58436a08b7

+ 8 - 0
chatgpt/chatgpt.iml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module version="4">
+  <component name="FacetManager">
+    <facet type="Spring" name="Spring">
+      <configuration />
+    </facet>
+  </component>
+</module>

+ 4 - 0
chatgpt/pom.xml

@@ -26,6 +26,10 @@
             <groupId>org.springframework.ai</groupId>
             <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.ai</groupId>
+            <artifactId>spring-ai-ollama-spring-boot-starter</artifactId>
+        </dependency>
 
         <dependency>
             <groupId>org.springframework.boot</groupId>

+ 13 - 4
chatgpt/src/main/java/cn/qinys/ai/chatgpt/controller/MessageController.java

@@ -2,6 +2,9 @@ package cn.qinys.ai.chatgpt.controller;
 
 import cn.qinys.ai.chatgpt.req.MsgReq;
 import jakarta.annotation.Resource;
+import org.springframework.ai.chat.ChatResponse;
+import org.springframework.ai.chat.prompt.Prompt;
+import org.springframework.ai.ollama.api.OllamaOptions;
 import org.springframework.ai.openai.OpenAiChatClient;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -15,15 +18,21 @@ import org.springframework.web.bind.annotation.RestController;
  * @date: 2024/5/12
  */
 @RestController
-@RequestMapping("/openai")
+@RequestMapping("/kimi")
 public class MessageController {
 
     @Resource
     private OpenAiChatClient openAiChatClient;
 
     @PostMapping("/test")
-    public String test(@RequestBody MsgReq req){
-        String result = openAiChatClient.call(req.getMsg());
-        return result;
+    public Object test(@RequestBody MsgReq req){
+        ChatResponse response = openAiChatClient.call(
+                new Prompt(
+                        req.getMsg(),
+                        OllamaOptions.create()
+                                .withTemperature(0.4F)
+                ));
+        System.out.println(response.getResult().getOutput());
+        return response.getResult().getOutput();
     }
 }

+ 38 - 0
chatgpt/src/main/java/cn/qinys/ai/chatgpt/controller/OllamaController.java

@@ -0,0 +1,38 @@
+package cn.qinys.ai.chatgpt.controller;
+
+import cn.qinys.ai.chatgpt.req.MsgReq;
+import jakarta.annotation.Resource;
+import org.springframework.ai.chat.ChatResponse;
+import org.springframework.ai.chat.prompt.Prompt;
+import org.springframework.ai.ollama.OllamaChatClient;
+import org.springframework.ai.ollama.api.OllamaOptions;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @description
+ * @date 2025-03-11 15:40
+ **/
+@RestController
+@RequestMapping("/ollama")
+public class OllamaController {
+
+    @Resource
+    private OllamaChatClient ollamaChatClient;
+
+
+    @PostMapping("/test")
+    public Object test(@RequestBody MsgReq req) {
+        ChatResponse response = ollamaChatClient.call(
+                new Prompt(
+                        req.getMsg(),
+                        OllamaOptions.create()
+                                .withTemperature(0.4F)
+                ));
+        System.out.println(response.getResult().getOutput());
+        return response.getResult().getOutput();
+    }
+
+}

+ 12 - 2
chatgpt/src/main/resources/application.yml

@@ -1,5 +1,15 @@
 spring:
   ai:
     openai:
-      api-key: sk-zCUZT5DJCnAubc10517470Ce06C544Bd8a7c3726608517Fe
-      base-url: https://api.pumpkinaigc.online
+      api-key: sk-71RyBMlhwTDKC5jABYdYkN0e6QAiFGJ01RW5oAKBTrIKRQGd
+      base-url: https://api.moonshot.cn
+      #api-key: sk-zCUZT5DJCnAubc10517470Ce06C544Bd8a7c3726608517Fe
+      #base-url: https://api.pumpkinaigc.online
+      chat:
+        options:
+          model: moonshot-v1-128k
+    ollama:
+      base-url: http://192.168.189.128:11434
+      chat:
+        options:
+          model: deepseek-r1