赞
踩
在日常使用大模型的时候你是否遇到过以下问题:
需要自己字斟句酌提示词(Prompt),进行CoT
需要自己为大模型分解任务
需要在多种大模型,多种工具(绘图模型,集成开发环境IDE,搜索引擎….)之间辗转才能达到最终目标......
这些都是普遍存在,靠目前的单一模型无法解决的问题。把时间推回到250万年前,旧石器时代见证了人类从简单工具的使用者到复杂技术创造者的转变。我们的祖先南方古猿、直立人等,逐步发展出更高级的工具,如手斧和刮刀,以适应狩猎和生活的需求。大约4万年前,现代人类——智人——的出现标志着技术和文化的飞跃,工具进一步精致化如骨针、鱼钩,艺术创作如洞穴壁画和雕塑也随之兴起。这一时期,火的利用、语言和社会结构的形成,为人类文明的后续发展奠定了坚实的基础。
我们无法保证大模型的“进化”和人类的进化史必定存在强相关性,不过,若以历史作为教科书,解决问题的答案或许已在书中沉淀万年。我们相信,大模型调用工具的能力(或称作智能体能力)是解决前文问题的一种有效方法。
我们在 bigmodel.cn[1]对最新的GLM-4-AllTools API进行了评测。
GLM-4-AllTools: Chat API,集成了调用工具的能力,能够自主使用多种工具组合和多轮对话来达成用户任务。和传统LLM API相比,GLM-4-AllTools API集成了五大核心功能,包括智能编程助手,安全代码沙盒,实时联网搜索,绘图设计工具,函数调用能力。其中函数调用功能支持用户自定义函数,为进阶开发者提供了便利。当模型识别到解决用户输入的请求需要搜索引擎时,它会自动激活内置的联网搜索功能,以提供实时且全面的搜索结果。搜索完成后,内置的网页浏览工具能够打开并细致查看网页内容,从而进行更深入的分析。此外,借助卓越的自我规划能力和内置的代码沙盒、绘图设计等工具,API能够仅通过一次互动就高效地处理复杂的任务。
下面请跟随我们的脚步,我们将一步一步组合这些工具,测试GLM-4-AllTools的真正实力:
Tools: Web Search
代码:
- from zhipuai import ZhipuAI
- client = ZhipuAI(api_key="Zhipu API Key") # 请填写您自己的APIKey
-
- response = client.chat.completions.create(
- model="glm-4-alltools", # 填写需要调用的模型名称
- stream=True,
- messages=[
- {
- "role": "user",
- "content":[
- {
- "type":"text",
- "text":"帮我查询本届欧洲杯淘汰赛对阵情况。"
- }
- ]
- }
- ],
- tools=[
- {
- "type": "web_browser" #联网搜索
- },
- ]
- )
-
- for trunk in response:
- if trunk.choices[0].delta.content is not None:
- print(trunk.choices[0].delta.content, end="")
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
回复:
- 2024年欧洲杯淘汰赛的对阵情况如下:
-
- - 6月30日:
- - 瑞士 vs 意大利(00:00)
- - 德国 vs 丹麦(03:00)
-
- - 7月1日:
- - 英格兰 vs 斯洛伐克(00:00)
- - 西班牙 vs 格鲁吉亚(03:00)
-
- - 7月2日:
- - 法国 vs 比利时(00:00)
- - 葡萄牙 vs 斯洛文尼亚(03:00)
-
- - 7月3日:
- - 荷兰 vs 罗马尼亚(00:00)
- - 奥地利 vs 土耳其(03:00)
-
- 请注意,以上时间均为北京时间。
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
Tools: Web Search, Code Interpreter, Sandbox
- from zhipuai import ZhipuAI
- client = ZhipuAI(api_key="") # 请填写您自己的APIKey
-
- response = client.chat.completions.create(
- model="glm-4-alltools", # 填写需要调用的模型名称
- stream=True,
- messages=[
- {
- "role": "user",
- "content":[
- {
- "type":"text",
- "text":"帮我查询慕尼黑07/05至07/15的日平均气温。并将所有平均气温数值组成数列,绘出折线图显示趋势。"
- }
- ]
- }
- ],
- tools=[
- {
- "type": "web_browser"
- },
- {
- "type": "code_interpreter", #智能编程助手
- },
- ]
- )
-
-
- for trunk in response:
- print(trunk)
- if trunk.choices[0].delta.content is not None:
- print(trunk.choices[0].delta.content, end="")
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
回复:这次我们进入到GLM-4-AllTools API的工作流中,看看模型为了解决Case2执行了哪些步骤:
- #search
- ChatCompletionChunk(id='8822098568301210663', choices=[Choice(delta=ChoiceDelta(content=None, role='assistant', tool_calls=[ChoiceDeltaToolCall(index=None, id='call_bwN-_DC2XvXuP2meMxKzd', function=None, type='web_browser', web_browser={'input': 'search'})]), finish_reason=None, index=0)], created=1720460600, model='glm-4-alltools', usage=None, extra_json=None)
- ChatCompletionChunk(id='8822098568301210663', choices=[Choice(delta=ChoiceDelta(content=None, role='assistant', tool_calls=[ChoiceDeltaToolCall(index=None, id='call_bwN-_DC2XvXuP2meMxKzd', function=None, type='web_browser', web_browser={'input': '("'})]), finish_reason=None, index=0)], created=1720460600, model='glm-4-alltools', usage=None, extra_json=None)
- ChatCompletionChunk(id='8822098568301210663', choices=[Choice(delta=ChoiceDelta(content=None, role='assistant', tool_calls=[ChoiceDeltaToolCall(index=None, id='call_bwN-_DC2XvXuP2meMxKzd', function=None, type='web_browser', web_browser={'input': 'M'})]), finish_reason=None, index=0)], created=1720460600, model='glm-4-alltools', usage=None, extra_json=None)
- ChatCompletionChunk(id='8822098568301210663', choices=[Choice(delta=ChoiceDelta(content=None, role='assistant', tool_calls=[ChoiceDeltaToolCall(index=None, id='call_bwN-_DC2XvXuP2meMxKzd', function=None, type='web_browser', web_browser={'input': 'un'})]), finish_reason=None, index=0)], created=1720460600, model='glm-4-alltools', usage=None, extra_json=None)
- ChatCompletionChunk(id='8822098568301210663', choices=[Choice(delta=ChoiceDelta(content=None, role='assistant', tool_calls=[ChoiceDeltaToolCall(index=None, id='call_bwN-_DC2XvXuP2meMxKzd', function=None, type='web_browser', web_browser={'input': 'ich'})]), finish_reason=None, index=0)], created=1720460600, model='glm-4-alltools', usage=None, extra_json=None)
- ChatCompletionChunk(id='8822098568301210663', choices=[Choice(delta=ChoiceDelta(content=None, role='assistant', tool_calls=[ChoiceDeltaToolCall(index=None, id='call_bwN-_DC2XvXuP2meMxKzd', function=None, type='web_browser', web_browser={'input': ' average'})]), finish_reason=None, index=0)], created=1720460601, model='glm-4-alltools', usage=None, extra_json=None)
- ChatCompletionChunk(id='8822098568301210663', choices=[Choice(delta=ChoiceDelta(content=None, role='assistant', tool_calls=[ChoiceDeltaToolCall(index=None, id='call_bwN-_DC2XvXuP2meMxKzd', function=None, type='web_browser', web_browser={'input': ' temperature'})]), finish_reason=None, index=0)], created=1720460601, model='glm-4-alltools', usage=None, extra_json=None)
- ChatCompletionChunk(id='8822098568301210663', choices=[Choice(delta=ChoiceDelta(content=None, role='assistant', tool_calls=[ChoiceDeltaToolCall(index=None, id='call_bwN-_DC2XvXuP2meMxKzd', function=None, type='web_browser', web_browser={'input': ' July'})]), finish_reason=None, index=0)], created=1720460601, model='glm-4-alltools', usage=None, extra_json=None)
- ChatCompletionChunk(id='8822098568301210663', choices=[Choice(delta=ChoiceDelta(content=None, role='assistant', tool_calls=[ChoiceDeltaToolCall(index=None, id='call_bwN-_DC2XvXuP2meMxKzd', function=None, type='web_browser', web_browser={'input': ' '})]), finish_reason=None, index=0)], created=1720460601, model='glm-4-alltools', usage=None, extra_json=None)
- ChatCompletionChunk(id='8822098568301210663', choices=[Choice(delta=ChoiceDelta(content=None, role='assistant', tool_calls=[ChoiceDeltaToolCall(index=None, id='call_bwN-_DC2XvXuP2meMxKzd', function=None, type='web_browser', web_browser={'input': '5'})]), finish_reason=None, index=0)], created=1720460601, model='glm-4-alltools', usage=None, extra_json=None)
- ChatCompletionChunk(id='8822098568301210663', choices=[Choice(delta=ChoiceDelta(content=None, role='assistant', tool_calls=[ChoiceDeltaToolCall(index=None, id='call_bwN-_DC2XvXuP2meMxKzd', function=None, type='web_browser', web_browser={'input': ' to'})]), finish_reason=None, index=0)], created=1720460601, model='glm-4-alltools', usage=None, extra_json=None)
- ChatCompletionChunk(id='8822098568301210663', choices=[Choice(delta=ChoiceDelta(content=None, role='assistant', tool_calls=[ChoiceDeltaToolCall(index=None, id='call_bwN-_DC2XvXuP2meMxKzd', function=None, type='web_browser', web_browser={'input': ' July'})]), finish_reason=None, index=0)], created=1720460601, model='glm-4-alltools', usage=None, extra_json=None)
- ...
- ChatCompletionChunk(id='8822098568301210663', choices=[Choice(delta=ChoiceDelta(content=None, role='assistant', tool_calls=[ChoiceDeltaToolCall(index=None, id='call_bwN-_DC2XvXuP2meMxKzd', function=None, type='web_browser', web_browser={'input': ''})]), finish_reason='tool_calls', index=0)], created=1720460601, model='glm-4-alltools', usage=None, extra_json=None)
- ChatCompletionChunk(id='8822098568301210663', choices=[Choice(delta=ChoiceDelta(content=None, role='tool', tool_calls=[ChoiceDeltaToolCall(index=None, id=None, function=None, type='web_browser', web_browser={'outputs': [{'title': 'Weather in Munich in July 2024', 'link': 'https://world-weather.info/forecast/germany/munich/july-2024/', 'content': 'Detailed ⚡ Munich Weather Forecast for July 2024 – day/night 声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/834199推荐阅读
相关标签
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。