| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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 = ""; |
| | |
| | | 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(); |
| | |
| | | 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(); |
| | |
| | | } |
| | | } |
| | | } |
| | | return aiBodyDto; |
| | | log.info("xsd:{}", aiBodyDto); |
| | | return R.ok(aiBodyDto); |
| | | } |
| | | |
| | | private Map<String, String> initHead(String token) { |