From e70a362606b78a822e93d5117a9013e8f9086faf Mon Sep 17 00:00:00 2001
From: 秦芳睿 <1425609123@qq.com>
Date: 星期二, 22 四月 2025 09:38:38 +0800
Subject: [PATCH] 1

---
 JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/javaai/qwen/SMTQwenAgentManager.java |  212 +++++++++++++++++++++++++++--------------------------
 1 files changed, 108 insertions(+), 104 deletions(-)

diff --git a/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/javaai/qwen/SMTQwenAgentManager.java b/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/javaai/qwen/SMTQwenAgentManager.java
index 7bb0b36..3b23932 100644
--- a/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/javaai/qwen/SMTQwenAgentManager.java
+++ b/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/javaai/qwen/SMTQwenAgentManager.java
@@ -97,134 +97,138 @@
 	
 	public SMTJavaAIError executeUnknowQuestionAgent(String rawKeyword, SMTAIServerRequest tranReq) throws Exception
 	{
-		int maxQuestion = 5;
-		List<String> listKeyword = new ArrayList<>();
-		
-		// 濡傛灉鍏抽敭瀛楀お闀匡紝鎰忓懗鐫�闇�瑕佸仛浜屾鍒囧垎
-		if(rawKeyword.length() > 1)
+		if(!"鐭ヨ瘑搴�".equals(tranReq.getCurGroupType()))
 		{
-			tranReq.sendChunkedBlock("begin", "鏃犳硶鎵惧埌鍖归厤鐨勬墽琛屽櫒锛屽闂涓叧閿瓧杩涜鍒囧垎");
-			SMTLLMConnect llm = SMTAIServerApp.getApp().allocLLMConnect(null);
-			String sJsonKeywords = llm.callWithMessage(new String[] {"璇峰皢杈撳叆鐨勫唴瀹瑰垏鍒嗘垚鐙珛鐨勫崟璇嶏紝骞朵互json鏁扮粍褰㈠紡琛ㄧず銆備緥濡傦細娴侀噺鍜屽帇鍔涳紝杩斿洖[\"娴侀噺\",\"鍜孿",\"鍘嬪姏\"]"}, rawKeyword, tranReq);
-			Json jsonKeywors = SMTStatic.convLLMAnswerToJson(sJsonKeywords, false);
-			if(jsonKeywors != null && jsonKeywors.isArray())
+		
+			int maxQuestion = 5;
+			List<String> listKeyword = new ArrayList<>();
+			
+			// 濡傛灉鍏抽敭瀛楀お闀匡紝鎰忓懗鐫�闇�瑕佸仛浜屾鍒囧垎
+			if(rawKeyword.length() > 1)
 			{
-				for(Json jsonKeyword : jsonKeywors.asJsonList())
+				tranReq.sendChunkedBlock("begin", "鏃犳硶鎵惧埌鍖归厤鐨勬墽琛屽櫒锛屽闂涓叧閿瓧杩涜鍒囧垎");
+				SMTLLMConnect llm = SMTAIServerApp.getApp().allocLLMConnect(null);
+				String sJsonKeywords = llm.callWithMessage(new String[] {"璇峰皢杈撳叆鐨勫唴瀹瑰垏鍒嗘垚鐙珛鐨勫崟璇嶏紝骞朵互json鏁扮粍褰㈠紡琛ㄧず銆備緥濡傦細娴侀噺鍜屽帇鍔涳紝杩斿洖[\"娴侀噺\",\"鍜孿",\"鍘嬪姏\"]"}, rawKeyword, tranReq);
+				Json jsonKeywors = SMTStatic.convLLMAnswerToJson(sJsonKeywords, false);
+				if(jsonKeywors != null && jsonKeywors.isArray())
 				{
-					listKeyword.add(jsonKeyword.asString());
+					for(Json jsonKeyword : jsonKeywors.asJsonList())
+					{
+						listKeyword.add(jsonKeyword.asString());
+					}
 				}
 			}
-		}
-		
-		// 濡傛灉鍏抽敭瀛楀瓨鍦紝鍒欑洿鎺ヤ娇鐢�
-		if(listKeyword.size() == 0)
-		{
-			tranReq.sendChunkedBlock("begin", "鍏抽敭瀛楀垏鍒嗗け璐�, 鐩存帴鐢ㄥ師濮嬮棶棰樿繘琛屽尮閰�");
-			listKeyword.add(rawKeyword);
-		}
-		
-		// 棣栧厛灏濊瘯浠巃gent涓壘鍒扮浉鍏抽棶棰�
-		List<SMTQwenAgent> listAgent = getUsefulAgentList(tranReq.getAgentGroupSet(), _mapId2Agent, tranReq.getCurGroupType(), null);
-		for(String keywrod : listKeyword)
-		{
-			tranReq.sendChunkedBlock("begin", "寮�濮嬪尮閰嶅叧閿瓧:" + keywrod);
-			for(SMTQwenAgent agent : listAgent)
+			
+			// 濡傛灉鍏抽敭瀛楀瓨鍦紝鍒欑洿鎺ヤ娇鐢�
+			if(listKeyword.size() == 0)
 			{
-				agent.queryUnknowQuestionList(keywrod, tranReq);
+				tranReq.sendChunkedBlock("begin", "鍏抽敭瀛楀垏鍒嗗け璐�, 鐩存帴鐢ㄥ師濮嬮棶棰樿繘琛屽尮閰�");
+				listKeyword.add(rawKeyword);
 			}
 			
-			if(tranReq.getContentSampleQuestionCount() >= maxQuestion)
-				break;
-		}
-			
-		// 濡傛灉鏃犳硶浠巃gent涓壘鍒拌冻澶熷闂锛屽垯浠庝緥瀛愪腑瀵绘壘
-		if(tranReq.getContentSampleQuestionCount() < maxQuestion)
-		{
-			tranReq.sendChunkedBlock("begin", "閫傞厤鍣ㄤ腑鍖归厤鐨勭浉鍏抽棶棰樹笉瓒筹紝浠庝緥瀛愪腑瀵绘壘鍖归厤");
-			Set<String> matchQuestion = new HashSet<>();
-			Set<String> randQuestion = new HashSet<>();
-			SMTDatabase db = SMTAIServerApp.getApp().allocDatabase();
-			JaccardSimilarity jaccardSimilarity = new JaccardSimilarity();
-			try
+			// 棣栧厛灏濊瘯浠巃gent涓壘鍒扮浉鍏抽棶棰�
+			List<SMTQwenAgent> listAgent = getUsefulAgentList(tranReq.getAgentGroupSet(), _mapId2Agent, tranReq.getCurGroupType(), null);
+			for(String keywrod : listKeyword)
 			{
-				String curGroupType = tranReq.getCurGroupType();
-				Set<String> setAgentGroup = tranReq.getAgentGroupSet();
-				DBRecords recs = db.querySQL("SELECT A.sample_question, A.sample_match, A.group_id, G.group_type FROM ai_scene_sample A LEFT JOIN ai_scene_group G ON A.group_id=G.group_id", null);
-				for(DBRecord rec : recs.getRecords())
+				tranReq.sendChunkedBlock("begin", "寮�濮嬪尮閰嶅叧閿瓧:" + keywrod);
+				for(SMTQwenAgent agent : listAgent)
 				{
-					String groupId = rec.getString("group_id");
-					
-					// 濡傛灉渚嬪瓙涓嶅湪鏈夋潈闄愬垎缁勶紝鍒欏拷鐣�
-					if(setAgentGroup != null && !setAgentGroup.contains(groupId))
-						continue;
-					
-					String groupType = rec.getString("group_type");
-					if(curGroupType != null && !curGroupType.equals(groupType))
-						continue;
-					
-					// 灏嗕緥瀛愬姞鍏ラ殢鏈洪棶棰樺垪琛�
-					String question = rec.getString("sample_question");
-					if(randQuestion.size() < maxQuestion)
-						randQuestion.add(question);
-					
-					// 濡傛灉渚嬪瓙涓寘鍚叧閿瓧锛屽垯鐩存帴鍔犲叆
-					for(String keywrod : listKeyword)
+					agent.queryUnknowQuestionList(keywrod, tranReq);
+				}
+				
+				if(tranReq.getContentSampleQuestionCount() >= maxQuestion)
+					break;
+			}
+				
+			// 濡傛灉鏃犳硶浠巃gent涓壘鍒拌冻澶熷闂锛屽垯浠庝緥瀛愪腑瀵绘壘
+			if(tranReq.getContentSampleQuestionCount() < maxQuestion)
+			{
+				tranReq.sendChunkedBlock("begin", "閫傞厤鍣ㄤ腑鍖归厤鐨勭浉鍏抽棶棰樹笉瓒筹紝浠庝緥瀛愪腑瀵绘壘鍖归厤");
+				Set<String> matchQuestion = new HashSet<>();
+				Set<String> randQuestion = new HashSet<>();
+				SMTDatabase db = SMTAIServerApp.getApp().allocDatabase();
+				JaccardSimilarity jaccardSimilarity = new JaccardSimilarity();
+				try
+				{
+					String curGroupType = tranReq.getCurGroupType();
+					Set<String> setAgentGroup = tranReq.getAgentGroupSet();
+					DBRecords recs = db.querySQL("SELECT A.sample_question, A.sample_match, A.group_id, G.group_type FROM ai_scene_sample A LEFT JOIN ai_scene_group G ON A.group_id=G.group_id", null);
+					for(DBRecord rec : recs.getRecords())
 					{
-						// 濡傛灉鍏抽敭瀛楀寘鍚湪闂涓紝鍒欑洿鎺ュ姞鍏ュ苟閫�鍑�
-						if(question.indexOf(keywrod) >= 0)
-						{
-							tranReq.sendChunkedBlock("begin", "鍏抽敭瀛梉" + keywrod + "]鍖呭惈鍦ㄩ噷瀛怺" + question + "]涓�");
-							matchQuestion.add(question);
-							break;
-						}
+						String groupId = rec.getString("group_id");
 						
-						// 濡傛灉瀛樺湪鍖归厤瀛楁锛屽垯鎸夌収鍖归厤瀛楁鍜屽叧閿瓧鍖归厤鐩镐技搴�
-						String sJsonMatch = rec.getString("sample_match");
-						if(!SMTStatic.isNullOrEmpty(sJsonMatch))
+						// 濡傛灉渚嬪瓙涓嶅湪鏈夋潈闄愬垎缁勶紝鍒欏拷鐣�
+						if(setAgentGroup != null && !setAgentGroup.contains(groupId))
+							continue;
+						
+						String groupType = rec.getString("group_type");
+						if(curGroupType != null && !curGroupType.equals(groupType))
+							continue;
+						
+						// 灏嗕緥瀛愬姞鍏ラ殢鏈洪棶棰樺垪琛�
+						String question = rec.getString("sample_question");
+						if(randQuestion.size() < maxQuestion)
+							randQuestion.add(question);
+						
+						// 濡傛灉渚嬪瓙涓寘鍚叧閿瓧锛屽垯鐩存帴鍔犲叆
+						for(String keywrod : listKeyword)
 						{
-							for(Json jsonMatch : Json.read(sJsonMatch).asJsonList())
+							// 濡傛灉鍏抽敭瀛楀寘鍚湪闂涓紝鍒欑洿鎺ュ姞鍏ュ苟閫�鍑�
+							if(question.indexOf(keywrod) >= 0)
 							{
-								String sMatch = jsonMatch.asString();
-								double match = jaccardSimilarity.apply(keywrod, sMatch);
-								if(match > 0.3 || sMatch.indexOf(keywrod) >= 0 || keywrod.indexOf(sMatch) >= 0)
+								tranReq.sendChunkedBlock("begin", "鍏抽敭瀛梉" + keywrod + "]鍖呭惈鍦ㄩ噷瀛怺" + question + "]涓�");
+								matchQuestion.add(question);
+								break;
+							}
+							
+							// 濡傛灉瀛樺湪鍖归厤瀛楁锛屽垯鎸夌収鍖归厤瀛楁鍜屽叧閿瓧鍖归厤鐩镐技搴�
+							String sJsonMatch = rec.getString("sample_match");
+							if(!SMTStatic.isNullOrEmpty(sJsonMatch))
+							{
+								for(Json jsonMatch : Json.read(sJsonMatch).asJsonList())
 								{
-									tranReq.sendChunkedBlock("begin", "鍏抽敭瀛梉" + keywrod + "]鍜屼緥瀛怺" + sMatch + "]鐨勫尮閰嶅害涓�:" + match);
-									matchQuestion.add(question);
-									break;
+									String sMatch = jsonMatch.asString();
+									double match = jaccardSimilarity.apply(keywrod, sMatch);
+									if(match > 0.3 || sMatch.indexOf(keywrod) >= 0 || keywrod.indexOf(sMatch) >= 0)
+									{
+										tranReq.sendChunkedBlock("begin", "鍏抽敭瀛梉" + keywrod + "]鍜屼緥瀛怺" + sMatch + "]鐨勫尮閰嶅害涓�:" + match);
+										matchQuestion.add(question);
+										break;
+									}
 								}
 							}
+							
 						}
-						
 					}
-				}
-			
-				// 灏嗘壘鍒扮殑鏁版嵁鍔犲叆鍖归厤鍒楄〃
-				if(matchQuestion.size() < maxQuestion)
-				{
-					tranReq.sendChunkedBlock("begin", "鍖归厤鍒扮殑渚嬪瓙涓暟涓嶈冻锛屽姞鍏ラ殢鏈哄尮閰嶇殑渚嬪瓙");
-					for(String randQ : randQuestion)
+				
+					// 灏嗘壘鍒扮殑鏁版嵁鍔犲叆鍖归厤鍒楄〃
+					if(matchQuestion.size() < maxQuestion)
 					{
-						if(matchQuestion.size() >= maxQuestion)
-							break;
-						
-						tranReq.sendChunkedBlock("begin", "鍔犲叆闅忔満鍖归厤渚嬪瓙:" + randQ);
-						matchQuestion.add(randQ);
+						tranReq.sendChunkedBlock("begin", "鍖归厤鍒扮殑渚嬪瓙涓暟涓嶈冻锛屽姞鍏ラ殢鏈哄尮閰嶇殑渚嬪瓙");
+						for(String randQ : randQuestion)
+						{
+							if(matchQuestion.size() >= maxQuestion)
+								break;
+							
+							tranReq.sendChunkedBlock("begin", "鍔犲叆闅忔満鍖归厤渚嬪瓙:" + randQ);
+							matchQuestion.add(randQ);
+						}
 					}
+					
+					// 灏嗗尮閰嶅垪琛ㄦ暟鎹姞鍏ヨ繑鍥�
+					for(String matchQ : matchQuestion)
+					{
+						tranReq.addContentSampleQuestion(matchQ);
+					}
+					
+					// 鍙繚鐣欓檺瀹氶棶棰�
+					tranReq.sendChunkedBlock("begin", "闄愬畾鍖归厤鍚庣殑闂鏉$洰涓�" + maxQuestion + "鏉�");
+					tranReq.limitContentSampleQuestion(maxQuestion);
 				}
-				
-				// 灏嗗尮閰嶅垪琛ㄦ暟鎹姞鍏ヨ繑鍥�
-				for(String matchQ : matchQuestion)
+				finally
 				{
-					tranReq.addContentSampleQuestion(matchQ);
+					db.close();
 				}
-				
-				// 鍙繚鐣欓檺瀹氶棶棰�
-				tranReq.sendChunkedBlock("begin", "闄愬畾鍖归厤鍚庣殑闂鏉$洰涓�" + maxQuestion + "鏉�");
-				tranReq.limitContentSampleQuestion(maxQuestion);
-			}
-			finally
-			{
-				db.close();
 			}
 		}
 			

--
Gitblit v1.9.3