更新API密钥管理,优化意图识别和Excel数据验证功能,增强日志记录,改进错误处理机制,支持文档检索功能,提升代码可读性和灵活性。

This commit is contained in:
2025-06-24 17:12:09 +08:00
parent 4386cfac41
commit 7142c7c43e
8 changed files with 352 additions and 324 deletions
@@ -635,7 +635,7 @@ class IntentRecognizer:
return parsed_output
except Exception as e:
# 如果解析失败,返回原始查询作为后退提示
logging.error(f"后退提示生成失败: {e}")
logging.error(f"后退提示生成失败: {e}", exc_info=True)
return StepBackPrompt(original_query=query, step_back_query=query)
def _generate_follow_up_questions(self, query: str, chat_history: List[Dict[str, str]] = None, conversation_context: str = "") -> FollowUpQuestions:
@@ -672,7 +672,7 @@ class IntentRecognizer:
return parsed_output
except Exception as e:
# 如果解析失败,返回原始查询作为后续问题
logging.error(f"后续问题生成失败: {e}")
logging.error(f"后续问题生成失败: {e}", exc_info=True)
return FollowUpQuestions(original_query=query, follow_up_query=query)
def _generate_hypothetical_document(self, query: str, chat_history: List[Dict[str, str]] = None, conversation_context: str = "") -> HypotheticalDocument:
@@ -709,7 +709,7 @@ class IntentRecognizer:
return parsed_output
except Exception as e:
# 如果解析失败,返回空的假设性回答
logging.error(f"假设性文档生成失败: {e}")
logging.error(f"假设性文档生成失败: {e}", exc_info=True)
return HypotheticalDocument(original_query=query, hypothetical_answer="")
def _generate_multi_questions(self, query: str, chat_history: List[Dict[str, str]] = None, conversation_context: str = "") -> MultiQuestions:
@@ -746,7 +746,7 @@ class IntentRecognizer:
return parsed_output
except Exception as e:
# 如果解析失败,返回原始查询作为唯一子问题
logging.error(f"多角度问题生成失败: {e}LLM返回内容:{response.content}")
logging.error(f"多角度问题生成失败: {e}",exc_info=True)
return MultiQuestions(original_query=query, sub_questions=[query])
def _run_in_thread(self, func, args=(), kwargs={}):
@@ -768,7 +768,7 @@ class IntentRecognizer:
result = func(*args, **kwargs)
result_container.append(result)
except Exception as e:
logging.error(f"线程执行函数 {func.__name__} 时出错: {e}")
logging.error(f"线程执行函数 {func.__name__} 时出错: {e}", exc_info=True)
result_container.append(None)
thread = threading.Thread(target=thread_target)
@@ -866,5 +866,4 @@ class IntentRecognizer:
return result
except Exception as e:
logging.error(f"process_intent_and_slot error:{e}")
raise RuntimeError(f"process_intent_and_slot error:{e}") from e
@@ -93,7 +93,7 @@ class ProfessionalNounVectorizer:
logging.info(f"总共加载了 {len(merged_terms)} 条专业名词")
return merged_terms
except Exception as e:
logging.error(f"加载多个文件失败: {e}")
logging.error(f"加载多个文件失败: {e}", exc_info=True)
return []
def vectorize_files_and_save(self, file_paths: List[str]) -> bool:
@@ -139,7 +139,7 @@ class ProfessionalNounVectorizer:
logging.info("完成多文件专业名词向量化和索引创建")
return True
except Exception as e:
logging.error(f"多文件向量化处理失败: {e}")
logging.error(f"多文件向量化处理失败: {e}", exc_info=True)
return False
def _updata_suffix_item(self)->Tuple[List[str], List[Dict]] :
@@ -246,7 +246,7 @@ class ProfessionalNounVectorizer:
faiss_index.save_local(folder_path=self.index_path)
logging.info(f"FAISS索引已保存至 {self.index_path}")
except Exception as e:
logging.error(f"保存FAISS索引失败: {e}")
logging.error(f"保存FAISS索引失败: {e}", exc_info=True)
raise e
@@ -349,5 +349,5 @@ class ProfessionalNounRetriever:
return [json.loads(item) for item in intersection]
except Exception as e:
logging.error(f"查询FAISS索引失败: {e}")
logging.error(f"查询FAISS索引失败: {e}", exc_info=True)
return []