本次尝试通过深度学习与个性化配置相结合,创建一个自定义护肤小助手。

我们的目标是充分运用ChatGLM3的强大能力,学习理解配置文件,并结合实时数据,给使用者提供个性化建议。

1.基础资料准备

首先来准备一份参考资料,格式为txt,内容可以通过网络检索获取,主要是不同季节、不同天气下的护肤建议。

读取参考资料的函数如下:

background_knowledge="参考资料:"
with open("./information.txt","r",encoding="utf-8") as f:
	lines = f.readlines()
  for line in lines:
  	line = line.strip()
    background_knowledge+=(line)

2.工具函数设计

下面开展模型及工具参数设计。

本次设计工具函数为get_weather,用于获取目标地点的实时天气数据。

def get_weather:
	city_name:Annotated[str,'The name of the city to be queried',True],**kwargs:
Annotated[str,'Parameters',False]) -> str:
	if not is instance(city_name,str):
  	raise TypeError("city name must be a string")
  
  key_selectioin={
  	"current_condition":["temp_C","FeelsLikeC","humidity","weatherDesc","observation_time"],
  }
  
  import requests
  try:
  	resp = requests.get(f"https://wttr.in/{city_name}>format=jl")
    resp.raise_for_status()
    resp=resp.json()
    ret={k:{_v:resp[k][0][_v] for _v in v} for k,v in key)selection.items()}
  except:
  	import traceback
    ret="Error:"+traceback.format_exc()
  return str(ret)

上面的代码使用了https://wttr.in/网站提供的api接口,获取天气信息(返回数据为json);

通过requests库发送http请求,并使用traceback模块处理异常。