This commit is contained in:
van
2026-04-05 21:35:06 +08:00
parent 26550c033b
commit 0d408d66c3
2 changed files with 51 additions and 0 deletions

View File

@@ -153,6 +153,35 @@ public class SocialMediaController {
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值
*/

View File

@@ -343,5 +343,27 @@ public class SocialMediaService {
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;
}
}