广州市综治平台后端
xusd
12 hours ago 2f83e6c961888e462b308223dfccbb679e6d9cd4
dyh-service/dyh-sys/src/main/java/cn/huge/module/ai/AiChatController.java
@@ -1,5 +1,6 @@
package cn.huge.module.ai;
import cn.huge.base.common.bo.R;
import cn.huge.base.common.utils.HttpClientUtils;
import cn.huge.base.common.utils.ReturnFailUtils;
import cn.huge.base.common.utils.ReturnSucUtils;
@@ -9,6 +10,7 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -19,13 +21,14 @@
import java.util.Map;
@RestController
@RequestMapping("/api/ai/chat")
@RequestMapping("/api/web/ai/chat")
@Slf4j
public class AiChatController {
    private String url = "http://10.202.1.102:9002/";
    @PostMapping("/risk")
    public String risk(@RequestBody AiRequestVo aiRequestVo) {
    public R<String> risk(@RequestBody AiRequestVo aiRequestVo) {
        String postUrl = url + "v1/workflows/run";
        initHead("Bearer app-8ylvZOHf2fOgTGfe28MYtHDD");
        String s = "";
@@ -40,18 +43,19 @@
            if (data != null) {
                JSONObject outputs = data.getJSONObject("outputs");
                if (outputs != null) {
                    JSONArray result = outputs.getJSONArray("result");
                    if (result != null && result.size() > 0) {
                        return result.getJSONObject(0).getString("is_risk_ai");
                    JSONObject body = outputs.getJSONObject("body");
                    if (body != null) {
                        return R.ok(body.getJSONObject("data").getString("is_risk_ai"));
                    }
                }
            }
        }
        return "0";
        log.info("xsd:{}", object);
        return R.ok("0");
    }
    @PostMapping("/chat")
    public AiBodyDto chat(@RequestBody AiRequestVo aiRequestVo) {
    public R<AiBodyDto> chat(@RequestBody AiRequestVo aiRequestVo) {
        String postUrl = url + "v1/chat-messages";
        String s = "";
        AiBodyDto aiBodyDto = new AiBodyDto();
@@ -67,11 +71,12 @@
            aiBodyDto.setAnswer(answer);
            aiBodyDto.setConversationId(conversation_id);
        }
        return aiBodyDto;
        log.info("xsd:{}", aiBodyDto);
        return R.ok(aiBodyDto);
    }
    @PostMapping("/strategy")
    public AiBodyDto strategy(@RequestBody AiRequestVo aiRequestVo) {
    public R<AiBodyDto> strategy(@RequestBody AiRequestVo aiRequestVo) {
        String postUrl = url + "v1/workflows/run";
        String s = "";
        AiBodyDto aiBodyDto = new AiBodyDto();
@@ -91,7 +96,8 @@
                }
            }
        }
        return aiBodyDto;
        log.info("xsd:{}", aiBodyDto);
        return R.ok(aiBodyDto);
    }
    private Map<String, String> initHead(String token) {