Files
2025-02-28 20:30:47 +08:00

6.7 KiB
Raw Permalink Blame History

集成的工具

当前au的 sample工程当中集成了以下工具

1. 搜索工具

1.1 谷歌搜索

工具地址
详细配置信息:

name: 'google_search_tool'
description: |
  该工具可以用来进行谷歌搜索,工具的输入是你想搜索的内容。
  工具输入示例:
    示例1: 你想要搜索上海的天气时,工具的输入应该是:上海今天的天气
    示例2: 你想要搜索日本的天气时,工具的输入应该是:日本的天气
tool_type: 'api'
input_keys: ['input']
metadata:
  type: 'TOOL'
  module: 'sample_standard_app.intelligence.agentic.tool.samples.google_search_tool'
  class: 'GoogleSearchTool'

为了使用该api,你必须申请(https://serper.dev)SERPER_API_KEY并配置在环境变量当中。
配置方法:

  1. 通过python代码配置 必须配置SERPER_API_KEY
import os
os.environ['SERPER_API_KEY'] = 'xxxx'
  1. 通过配置文件配置 在项目的config目录下的custom_key.toml当中添加配置
SERPER_API_KEY="xxxx"

1.2 Bing(必应)搜索

当前集成了Bing官方的搜索 工具地址
工具配置:

name: 'bing_search_tool'
description: 'demo bing search tool'
tool_type: 'api'
input_keys: ['input']
metadata:
  type: 'TOOL'
  module: 'sample_standard_app.intelligence.agentic.tool.samples.bing_search_tool'
  class: 'BingSearchTool'

为了使用该api,你必须申请BING_SUBSCRIPTION_KEY,并配置在环境变量当中。
配置方法:

  1. 通过python代码配置 必须配置BING_SUBSCRIPTION_KEY
import os
os.environ['BING_SUBSCRIPTION_KEY'] = 'xxxx'
  1. 通过配置文件配置 在项目的config目录下的custom_key.toml当中添加配置
BING_SUBSCRIPTION_KEY="xxxx"

1.3 Search API

支持多种搜索工具,例如:

name: 'search_api_baidu_tool'
description: '百度(必应)搜索工具输入为一个要搜索内容的字符串例如input=黄金价格是多少'
tool_type: 'api'
input_keys: ['input']
engine: 'baidu'
search_type: 'common'
search_params:
  num: 10
metadata:
  type: 'TOOL'
  module: 'sample_standard_app.intelligence.agentic.tool.samples.search_api_tool'
  class: 'SearchAPITool'

参数说明:
search_type: 代表你期望返回的搜索结果的格式json代表你期望为json格式common代表你期望为string字符串格式。 search_params: 代表你需要额外的传递给搜索引擎的参数比如在百度搜索中num代表了返回的搜索结果条数详细参数需要参考https://www.searchapi.io/ 。 engine: 你期望使用的搜索引擎baidu、google、bing、amazon、youtube... 为了使用该api,你必须从官网申请SEARCH_API_KEY,并配置在环境变量当中。
配置方法:

  1. 通过python代码配置 必须配置SEARCH_API_KEY
import os
os.environ['SEARCHAPI_API_KEY'] = 'xxxxxx'
  1. 通过配置文件配置 在项目的config目录下的custom_key.toml当中添加配置
SEARCHAPI_API_KEY="xxxxxx"

2. 代码工具

2.1 PythonRepl

工具地址
该工具可以执行一段Python代码,工具的配置信息:

name: 'python_runner'
description: '使用该工具可以执行python代码可以在pycharm中直接运行的代码.工具的输入必须时一段有效的python代码. 如何你想要查看工具的执行结果, 必须在python代码中使用print(...)打印你想查看的内容。
    工具输入示例:
      你想要计算1+3等于多少时工具的输入应该是
        ```py 
        print(1+3)
        ```
      你想要获取百度页面的信息时,工具的输入应该是: 
        ```py 
        import requests
        resp=requests.get("https://www.baidu.com")
        print(resp.content)
        ```'
tool_type: 'api'
input_keys: ['input']
metadata:
  type: 'TOOL'
  module: 'sample_standard_app.intelligence.agentic.tool.samples.python_repl'
  class: 'PythonREPLTool'

该工具可以直接使用无需任何key但是为了系统安全请不要在生产环境使用该工具

3.HTTP 工具

工具地址 该工具可以发送一个GET请求工具的配置信息 :

name: 'requests_get'
description: 'A portal to the internet. Use this when you need to get specific
    content from a website. Input should be a  url (i.e. https://www.google.com).
    The output will be the text response of the GET request.
        ```'
headers:
  content-type: 'application/json'
method: 'GET'
json_parser: false
response_content_type: json
tool_type: 'api'
input_keys: ['input']
metadata:
  type: 'TOOL'
  module: 'sample_standard_app.intelligence.agentic.tool.samples.request_tool'
  class: 'RequestTool'

发送POST请求时可以参考的配置

name: 'requests_post'
# description copy from langchain RequestPOSTTool
description: 'Use this when you want to POST to a website.
    Input should be a json string with two keys: "url" and "data".
    The value of "url" should be a string, and the value of "data" should be a dictionary of 
    key-value pairs you want to POST to the url.
    Be careful to always use double quotes for strings in the json string
    The output will be the text response of the POST request.
        ```'
headers:
  content-type: 'application/json'
method: 'POST'
json_parser: true
response_content_type: json
tool_type: 'api'
input_keys: ['input']
metadata:
  type: 'TOOL'
  module: 'sample_standard_app.intelligence.agentic.tool.samples.request_tool'
  class: 'RequestTool'

参数说明: method 请求的方式GET/POST/PUT等 headers 发送请求需要使用的 http的header, json_parse 输入参数是否需要是要HTTP解析POST请求时需要设置为True,GET请求需要设置为False response_content_type http请求结果的解析方式设置为json时会返回json结果设置为text时会返回text结果 该工具可以直接使用无需任何keys