dify学习笔记之天气小助手搭建
1.天气小助手工作流搭建
- (1) 去高德开放平台上注册一个用户,并申请一个key
- (2) 下载高德地图地理编码表
AMap_adcode_citycode.xlsx
> wget https://modelscope.oss-cn-beijing.aliyuncs.com/resource/agent/AMap_adcode_citycode.xlsx
- (3) 使用高德地图地理编码表创建一个知识库
"知识库" -> “创建知识库” -> 上传 AMap_adcode_citycode.xlsx
文件 -> 配置知识库,可以不用rerank模型
-
(4)
dify市场
搜索amap_weather
,安装工具,并添加key -
(5) 搭建天气助手工作流:
注意,这里 LLM
的提示词设置为:根据用户输入和知识检索的结果,输出用户期望得到的中文名。只需要给出准确的adcode的值,禁止出现 “think” 相关内容。
- (6) 测试效果:单击""运行" -> 设置“输入” -> 单击“开始运行”即可。
2.问题处理
直接使用插件可能会出现如下所示:No weather information for 350200 was found.
多余信息:
处理办法有三种:
2.1 修改工具源码
源码路径为:dify/docker/volumes/plugin_daemon/cwd/langgenius/gaode-0.0.2@960a445e3b92f6fe774486411305bc0e78bd515d583f6dac7f2f77af9d162446/tools/gaode_weather.py
,做如下修改:
# 修改前
s.close()
yield self.create_text_message(f"No weather information for {city} was found.")
# 修改后:
else:
s.close()
yield self.create_text_message(f"No weather information for {city} was found.")
然后重启一下dify的docker
2.2 使用 Http请求
工具
将 天气预报
节点,替换为 Http请求
节点,然后设置如下内容:
API:https://restapi.amap.com/v3/weather/weatherInfo?parameters
PARAMS:
key:输入注册高德的key值
city: adcode
2.3 使用fastapi搭建一个服务
懒得写了,可以参考前面一节内容
3.参考资料
- [1] Dify应用实战(1)
- [2] dify工作流应用2-HTTP节点实现高德天气查询