Prechádzať zdrojové kódy

Update user_profile_extractor: support customize prompt

StrayWarrior 3 dní pred
rodič
commit
1806a6d5e4
1 zmenil súbory, kde vykonal 4 pridanie a 2 odobranie
  1. 4 2
      pqai_agent/user_profile_extractor.py

+ 4 - 2
pqai_agent/user_profile_extractor.py

@@ -147,11 +147,12 @@ class UserProfileExtractor:
             logger.error(f"用户画像提取出错: {e}")
             return None
 
-    def extract_profile_info_v2(self, user_profile: Dict, dialogue_history: List[Dict]) -> Optional[Dict]:
+    def extract_profile_info_v2(self, user_profile: Dict, dialogue_history: List[Dict], prompt_template: Optional[str] = None) -> Optional[Dict]:
         """
         使用JSON输出提取用户画像信息
         :param user_profile:
         :param dialogue_history:
+        :param prompt_template: 可选的自定义提示模板
         :return:
         """
         if configs.get().get('debug_flags', {}).get('disable_llm_api_call', False):
@@ -159,7 +160,8 @@ class UserProfileExtractor:
 
         try:
             logger.debug("try to extract profile from message: {}".format(dialogue_history))
-            prompt = self.generate_extraction_prompt(user_profile, dialogue_history, USER_PROFILE_EXTRACT_PROMPT_V2)
+            prompt_template = prompt_template or USER_PROFILE_EXTRACT_PROMPT_V2
+            prompt = self.generate_extraction_prompt(user_profile, dialogue_history, prompt_template)
             print(prompt)
             response = self.llm_client.chat.completions.create(
                 model=self.model_name,