调用本地大模型
This commit is contained in:
@@ -2,7 +2,10 @@ package com.rj.controller;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.rj.dto.AiQaCustomerAskRequestDto;
|
||||||
|
import com.rj.dto.AiQaCustomerAskResponseDto;
|
||||||
import com.rj.entity.AiQaItem;
|
import com.rj.entity.AiQaItem;
|
||||||
|
import com.rj.service.IAiQaCustomerAskService;
|
||||||
import com.rj.service.IAiQaItemService;
|
import com.rj.service.IAiQaItemService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
@@ -33,6 +36,32 @@ public class AiQaItemController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IAiQaItemService aiQaItemService;
|
private IAiQaItemService aiQaItemService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IAiQaCustomerAskService aiQaCustomerAskService;
|
||||||
|
|
||||||
|
@PostMapping("/ask")
|
||||||
|
@Operation(summary = "客户问答(大模型)", description = "接收客户问题,调用本地 OpenAI 兼容 Chat Completions,将回答返回给前端")
|
||||||
|
public ResponseEntity<Map<String, Object>> askCustomer(
|
||||||
|
@Parameter(description = "提问请求", required = true) @RequestBody AiQaCustomerAskRequestDto request) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
try {
|
||||||
|
AiQaCustomerAskResponseDto data = aiQaCustomerAskService.askCustomer(request);
|
||||||
|
result.put("success", true);
|
||||||
|
result.put("message", "回答生成成功");
|
||||||
|
result.put("data", data);
|
||||||
|
return ResponseEntity.ok(result);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", e.getMessage());
|
||||||
|
return ResponseEntity.badRequest().body(result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("ai_qa_item ask error", e);
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "调用大模型异常:" + e.getMessage());
|
||||||
|
return ResponseEntity.internalServerError().body(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
@Operation(summary = "新增", description = "新增 AI 问答子表记录")
|
@Operation(summary = "新增", description = "新增 AI 问答子表记录")
|
||||||
public ResponseEntity<Map<String, Object>> add(
|
public ResponseEntity<Map<String, Object>> add(
|
||||||
|
|||||||
@@ -9,6 +9,14 @@ dashscope:
|
|||||||
api:
|
api:
|
||||||
key: ${DASHSCOPE_API_KEY}
|
key: ${DASHSCOPE_API_KEY}
|
||||||
|
|
||||||
|
# AI 问答 - 本地 OpenAI 兼容 Chat Completions(无 Authorization)
|
||||||
|
ai:
|
||||||
|
qa:
|
||||||
|
local:
|
||||||
|
chat-url: http://192.168.1.44:8000/v1/chat/completions
|
||||||
|
default-model: Qwen2.5-7B-Instruct
|
||||||
|
max-tokens: 512
|
||||||
|
|
||||||
langchain4j:
|
langchain4j:
|
||||||
open-ai:
|
open-ai:
|
||||||
chat-model:
|
chat-model:
|
||||||
|
|||||||
Reference in New Issue
Block a user