mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-26 04:39:53 +01:00
fix: prevent tool description cache mutation
This commit is contained in:
parent
c8e60d1325
commit
99a62665e0
1 changed files with 6 additions and 3 deletions
|
|
@ -47,9 +47,12 @@ class ToolManager:
|
||||||
return all_tools
|
return all_tools
|
||||||
|
|
||||||
def get_function_descriptions(self) -> List[Dict[str, Any]]:
|
def get_function_descriptions(self) -> List[Dict[str, Any]]:
|
||||||
"""获取所有工具的函数描述(OpenAI格式)"""
|
"""获取所有工具的函数描述(OpenAI格式)
|
||||||
|
|
||||||
|
返回缓存的浅拷贝,防止调用方就地修改污染缓存。
|
||||||
|
"""
|
||||||
if self._cached_function_descriptions is not None:
|
if self._cached_function_descriptions is not None:
|
||||||
return self._cached_function_descriptions
|
return list(self._cached_function_descriptions)
|
||||||
|
|
||||||
descriptions = []
|
descriptions = []
|
||||||
tools = self.get_all_tools()
|
tools = self.get_all_tools()
|
||||||
|
|
@ -57,7 +60,7 @@ class ToolManager:
|
||||||
descriptions.append(tool_definition.description)
|
descriptions.append(tool_definition.description)
|
||||||
|
|
||||||
self._cached_function_descriptions = descriptions
|
self._cached_function_descriptions = descriptions
|
||||||
return descriptions
|
return list(descriptions)
|
||||||
|
|
||||||
def has_tool(self, tool_name: str) -> bool:
|
def has_tool(self, tool_name: str) -> bool:
|
||||||
"""检查是否存在指定工具"""
|
"""检查是否存在指定工具"""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue