当前位置:   article > 正文

解决问题而非制造问题!GLM-4-AllTools API革新大模型使用体验

解决问题而非制造问题!GLM-4-AllTools API革新大模型使用体验

797aa87acf4811eae369c0e3d8843c88.png

在日常使用大模型的时候你是否遇到过以下问题:

  1. 需要自己字斟句酌提示词(Prompt),进行CoT

  2. 需要自己为大模型分解任务

  3. 需要在多种大模型,多种工具(绘图模型,集成开发环境IDE,搜索引擎….)之间辗转才能达到最终目标......

这些都是普遍存在,靠目前的单一模型无法解决的问题。2d55c2e6549ee05b33c3fc12599af445.png把时间推回到250万年前,旧石器时代见证了人类从简单工具的使用者到复杂技术创造者的转变。我们的祖先南方古猿、直立人等,逐步发展出更高级的工具,如手斧和刮刀,以适应狩猎和生活的需求。大约4万年前,现代人类——智人——的出现标志着技术和文化的飞跃,工具进一步精致化如骨针、鱼钩,艺术创作如洞穴壁画和雕塑也随之兴起。这一时期,火的利用、语言和社会结构的形成,为人类文明的后续发展奠定了坚实的基础。

我们无法保证大模型的“进化”和人类的进化史必定存在强相关性,不过,若以历史作为教科书,解决问题的答案或许已在书中沉淀万年。我们相信,大模型调用工具的能力(或称作智能体能力)是解决前文问题的一种有效方法。

GLM-4-AllTools - 革新大模型API调用体验

b301ef1b2162476b9e67847dc752c895.png我们在 bigmodel.cn[1]对最新的GLM-4-AllTools API进行了评测。

GLM-4-AllTools: Chat API,集成了调用工具的能力,能够自主使用多种工具组合和多轮对话来达成用户任务。和传统LLM API相比,GLM-4-AllTools API集成了五大核心功能,包括智能编程助手,安全代码沙盒,实时联网搜索,绘图设计工具,函数调用能力。其中函数调用功能支持用户自定义函数,为进阶开发者提供了便利。当模型识别到解决用户输入的请求需要搜索引擎时,它会自动激活内置的联网搜索功能,以提供实时且全面的搜索结果。搜索完成后,内置的网页浏览工具能够打开并细致查看网页内容,从而进行更深入的分析。此外,借助卓越的自我规划能力和内置的代码沙盒、绘图设计等工具,API能够仅通过一次互动就高效地处理复杂的任务。

下面请跟随我们的脚步,我们将一步一步组合这些工具,测试GLM-4-AllTools的真正实力:

Case1: 实时查询欧洲杯淘汰赛对阵

Tools: Web Search

代码:

  1. from zhipuai import ZhipuAI
  2. client = ZhipuAI(api_key="Zhipu API Key") # 请填写您自己的APIKey
  3. response = client.chat.completions.create(
  4.     model="glm-4-alltools",  # 填写需要调用的模型名称
  5.     stream=True,
  6.     messages=[
  7.         {
  8.             "role""user",
  9.             "content":[
  10.                 {
  11.                     "type":"text",
  12.                     "text":"帮我查询本届欧洲杯淘汰赛对阵情况。"
  13.                 }
  14.             ]
  15.         }
  16.     ],
  17.     tools=[
  18.         {
  19.             "type""web_browser" #联网搜索
  20.         },
  21.     ]
  22. )
  23. for trunk in response:
  24.     if trunk.choices[0].delta.content is not None:
  25.         print(trunk.choices[0].delta.content, end="")

回复:

  1. 2024年欧洲杯淘汰赛的对阵情况如下:
  2. 630日:
  3.   - 瑞士 vs 意大利(00:00
  4.   - 德国 vs 丹麦(03:00
  5. 71日:
  6.   - 英格兰 vs 斯洛伐克(00:00
  7.   - 西班牙 vs 格鲁吉亚(03:00
  8. 72日:
  9.   - 法国 vs 比利时(00:00
  10.   - 葡萄牙 vs 斯洛文尼亚(03:00
  11. 73日:
  12.   - 荷兰 vs 罗马尼亚(00:00
  13.   - 奥地利 vs 土耳其(03:00
  14. 请注意,以上时间均为北京时间。

Case2: 查询慕尼黑天气,自动绘画天气曲线

Tools: Web Search, Code Interpreter, Sandbox

  1. from zhipuai import ZhipuAI
  2. client = ZhipuAI(api_key="") # 请填写您自己的APIKey
  3. response = client.chat.completions.create(
  4.     model="glm-4-alltools",  # 填写需要调用的模型名称
  5.     stream=True,
  6.     messages=[
  7.         {
  8.             "role""user",
  9.             "content":[
  10.                 {
  11.                     "type":"text",
  12.                     "text":"帮我查询慕尼黑07/05至07/15的日平均气温。并将所有平均气温数值组成数列,绘出折线图显示趋势。"
  13.                 }
  14.             ]
  15.         }
  16.     ],
  17.     tools=[
  18.         {
  19.             "type""web_browser"
  20.         },
  21.         {
  22.             "type""code_interpreter", #智能编程助手
  23.         },
  24.     ]
  25. )
  26. for trunk in response:
  27.     print(trunk)
  28.     if trunk.choices[0].delta.content is not None:
  29.         print(trunk.choices[0].delta.content, end="")

回复:这次我们进入到GLM-4-AllTools API的工作流中,看看模型为了解决Case2执行了哪些步骤:

  1. #search
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. 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)
  7. 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)
  8. 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)
  9. 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)
  10. 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)
  11. 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)
  12. 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)
  13. 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)
  14. ...
  15. 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)
  16. 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
    推荐阅读
    相关标签