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 |  168 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 152 insertions(+), 16 deletions(-)

diff --git a/src/main/java/com/yb/controller/AiController.java b/src/main/java/com/yb/controller/AiController.java
index 8694787..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,22 +31,83 @@
     @Value("${spring.intent}")
     String intent ;
 
-
+    @Autowired
+    WebSocketController webSocketController;
 
     @GetMapping("/chat")
     @Operation(summary = "澶фā鍨嬪璇�")
     public String chat(@RequestParam(value = "message",defaultValue = "Hi") String message){
-        return chatModel.call("璇风敤涓枃鍥炵瓟濡備笅闂,濡傛灉鏈夊湴鍚嶅嚭鐜帮紝鍥炲埌鍐呭鍖呮嫭缁忕含搴﹀苟浣跨敤json杩斿洖,"+message);
+        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;
@@ -72,21 +128,26 @@
     @GetMapping("/mix")
     @Operation(summary = "鎰忓浘涓庡ぇ妯″瀷璇锋眰")
     public String mix(@RequestParam(value = "message",defaultValue = "Hi") String message){
-        String json = okHttpUtil.postFastgpt(message);
+        String json = okHttpUtil.getMessage(intent+"="+message);
         System.out.println(message);
 //        JSONObject jsonObject = JSONObject.parseObject(json);
         Map<String,String> hashMap = new HashMap<>() ;
-        iteraJson(json,hashMap);
+        String place = null ;
+        if( json != null) {
 
-        String place = hashMap.get("place");
+            iteraJson(json, hashMap);
+            intentSwitch(hashMap,message);
+            place = hashMap.get("place");
+        }
         if( place != null ){
-            String llm = chatModel.call("璇风敤涓枃鍥炵瓟濡備笅闂,濡傛灉鏈夊湴鍚嶅嚭鐜帮紝鍥炲埌鍐呭鍖呮嫭缁忕含搴﹀苟浣跨敤json杩斿洖,"+place);
+            String llm = chatModel.call(place);
            hashMap.put("content",llm);
 
           json =   JSON.toJSON(hashMap).toString() ;
         }else{
-            json = hashMap.put("content", chatModel.call("璇风敤涓枃鍥炵瓟濡備笅闂,濡傛灉鏈夊湴鍚嶅嚭鐜帮紝鍥炲埌鍐呭鍖呮嫭缁忕含搴﹀苟浣跨敤json杩斿洖,"+message));
+            json = hashMap.put("content", chatModel.call(message));
         }
+        hashMap.put("code","200");
         System.out.println(JSON.toJSON(hashMap).toString());
         System.out.println("====================================");
         return JSON.toJSON(hashMap).toString() ;
@@ -96,9 +157,9 @@
 
     @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);
+        //okHttpUtil.requesFast(message);
         String json = okHttpUtil.requesFast(message);
 
         return  json ;
@@ -113,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