|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.supervision.demo.controller;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.supervision.demo.service.ModelMetricService;
|
|
|
|
|
import com.supervision.police.domain.ModelRecordType;
|
|
|
|
|
import com.supervision.police.domain.NoteRecordSplit;
|
|
|
|
@ -18,15 +19,15 @@ import org.json.JSONException;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
import org.springframework.ai.chat.ChatResponse;
|
|
|
|
|
import org.springframework.ai.chat.Generation;
|
|
|
|
|
import org.springframework.ai.chat.messages.AssistantMessage;
|
|
|
|
|
import org.springframework.ai.chat.messages.Message;
|
|
|
|
|
import org.springframework.ai.chat.messages.SystemMessage;
|
|
|
|
|
import org.springframework.ai.chat.messages.UserMessage;
|
|
|
|
|
import org.springframework.ai.chat.prompt.Prompt;
|
|
|
|
|
import org.springframework.ai.ollama.OllamaChatClient;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.util.StopWatch;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
@ -255,4 +256,26 @@ public class ExampleChatController {
|
|
|
|
|
log.info("分析的结果是:{}", content);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("chat")
|
|
|
|
|
public String chat(@RequestBody Map<String,String> messages) {
|
|
|
|
|
|
|
|
|
|
Prompt prompt = null;
|
|
|
|
|
if (StrUtil.isNotEmpty(messages.get("message"))){
|
|
|
|
|
prompt = new Prompt(new UserMessage(messages.get("message")));
|
|
|
|
|
}else {
|
|
|
|
|
prompt = new Prompt(List.of(new AssistantMessage(messages.get("assistantMessage")), new UserMessage(messages.get("userMessage"))));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
ChatResponse call = chatClient.call(prompt);
|
|
|
|
|
Generation result = call.getResult();
|
|
|
|
|
|
|
|
|
|
String content = result.getOutput().getContent();
|
|
|
|
|
log.info("分析的结果是:{}", content);
|
|
|
|
|
if (StrUtil.isBlank(content)){
|
|
|
|
|
content = "{}";
|
|
|
|
|
}
|
|
|
|
|
return content;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|