| | |
| | | import jakarta.annotation.Resource; |
| | | |
| | | import net.sf.json.JSONObject; |
| | | import okhttp3.Response; |
| | | import org.springframework.ai.ollama.OllamaChatModel; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | |
| | | @Tag(name="terra openai") |
| | |
| | | @Value("${spring.intent}") |
| | | String intent ; |
| | | |
| | | |
| | | @Autowired |
| | | WebSocketController webSocketController; |
| | | |
| | | @GetMapping("/chat") |
| | | @Operation(summary = "大模型对话") |
| | |
| | | return chatModel.call(message); |
| | | } |
| | | |
| | | @GetMapping("/ai") |
| | | @Operation(summary = "大模型对话") |
| | | public String ai(@RequestParam(value = "message",defaultValue = "Hi") String message){ |
| | | System.out.println("rec message:"+message); |
| | | HashMap<String,String> hash = new HashMap<>(); |
| | | hash.put("func","flyTo()"); |
| | | hash.put("content","x:120.9671,y:13.5748"); |
| | | message = JSON.toJSONString(hash); |
| | | return webSocketController.sendAllMessage(message); |
| | | } |
| | | @GetMapping("/ai/{place}/{funcName}/showPlaceMap") |
| | | @Operation(summary = "大模型对话") |
| | | public String intentShowMap(@PathVariable("place")String place,@PathVariable("funcName")String funcName){ |
| | | System.out.println("rec message:"+place); |
| | | HashMap<String,Object> hash = new HashMap<>(); |
| | | hash.put("func","flyTo()"); |
| | | HashMap<String,String> xy = new HashMap<>(); |
| | | xy.put("x","120.9671"); |
| | | xy.put("y","13.5748"); |
| | | hash.put("content",xy); |
| | | |
| | | webSocketController.sendAllMessage(JSON.toJSONString(hash)); |
| | | HashMap<String,Object> result = new HashMap<>(); |
| | | result.put("code","200"); |
| | | result.put("message","成功"); |
| | | result.put("data",""); |
| | | return JSON.toJSONString(result); |
| | | } |
| | | @GetMapping("/intent") |
| | | @Operation(summary = "意图请求") |
| | | public String intent(@RequestParam(value = "message",defaultValue = "Hi") String message){ |
| | | String json = okHttpUtil.getMessage(intent+"="+message); |
| | | if( message.toLowerCase().indexOf("x") == 0){ |
| | | return getString(message.substring(1)); |
| | | } |
| | | String r = intent+"=\""+message+"\""; |
| | | System.out.println(r); |
| | | String json = okHttpUtil.getMessage(r); |
| | | System.out.println(json); |
| | | |
| | | Map<String,String> hashMap = new HashMap<>() ; |
| | | if( json == null){ |
| | | hashMap.put("status","500"); |
| | | //String llm = chatModel.call(message); |
| | | //hashMap.put("content","识别异常,"+llm); |
| | | if( hashMap.get("name") == null ){ |
| | | String json2 = okHttpUtil.requesFast(message); |
| | | |
| | | return json2 ; |
| | | } |
| | | return JSON.toJSON(hashMap).toString() ; |
| | | |
| | | } |
| | | iteraJson(json,hashMap); |
| | | if( hashMap.get("name") == null ){ |
| | | String json2 = okHttpUtil.requesFast(message); |
| | | |
| | | return json2 ; |
| | | } |
| | | intentSwitch(hashMap,message); |
| | | return JSON.toJSON(hashMap).toString() ; |
| | | } |
| | | |
| | | private String getString(String message) { |
| | | String json = okHttpUtil.requesFast(message.substring(1)); |
| | | |
| | | return json; |
| | | } |
| | | |
| | | public boolean iteraJson(String str, Map res){ |
| | | if(str.toString().indexOf(":") == -1){ |
| | | return true; |
| | |
| | | |
| | | @GetMapping("/fastgpt") |
| | | @Operation(summary = "知识库查询") |
| | | public String fastgpt(@RequestParam(value = "message",defaultValue = "三维实景") String message){ |
| | | public String fastgpt(@RequestParam(value = "message",defaultValue = "055") String message){ |
| | | |
| | | //okHttpUtil.requesFast(message); |
| | | String json = okHttpUtil.requesFast(message); |
| | |
| | | */ |
| | | private void intentSwitch(Map<String,String>hash,String message){ |
| | | if( hash.get("name") == null ) return ; |
| | | if( hash.get("name").equals("anomalyCheck")) hash.put("name","scanWeapon"); |
| | | if( hash.get("name").equals("weaponParameters")) hash.put("name","weaponParameters"); |
| | | // if( hash.get("name").equals("anomalyCheck")) hash.put("name","scanWeapon"); |
| | | // if( hash.get("name").equals("weaponParameters")) hash.put("name","weaponParameters"); |
| | | String ws = " 堤丰武器系统 堤丰系统" + |
| | | "圣安东尼奥级" + |
| | | " C130 C130飞机 C130运输机 C130炮艇" + |
| | | "何塞黎刹级系统" + |
| | | " 鱼鹰武器系统 鱼鹰系统" + |
| | | "丹鹿级武器系统 丹鹿级系统" + |
| | | "先锋级武器系统 先锋级系统" + |
| | | "支奴干武器系统 支奴干直升机 支奴干系统 支奴干运输机" + |
| | | "黑鹰武器系统 黑鹰直升机 黑鹰系统 黑鹰武装直升机"; |
| | | if( hash.get("name").toLowerCase().equals("weaponsystemparametersinput") |
| | | || hash.get("name").toLowerCase().equals("weaponsystemparameters")){ |
| | | if(ws.indexOf(hash.get("weapons")) > -1 )hash.put("name","weaponSystemParameters"); |
| | | else { |
| | | hash.put("name", "weaponSystemParameters"); |
| | | hash.put("weapons", ""); |
| | | String llm = chatModel.call(message); |
| | | System.out.println("llm:" + llm); |
| | | hash.put("content", llm); |
| | | } |
| | | } |
| | | |
| | | if( hash.get("name").equals("searchTarget")) { |
| | | String entity = hash.get("entity"); |
| | | if( entity.indexOf("政治")>=0 || entity.indexOf("社会")>=0||entity.indexOf("军事")>=0 || |