惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hacker News - Newest:
Hacker News - Newest: "LLM"
The Last Watchdog
The Last Watchdog
L
LINUX DO - 最新话题
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Troy Hunt's Blog
Cloudbric
Cloudbric
N
News | PayPal Newsroom
Security Archives - TechRepublic
Security Archives - TechRepublic
TaoSecurity Blog
TaoSecurity Blog
H
Hacker News: Front Page
Help Net Security
Help Net Security
S
Secure Thoughts
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
PCI Perspectives
PCI Perspectives
AI
AI
Hacker News: Ask HN
Hacker News: Ask HN
NISL@THU
NISL@THU
Last Week in AI
Last Week in AI
Forbes - Security
Forbes - Security
The GitHub Blog
The GitHub Blog
D
DataBreaches.Net
Scott Helme
Scott Helme
Jina AI
Jina AI
T
Threatpost
W
WeLiveSecurity
P
Palo Alto Networks Blog
F
Fortinet All Blogs
腾讯CDC
人人都是产品经理
人人都是产品经理
云风的 BLOG
云风的 BLOG
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
P
Privacy International News Feed
P
Proofpoint News Feed
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
A
About on SuperTechFans
V
Vulnerabilities – Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cyber Attacks, Cyber Crime and Cyber Security
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Darknet – Hacking Tools, Hacker News & Cyber Security
IT之家
IT之家
美团技术团队
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
T
Threat Research - Cisco Blogs
博客园 - 司徒正美

博客园 - 仙守

用audit审计去记录谁用了docker docker容器大小使用限制 docker容器的磁盘使用进行限额 sentry私有化部署: 在8c16g上降低资源使用 私有化部署sentry: 获取dsn 私有化部署sentry:卷备份及恢复 docker 保存所有镜像 私有化部署sentry:镜像构建 docker拉取代理脚本 vscode密钥从windows连接远程linux 基于docker构建es集群 在es中进行update+upsert milvus遍历查询全部数据 一个中转代码,底层调用openai,上层模拟openai 一个小工具识别哪个docker占用gpu NLP之预训练语言模型BERT NLP之预训练语言模型GPT NLP之引言 [推荐系统]粗排之FSCD
简单剖析qwen-agent回答是怎么获取tool的
仙守 · 2024-07-15 · via 博客园 - 仙守

openai是一家伟大的公司(虽然是closedai),当他们提出agent的概念后,就很神奇。之前通过langchain的langgraph进行写demo,就很好奇,他是怎么基于我的话自动去识别这句话是大模型的闲聊,那句话是大模型去调用tool

1.现象

1.和大模型打招呼,大模型知道回答,这没啥稀奇

2.可是当问它某个地方的天气怎样后,它内部知道去调用工具就很神奇

2.简单分析

通过langchain的简单分析,是当交流天气时候,

大模型输出工具的名字name,以及对应的工具入参args。
然后本地的tool函数进行对应的函数调用,
然后结果再塞给大模型进行润色。

AIMessage(content=[{'id': 'toolu_01Y5EK4bw2LqsQXeaUv8iueF', 'input': {'query': 'weather in san francisco'}, 'name': 'tavily_search_results_json', 'type': 'tool_use'}], response_metadata={'id': 'msg_0132wQUcEduJ8UKVVVqwJzM4', 'model': 'claude-3-sonnet-20240229', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'input_tokens': 269, 'output_tokens': 61}}, id='run-26d5e5e8-d4fd-46d2-a197-87b95b10e823-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'weather in san francisco'}, 'id': 'toolu_01Y5EK4bw2LqsQXeaUv8iueF'}], usage_metadata={'input_tokens': 269, 'output_tokens': 61, 'total_tokens': 330}),

也就是大模型当遇到需要调用工具的时候,就输出对应的工具名称和入参。
但是问题是,这是怎么回事?

3.基于qwen-agent进行剖析

要想支持tool_call,首先是有个训练集的,输入是一些问题,输出是一个json,如这里 https://hf-mirror.com/datasets/Salesforce/xlam-function-calling-60k

{
  "query": "Find the sum of all the multiples of 3 and 5 between 1 and 1000. Also find the product of the first five prime numbers.",
  "tools": [
    {
      "name": "math_toolkit.sum_of_multiples",
      "description": "Find the sum of all multiples of specified numbers within a specified range.",
      "parameters": {
        "lower_limit": {
          "type": "int",
          "description": "The start of the range (inclusive).",
          "required": true
        },
        "upper_limit": {
          "type": "int",
          "description": "The end of the range (inclusive).",
          "required": true
        },
        "multiples": {
          "type": "list",
          "description": "The numbers to find multiples of.",
          "required": true
        }
      }
    },
    {
      "name": "math_toolkit.product_of_primes",
      "description": "Find the product of the first n prime numbers.",
      "parameters": {
        "count": {
          "type": "int",
          "description": "The number of prime numbers to multiply together.",
          "required": true
        }
      }
    }
  ],
  "answers": [
    {
      "name": "math_toolkit.sum_of_multiples",
      "arguments": {
        "lower_limit": 1,
        "upper_limit": 1000,
        "multiples": [3, 5]
      }
    },
    {
      "name": "math_toolkit.product_of_primes",
      "arguments": {
        "count": 5
      }
    }
  ]
}

所以大模型就会生成一个完整的json,那qwen-agent是怎么回事呢如下面的截图,
miniconda3/lib/python3.10/site-packages/qwen_agent/llm/function_calling.py
下面的图片意思是:qwen是需要qwen-agent在调用qwen的时候,输入一些补充的prompt

下面图片的意思是,补充的prompt是补充在system_prompt的最后面

下面图片的意思是,qwen大模型的输出会有前面的输出文字,中间的toolcall部分,和后面的一些文字,为了保险,就需要处理下,把前后的文字弄掉,只输出中间的tool call部分

4.openai-client的包

在openai-client中找了下没qwen-agent这样的prompt的处理和输出的llm的处理,这个人有2种猜测
1)这些操作被隐藏在服务端了,但是觉得概率不大
2)还是大模型训练的好,通过function call的那些数据集进行大模型的训练,使得大模型能直接输出一个完整的json,openai-client就直接进行解析就行了。