2 Star 6 Fork 1

yanlang0123/chatTool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
testGlm4.py 1.91 KB
一键复制 编辑 原始数据 按行查看 历史
马噥 提交于 2024-02-19 20:48 +08:00 . glm4调用
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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yanlang0123/chat-tool.git
git@gitee.com:yanlang0123/chat-tool.git
yanlang0123
chat-tool
chatTool
master

搜索帮助