代码拉取完成,页面将自动刷新
from zhipuai import ZhipuAI
from tool.tool_register import dispatch_tool, get_lm4_tools
import json
client = ZhipuAI(api_key="6795fbe303878f35292f1aa14414e9a4.kOzmNe7PEk1l6zdK") # 请填写您自己的APIKey
# tools = [
# {
# "type": "function",
# "function": {
# "name": "query_train_info",
# "description": "根据用户提供的信息,查询对应的车次",
# "parameters": {
# "type": "object",
# "properties": {
# "departure": {
# "type": "string",
# "description": "出发城市或车站",
# },
# "destination": {
# "type": "string",
# "description": "目的地城市或车站",
# },
# "date": {
# "type": "string",
# "description": "要查询的车次日期",
# },
# },
# "required": ["departure", "destination", "date"],
# },
# }
# }
# ]
tools=get_lm4_tools()
messages = [
{
"role": "user",
"content": "帮我发一条微信消息给老板,告诉他今天太冷了不能准时上班"
}
]
response = client.chat.completions.create(
model="glm-4", # 填写需要调用的模型名称
messages=messages,
tools=tools,
tool_choice="auto",
)
print(response.choices[0].message)
def nested_object_to_dict(obj):
if isinstance(obj, list):
return [nested_object_to_dict(x) for x in obj]
if isinstance(obj, dict):
return {k: nested_object_to_dict(v) for k, v in obj.items()}
if obj and type(obj) not in (int, float, str):
return nested_object_to_dict(vars(obj))
else:
return obj
print(nested_object_to_dict(response.choices[0].message))
client.close()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。