1
This commit is contained in:
@@ -153,6 +153,35 @@ public class SocialMediaController {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调试:测试大模型连通性。
|
||||||
|
* POST /jarvis/social-media/llm/test
|
||||||
|
* body: { "profileId": "可选,不传则用当前激活或 yml 默认", "message": "可选,默认问 1+1" }
|
||||||
|
*/
|
||||||
|
@PostMapping("/llm/test")
|
||||||
|
public JSONObject testLlm(@RequestBody(required = false) Map<String, Object> request) {
|
||||||
|
JSONObject response = new JSONObject();
|
||||||
|
try {
|
||||||
|
Map<String, Object> req = request != null ? request : new HashMap<>();
|
||||||
|
Object pid = req.get("profileId");
|
||||||
|
String profileId = pid == null ? null : pid.toString().trim();
|
||||||
|
if (profileId != null && profileId.isEmpty()) {
|
||||||
|
profileId = null;
|
||||||
|
}
|
||||||
|
Object msg = req.get("message");
|
||||||
|
String message = msg == null ? null : msg.toString();
|
||||||
|
Map<String, Object> data = socialMediaService.testLlmChat(profileId, message);
|
||||||
|
response.put("code", 200);
|
||||||
|
response.put("msg", "操作成功");
|
||||||
|
response.put("data", data);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("LLM 测试接口异常", e);
|
||||||
|
response.put("code", 500);
|
||||||
|
response.put("msg", "测试失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析Double值
|
* 解析Double值
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -343,5 +343,27 @@ public class SocialMediaService {
|
|||||||
|
|
||||||
return content.toString();
|
return content.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调试:向大模型发一条短问题(默认 1+1)。profileId 为空时使用当前激活配置(或 yml 默认)。
|
||||||
|
*/
|
||||||
|
public Map<String, Object> testLlmChat(String profileId, String message) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
try {
|
||||||
|
String prompt = StrUtil.isBlank(message)
|
||||||
|
? "1+1等于几?请只回答一个数字或最简结果,不要多余解释。"
|
||||||
|
: message.trim();
|
||||||
|
String reply = StrUtil.isBlank(profileId)
|
||||||
|
? socialMediaLlmClient.getResponse(prompt)
|
||||||
|
: socialMediaLlmClient.getResponse(prompt, profileId);
|
||||||
|
result.put("success", true);
|
||||||
|
result.put("reply", reply);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("LLM 连通性测试失败", e);
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("error", e.getMessage() != null ? e.getMessage() : e.getClass().getSimpleName());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user