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 | 97 +++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 86 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/yb/controller/AiController.java b/src/main/java/com/yb/controller/AiController.java index 7e3df4a..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,16 +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; @@ -103,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); @@ -152,8 +206,29 @@ */ 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 = " 鍫や赴姝﹀櫒绯荤粺 鍫や赴绯荤粺" + + "鍦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 || -- Gitblit v1.9.3