mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-23 07:33:53 +08:00
* function call功能完善,增加天气查询,支持插件式扩展 * 增加角色切换功能,通过切换system提示词,修改角色认知 * 增加插件管理系统,可以通过语音加载和卸载插件 * docs: 添加命令操作 (#329) * docs: 添加命令操作 * feat: 添加 docker-setup.sh 脚本以简化服务端部署 - 新增 docker-setup.sh 脚本,自动创建目录结构、下载语音识别模型和配置文件,并检查文件完整性。 - 更新 Deployment.md 文档,提供一键执行脚本的说明和使用示例。 * docs: 更新 Deployment.md,添加环境访问 GitHub 的注意事项 * refactor: 更新 docker-setup.sh 脚本以支持多操作系统下载命令 - 修改脚本以检测操作系统类型,并根据不同系统选择合适的下载命令(curl 或 wget)。 - 优化错误处理,确保在下载失败时提供清晰的提示信息。 - 更新 Deployment.md 文档,调整懒人脚本的使用说明,增加手动部署的步骤。 * Update docker-setup.sh * Update docker-setup.sh --------- Co-authored-by: 欣南科技 <huangrongzhuang@xin-nan.com> * update:优化插件加载的配置提示 * update:增加自动安装脚本的操作说明 * update:优化插件配置,去掉旧版本的时间设定 --------- Co-authored-by: 玄凤科技 <eric230308@gmail.com> Co-authored-by: TinsFox <fox@tinsfox.com> Co-authored-by: hrz <1710360675@qq.com>
43 lines
1.8 KiB
Python
43 lines
1.8 KiB
Python
import requests
|
||
from bs4 import BeautifulSoup
|
||
from plugins_func.register import register_function,ToolType, ActionResponse, Action
|
||
|
||
|
||
get_weather_function_desc = {
|
||
"type": "function",
|
||
"function": {
|
||
"name": "get_weather",
|
||
"description": "获取某个地点的天气,用户应先提供一个位置,比如用户说杭州天气,参数为:zhejiang/hangzhou,比如用户说北京天气怎么样,参数为:beijing/beijing。如果用户只问天气怎么样,参数是:guangdong/guangzhou",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"city": {
|
||
"type": "string",
|
||
"description": "城市,zhejiang/hangzhou"
|
||
}
|
||
},
|
||
"required": [
|
||
"city"
|
||
]
|
||
}
|
||
}
|
||
}
|
||
|
||
@register_function('get_weather', get_weather_function_desc, ToolType.WAIT)
|
||
def get_weather(city: str):
|
||
"""
|
||
"获取某个地点的天气,用户应先提供一个位置,\n比如用户说杭州天气,参数为:zhejiang/hangzhou,\n\n比如用户说北京天气怎么样,参数为:beijing/beijing",
|
||
city : 城市,zhejiang/hangzhou
|
||
"""
|
||
url = "https://tianqi.moji.com/weather/china/"+city
|
||
headers = {
|
||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36'
|
||
}
|
||
response = requests.get(url, headers=headers)
|
||
if response.status_code!=200:
|
||
return ActionResponse(Action.REQLLM, None, "请求失败")
|
||
soup = BeautifulSoup(response.text, "html.parser")
|
||
weather = soup.find('meta', attrs={'name':'description'})["content"]
|
||
weather = weather.replace("墨迹天气", "")
|
||
return ActionResponse(Action.REQLLM, weather, None)
|