|
|
|
|
@ -36,7 +36,8 @@ import reactor.core.publisher.Mono;
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
/**
|
|
|
|
|
* @Author xins
|
|
|
|
|
* @Date 2025/7/17 14:31
|
|
|
|
|
@ -1081,6 +1082,7 @@ public class AIAssistantServiceImpl implements IAIAssistantService {
|
|
|
|
|
Mono<AIResponse> response = processor.chat(aiRequest);
|
|
|
|
|
if (Objects.requireNonNull(response.block()).isSuccess()) {
|
|
|
|
|
String content = response.block().getContent().toString();
|
|
|
|
|
content = extractJson(content);
|
|
|
|
|
JSONObject contentJson = JSONObject.parseObject(content);
|
|
|
|
|
parseRelateTable(aiFormSettingDetailList, contentJson);
|
|
|
|
|
processor.saveTokenUsage(HwMomAiConstants.AI_CHAT_MESSAGE_DETAIL_TYPE_FORM, prompt, content, response.block().getTokenUsage(),
|
|
|
|
|
@ -1115,7 +1117,7 @@ public class AIAssistantServiceImpl implements IAIAssistantService {
|
|
|
|
|
sb.append("【输出要求】\n")
|
|
|
|
|
.append("1. 根据需求推断并填充所有相关字段的值\n")
|
|
|
|
|
.append("2. 仅返回一个JSON对象,不要任何额外文本\n")
|
|
|
|
|
.append("3. 键名必须来自表单结构中的字段名\n")
|
|
|
|
|
.append("3. JSON对象的键名必须使用表单结构中「返回的JSON数据Key值」\\n")
|
|
|
|
|
.append("4. 未指定的字段返回空字符串\n")
|
|
|
|
|
.append("5. 不要随意添加标点符号");
|
|
|
|
|
|
|
|
|
|
@ -1246,6 +1248,25 @@ public class AIAssistantServiceImpl implements IAIAssistantService {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String extractJson(String text) {
|
|
|
|
|
// 正则匹配```json ... ```之间的内容
|
|
|
|
|
Pattern pattern = Pattern.compile("```json\\s*(.*?)\\s*```", Pattern.DOTALL);
|
|
|
|
|
Matcher matcher = pattern.matcher(text);
|
|
|
|
|
|
|
|
|
|
if (matcher.find()) {
|
|
|
|
|
return matcher.group(1).trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果没有代码块标记,尝试直接查找JSON对象
|
|
|
|
|
pattern = Pattern.compile("\\{.*\\}", Pattern.DOTALL);
|
|
|
|
|
matcher = pattern.matcher(text);
|
|
|
|
|
|
|
|
|
|
if (matcher.find()) {
|
|
|
|
|
return matcher.group(0).trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return text; // 如果没有匹配到,返回原文本
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
|
// * 在新建AI模型或修改AI模型时,测试AI模型是否可用,验证apikey和apisecret等信息
|
|
|
|
|
|