Commit 8fde3496 authored by 林洋洋's avatar 林洋洋

优化提示词

parent 550d9a7d
...@@ -49,6 +49,8 @@ import org.springframework.web.bind.annotation.*; ...@@ -49,6 +49,8 @@ import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
...@@ -213,7 +215,19 @@ public class ChatController { ...@@ -213,7 +215,19 @@ public class ChatController {
@RequestParam String conversationId, @RequestParam String conversationId,
@RequestParam(required = false) Optional<Long> modelId) { @RequestParam(required = false) Optional<Long> modelId) {
Long actualModelId = modelId.orElse(1L); Long actualModelId = modelId.orElse(1L);
Message systemMessage = new SystemMessage("你是一个AI问答助手,请用回答用户问题,使用相关工具"); String now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-M-d HH:mm:ss"));
Message systemMessage = new SystemMessage(
String.format(
"你是一位“工具优先”的 AI 问答助手。\n" +
"1.先判断是否需要调用工具获取最新信息;如需要,立即调用。\n" +
"2.将工具返回的结构化数据整理成简洁、可落地的自然语言答案。\n" +
"3.默认当前时间为 %s,使用表格或代码块清晰展示关键信息。\n" +
"4.若无法调用工具,说明原因并给出替代方案。\n" +
"5.遵守中国法律,拒绝敏感或违法内容。",
now
)
);
Message userMessage = new UserMessage(message); Message userMessage = new UserMessage(message);
Prompt prompt = new Prompt(List.of(systemMessage, userMessage)); Prompt prompt = new Prompt(List.of(systemMessage, userMessage));
ChatClient chatClient = askModelService.getChatClientById(actualModelId); ChatClient chatClient = askModelService.getChatClientById(actualModelId);
......
...@@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils; ...@@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.tool.annotation.Tool; import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -89,8 +90,8 @@ public class ExcelTools { ...@@ -89,8 +90,8 @@ public class ExcelTools {
return date.format(formatter); return date.format(formatter);
} }
@Tool(description = "获取科环集团电力运营日报,入参时间(yyyy-M-d)") @Tool(description = "获取科环集团电力运营日报")
public String getProductionFile(String dateStr) { public String getProductionFile(@ToolParam(description = "时间(yyyy-M-d)")String dateStr) {
log.info("getProductionFile{}", dateStr); log.info("getProductionFile{}", dateStr);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-M-d"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-M-d");
LocalDate date = LocalDate.parse(dateStr, formatter); LocalDate date = LocalDate.parse(dateStr, formatter);
...@@ -124,7 +125,7 @@ public class ExcelTools { ...@@ -124,7 +125,7 @@ public class ExcelTools {
} }
@Tool(description = "获取天津智深DCS卡件日报",returnDirect=true) @Tool(description = "获取天津智深DCS卡件日报",returnDirect=true)
public String getDcsFile(String dateStr) { public String getDcsFile(@ToolParam(description = "时间(yyyy-M-d)")String dateStr) {
var ref = new Object() { var ref = new Object() {
String markDown = "| 产线 | 计划产量 | 实际产量 | 成品率 |\n" + String markDown = "| 产线 | 计划产量 | 实际产量 | 成品率 |\n" +
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment