From 55e607b91e8058a7fe713fa07cd4c829b5593aa5 Mon Sep 17 00:00:00 2001 From: leutu <leutu@qq.com> Date: 星期二, 27 八月 2024 09:30:57 +0800 Subject: [PATCH] 更新 --- src/main/java/com/yb/controller/AiController.java | 152 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 142 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/yb/controller/AiController.java b/src/main/java/com/yb/controller/AiController.java index 2ded6a3..a8cf2cf 100644 --- a/src/main/java/com/yb/controller/AiController.java +++ b/src/main/java/com/yb/controller/AiController.java @@ -8,19 +8,14 @@ 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") @@ -36,7 +31,8 @@ @Value("${spring.intent}") String intent ; - + @Autowired + WebSocketController webSocketController; @GetMapping("/chat") @Operation(summary = "澶фā鍨嬪璇�") @@ -44,14 +40,74 @@ 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; @@ -78,8 +134,9 @@ Map<String,String> hashMap = new HashMap<>() ; String place = null ; if( json != null) { - iteraJson(json, hashMap); + iteraJson(json, hashMap); + intentSwitch(hashMap,message); place = hashMap.get("place"); } if( place != null ){ @@ -100,7 +157,7 @@ @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); @@ -117,4 +174,79 @@ return json ; } + /* + def anomalyCheck(time,place): 銆愭槧灏勫埌鎰忓浘1銆� + """寮傚父鎯呭喌鏌ヨ銆傛煡璇㈠湪鏌愪釜鏃堕棿鏌愪釜鍦扮偣鐨勫紓甯告儏鍐碉紝涓庡線鏃ユ湁浣曚笉鍚屻�傛煡鐪嬫煇涓湴鐐圭殑鍗槦鍥剧墖銆�""" + + scanWeapon(); + ======================================= + def weaponParameters(weapons): 銆愭槧灏勫埌鎰忓浘2銆� + """姝﹀櫒璇︾粏鍙傛暟鏌ヨ銆傛煡璇㈡鍣ㄧ殑璇︾粏淇℃伅銆傛煡璇㈡鍣ㄧ殑鍏蜂綋鍙傛暟銆�""" + raise ToolException(f"娌℃湁鍚嶇О涓簕weapons}鐨勬鍣ㄣ��") + + weaponParameters(); + ========================================= + + def searchTarget(place, entity): 銆愭槧灏勫埌鎰忓浘3,4,5,6 +銆�1. 杈撳叆鍙傛暟涓猴細鏀挎不鐩爣锛岀ぞ浼氱洰鏍囷紝鍐涗簨鐩爣锛屾皯瀹咃紝鍖婚櫌瀵瑰簲鎰忓浘3.4 +searchTarget(); +2.杈撳叆鍙傛暟涓猴細鍙墦鍑荤洰鏍�/涓嶅彲鎵撳嚮鐩爣瀵瑰簲鎰忓浘5 +searchStrikeableTarget(); +3.杈撳叆鍙傛暟涓猴細缇庡浗绌哄啗鎸囨尌涓績锛屽搴旀剰鍥�6銆� + """鏌ヨ鏌愬湴鐨勬斂娌荤洰鏍�/绀句細鐩爣/缁忔祹鐩爣/鍐涗簨鐩爣/姘戝畢/鍖婚櫌/鍙墦鍑荤洰鏍�/涓嶅彲鎵撳嚮鐩爣绛夊缓绛戝疄浣撶殑鎯呭喌""" + USAFCommandCenterQuery(); + +def attackanddefenceCenter(weapons: str, place: str): #銆愭槧灏勫埌鎰忓浘7.8銆� + 杩欓噷璁╀綘鍒ゆ柇鏄潃浼ゆ�ф鍣ㄨ繕鏄槻寰℃�ф鍣紝鏉�浼ゆ�ф鍣ㄧ殑灏卞瀵瑰簲鎰忓浘7鏉�浼ゅ崐寰勶紝 + 闃插尽鎬ф鍣ㄥ氨瀵瑰簲鎰忓浘8闃插尽鍗婂緞銆傘�� + """璇ュ伐鍏风殑杈撳叆蹇呴』涓烘鍣ㄥ悕绉板拰鍦扮偣銆傛鍣ㄦā鎷熶豢鐪燂紝缁欏嚭鏌愮鍦烘櫙銆傛鍣ㄥ垎鏋愶紝鍦板浘浠跨湡鎸囦护銆傛垨鑰呮煡璇㈡鍣ㄧ殑鏉�浼ゅ崐寰�/闃茬┖鍗婂緞/鏉�浼よ寖鍥�/闃茬┖鑼冨洿銆�""" +attackUSAFCommandCenter(); +defenceRangeTyphoonSystem(); + + */ + 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"); + String ws = " 鍫や赴姝﹀櫒绯荤粺 鍫や赴绯荤粺" + + "鍦e畨涓滃凹濂ョ骇" + + " 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 || + entity.indexOf("姘戝畢")>=0 || entity.indexOf("鍖婚櫌")>=0 || entity.indexOf("鍏跺畠")>=0) + hash.put("name","searchTarget"); + if( entity.indexOf("鎵撳嚮")>=0 ) + hash.put("name","searchStrikeableTarget"); + if( entity.indexOf("缇庡浗")>=0 || entity.indexOf("绌哄啗")>=0||entity.indexOf("鎸囨尌")>=0 + ||entity.indexOf("涓績")>=0) + hash.put("name","USAFCommandCenterQuery"); + + } + if( hash.get("name").equals("attackanddefenceCenter")) { + if( message.indexOf("鎵撳嚮")>=0 || message.indexOf("鏉�浼�")>=0 || message.indexOf("鎽ф瘉")>=0 || + message.indexOf("鐮村潖")>=0) + hash.put("name","attackUSAFCommandCenter"); + else + hash.put("name","defenceRangeTyphoonSystem"); + } + } } -- Gitblit v1.9.3