This commit is contained in:
van
2026-04-05 20:47:01 +08:00
parent 43e44c8f7f
commit 8a77598c88
3 changed files with 460 additions and 113 deletions

View File

@@ -157,13 +157,27 @@ public class SocialMediaController extends BaseController
}
/**
* 获取大模型接入配置API 地址、密钥等,与 Jarvis 共用 Redis
* 列出多套大模型接入配置及当前激活 id
*/
@GetMapping("/llm-config")
public AjaxResult getLlmConfig()
public AjaxResult listLlmProfiles()
{
try {
return socialMediaService.getLlmConfig();
return socialMediaService.listLlmProfiles();
} catch (Exception e) {
logger.error("列出大模型接入配置失败", e);
return AjaxResult.error("获取失败: " + e.getMessage());
}
}
/**
* 获取单套配置(编辑)
*/
@GetMapping("/llm-config/profiles/{id}")
public AjaxResult getLlmProfile(@PathVariable("id") String id)
{
try {
return socialMediaService.getLlmProfile(id);
} catch (Exception e) {
logger.error("获取大模型接入配置失败", e);
return AjaxResult.error("获取失败: " + e.getMessage());
@@ -171,32 +185,92 @@ public class SocialMediaController extends BaseController
}
/**
* 保存大模型接入配置
* 新增一套配置
*/
@Log(title = "保存大模型接入配置", businessType = BusinessType.UPDATE)
@PostMapping("/llm-config/save")
public AjaxResult saveLlmConfig(@RequestBody Map<String, Object> request)
@Log(title = "新增大模型接入配置", businessType = BusinessType.INSERT)
@PostMapping("/llm-config/profiles")
public AjaxResult createLlmProfile(@RequestBody Map<String, Object> request)
{
try {
return socialMediaService.saveLlmConfig(request);
return socialMediaService.createLlmProfile(request);
} catch (Exception e) {
logger.error("保存大模型接入配置失败", e);
logger.error("新增大模型接入配置失败", e);
return AjaxResult.error("保存失败: " + e.getMessage());
}
}
/**
* 清除大模型接入配置Jarvis 使用 yml 默认 Ollama
* 更新一套配置
*/
@Log(title = "重置大模型接入配置", businessType = BusinessType.DELETE)
@DeleteMapping("/llm-config")
public AjaxResult resetLlmConfig()
@Log(title = "更新大模型接入配置", businessType = BusinessType.UPDATE)
@PutMapping("/llm-config/profiles/{id}")
public AjaxResult updateLlmProfile(@PathVariable("id") String id, @RequestBody Map<String, Object> request)
{
try {
return socialMediaService.resetLlmConfig();
return socialMediaService.updateLlmProfile(id, request);
} catch (Exception e) {
logger.error("重置大模型接入配置失败", e);
return AjaxResult.error("重置失败: " + e.getMessage());
logger.error("更新大模型接入配置失败", e);
return AjaxResult.error("保存失败: " + e.getMessage());
}
}
/**
* 删除一套配置
*/
@Log(title = "删除大模型接入配置", businessType = BusinessType.DELETE)
@DeleteMapping("/llm-config/profiles/{id}")
public AjaxResult deleteLlmProfile(@PathVariable("id") String id)
{
try {
return socialMediaService.deleteLlmProfile(id);
} catch (Exception e) {
logger.error("删除大模型接入配置失败", e);
return AjaxResult.error("删除失败: " + e.getMessage());
}
}
/**
* 激活指定配置为当前使用
*/
@Log(title = "激活大模型接入配置", businessType = BusinessType.UPDATE)
@PutMapping("/llm-config/active/{id}")
public AjaxResult setActiveLlmProfile(@PathVariable("id") String id)
{
try {
return socialMediaService.setActiveLlmProfile(id);
} catch (Exception e) {
logger.error("激活大模型接入配置失败", e);
return AjaxResult.error("操作失败: " + e.getMessage());
}
}
/**
* 取消激活Jarvis 使用 yml 默认 Ollama
*/
@Log(title = "取消激活大模型接入配置", businessType = BusinessType.UPDATE)
@DeleteMapping("/llm-config/active")
public AjaxResult clearActiveLlmProfile()
{
try {
return socialMediaService.clearActiveLlmProfile();
} catch (Exception e) {
logger.error("取消激活大模型接入配置失败", e);
return AjaxResult.error("操作失败: " + e.getMessage());
}
}
/**
* 清空所有套及旧版单键
*/
@Log(title = "清空大模型接入配置", businessType = BusinessType.DELETE)
@DeleteMapping("/llm-config")
public AjaxResult resetAllLlmConfig()
{
try {
return socialMediaService.resetAllLlmConfig();
} catch (Exception e) {
logger.error("清空大模型接入配置失败", e);
return AjaxResult.error("清除失败: " + e.getMessage());
}
}