本仓库包含我使用大型模型GLM4.0进行函数调用的实践和实现。文章结尾附带具体代码文件。
1、天气查询
首先是天气查询接口,该接口来源于YY天气,是一个免费的天气查询接口,可查询到包括天气状况、温度、风力、风向以及湿度等信息。cityid.json为该天气查询接口的城市id信息。
def get_current_weather(city: str):
f = open("cityid.json", "r", encoding="utf-8")
fr = json.loads(f.read())
f.close()
# 换上你的api_key
key = "you api_key"
url = f"http://api.yytianqi.com/observe?city={
fr[city.lower()]}&key={
key}"
res = requests.get(url)
data = res.json()["data"]
if res.status_code == 200:
return f"""lastUpdate:{
data["lastUpdate"]} | weather:{
data["tq"]} | temperature:{
data["qw"]} |
wind power:{
data