|
@@ -2,6 +2,9 @@ package cn.qinys.ai.chatgpt.controller;
|
|
|
|
|
|
|
|
import cn.qinys.ai.chatgpt.req.MsgReq;
|
|
import cn.qinys.ai.chatgpt.req.MsgReq;
|
|
|
import jakarta.annotation.Resource;
|
|
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.ai.openai.OpenAiChatClient;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
@@ -15,15 +18,21 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
* @date: 2024/5/12
|
|
* @date: 2024/5/12
|
|
|
*/
|
|
*/
|
|
|
@RestController
|
|
@RestController
|
|
|
-@RequestMapping("/openai")
|
|
|
|
|
|
|
+@RequestMapping("/kimi")
|
|
|
public class MessageController {
|
|
public class MessageController {
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
private OpenAiChatClient openAiChatClient;
|
|
private OpenAiChatClient openAiChatClient;
|
|
|
|
|
|
|
|
@PostMapping("/test")
|
|
@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();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|