| 
					
				 | 
			
			
				@@ -6,6 +6,8 @@ import json 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 from openai import OpenAI 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 from applications.functions.chatgpt import OpenAIServer 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+from applications.config import moon_shot 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+from applications.config import deep_seek 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 from applications.log import logging 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -26,7 +28,7 @@ class KimiServer(object): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         contents = params['article_text'] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         trace_id = params['content_id'] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            kimi_title = await cls.kimi_title(title) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            kimi_title = await cls.kimi_title(title, ai_model=deep_seek) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             # 判断kimi 标题是否安全 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             title_score = await cls.get_kimi_title_safe_score(kimi_title) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if int(title_score) > safe_score: 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -48,7 +50,7 @@ class KimiServer(object): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         kimi_title = kimi_title.replace("'", "").replace('"', "").replace("\\", "") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            kimi_info = await cls.kimi_mining(contents) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            kimi_info = await cls.kimi_mining(contents, ai_model=deep_seek) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         except Exception as e: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             logging( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 code="4002", 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -143,10 +145,11 @@ class KimiServer(object): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 f.write(json.dumps(result, ensure_ascii=False)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @classmethod 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    async def kimi_title(cls, ori_title): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    async def kimi_title(cls, ori_title, ai_model): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         prompt + kimi + ori_title generate new title 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         :param ori_title: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        :param ai_model: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         :return: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         single_title_prompt = """ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -167,8 +170,8 @@ class KimiServer(object): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         避免误导:确保标题准确反映内容,避免夸大或误导读者。 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         client = OpenAI( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            api_key='sk-5DqYCa88kche6nwIWjLE1p4oMm8nXrR9kQMKbBolNAWERu7q', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            base_url="https://api.moonshot.cn/v1" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            api_key=ai_model['api_key'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            base_url=ai_model['base_url'] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         chat_completion = client.chat.completions.create( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             messages=[ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -177,16 +180,17 @@ class KimiServer(object): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     "content": ori_title + "\n" + single_title_prompt, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            model="moonshot-v1-32k", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            model=ai_model['model'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         response = chat_completion.choices[0].message.content 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return response.split("\n")[0] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @classmethod 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    async def kimi_mining(cls, text): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    async def kimi_mining(cls, text, ai_model): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         通过文章来挖掘出有效的信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         :param text: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        :param ai_model: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         :return: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         text_prompt = """ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -199,8 +203,8 @@ class KimiServer(object): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         你需要处理的文本是: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         client = OpenAI( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            api_key='sk-5DqYCa88kche6nwIWjLE1p4oMm8nXrR9kQMKbBolNAWERu7q', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            base_url="https://api.moonshot.cn/v1" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            api_key=ai_model['api_key'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            base_url=ai_model['base_url'] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         chat_completion = client.chat.completions.create( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             messages=[ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -209,21 +213,11 @@ class KimiServer(object): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     "content": text_prompt + text, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            model="moonshot-v1-32k", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            model=ai_model['model'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            response_format={"type": "json_object"} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        response = chat_completion.choices[0].message.content.replace('```json', '').replace('```', '') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            response = json.loads(response) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return response 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        except: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            # 处理中文双引号出现在 “key”: “value”情况 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                response_json_string = response.replace('“', '"').replace('”', '"') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                response = json.loads(response_json_string) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return response 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            except Exception as e: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return {} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        content = json.loads(chat_completion.choices[0].message.content) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return content 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @classmethod 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     async def get_kimi_title_safe_score(cls, kimi_title): 
			 |