mirror of
https://github.com/RYDE-WORK/Langchain-Chatchat.git
synced 2026-01-28 01:33:17 +08:00
- 修复:
- Qwen Agent 的 OutputParser 不再抛出异常,遇到非 COT 文本直接返回
- CallbackHandler 正确处理工具调用信息
- 重写 tool 定义方式:
- 添加 regist_tool 简化 tool 定义:
- 可以指定一个用户友好的名称
- 自动将函数的 __doc__ 作为 tool.description
- 支持用 Field 定义参数,不再需要额外定义 ModelSchema
- 添加 BaseToolOutput 封装 tool 返回结果,以便同时获取原始值、给LLM的字符串值
- 支持工具热加载(有待测试)
- 增加 openai 兼容的统一 chat 接口,通过 tools/tool_choice/extra_body 不同参数组合支持:
- Agent 对话
- 指定工具调用(如知识库RAG)
- LLM 对话
- 根据后端功能更新 webui
28 lines
1.0 KiB
Python
28 lines
1.0 KiB
Python
"""
|
|
简单的单参数输入工具实现,用于查询现在天气的情况
|
|
"""
|
|
from chatchat.server.pydantic_v1 import Field
|
|
from chatchat.server.utils import get_tool_config
|
|
from .tools_registry import regist_tool, BaseToolOutput
|
|
import requests
|
|
|
|
|
|
@regist_tool(title="天气查询")
|
|
def weather_check(city: str = Field(description="City name,include city and county,like '厦门'")):
|
|
'''Use this tool to check the weather at a specific city'''
|
|
|
|
tool_config = get_tool_config("weather_check")
|
|
api_key = tool_config.get("api_key")
|
|
url = f"https://api.seniverse.com/v3/weather/now.json?key={api_key}&location={city}&language=zh-Hans&unit=c"
|
|
response = requests.get(url)
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
weather = {
|
|
"temperature": data["results"][0]["now"]["temperature"],
|
|
"description": data["results"][0]["now"]["text"],
|
|
}
|
|
return BaseToolOutput(weather)
|
|
else:
|
|
raise Exception(
|
|
f"Failed to retrieve weather: {response.status_code}")
|