Skip to content

任意 API 请求

此工具会将 OpenAPI 规范转换为模型工具。使得模型可以调用工具请求外部的 API。

配置

  • 参考 介绍 中的配置方法,启用 plugin-common 插件。
  • 按照下图配置在 plugin-common 插件中启用 action 功能。

alt text

  • 完成后,还需要参考下图在 plugin-common 插件中配置 action 功能。

alt text

由上图,我们能知道在 action 功能中,我们可以添加任意的 API 请求。

分为以下几个部分:

  • name: 工具的名称。
  • description: 工具的描述。
  • headers: 请求头。用于某些需要认证的 API。
  • selector: 模型工具的触发词。当你的聊天内容含有这些词语时,这个指令对应的模型工具将会被激活。(可选项)
  • openAPISpec: OpenAPI 格式文件。用于指定 API 的请求方式、参数等信息。

配置完以下几个部分后,我们就可以让模型调用任意的 API 了。

测试

可以参考下面的 OpenAPI 格式文件,添加一个新闻查询工具。

news.yml
yaml
openapi: 3.0.0
info:
  title: Yujn API
  description: This API provides news data.
  version: 1.0.0
servers:
  - url: https://api.yujn.cn/
paths:
  /api/new.php:
    get:
      summary: Get news data
      description: Returns a list of news articles.
      parameters:
        - in: query
          name: count
          schema:
            type: integer
          description: Number of results to return
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                    description: Response code
                  count:
                    type: integer
                    description: Number of returned results
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        time:
                          type: string
                          description: News publication time
                        title:
                          type: string
                          description: News title
                        brief:
                          type: string
                          description: News brief
                        image:
                          type: string
                          description: Image URL
                        url:
                          type: string
                          description: News URL

询问模型调用工具,当模型回复相关信息时,说明命令执行工具配置成功。

聊天记录
U
User
chatluna chat text tell me the last news
B
Bot
{
    tool: 'gzdlte',
    arg: '{
      "query": {
        "count": "5"
      }
    }',
    log: 'Invoking "gzdlte" with {"query":{"count":"5"}}'
}
B
Bot
1. 刚果(金)反政府武装单方面宣布从2月4日起停火
时间: 2025-02-04 04:54:14
简介: The M23 movement in the Democratic Republic of Congo has unilaterally announced a ceasefire starting February 4 for humanitarian reasons.
Image
阅读更多

  1. 美国民调:大多数美国人反对实施新的加征关税措施
    时间: 2025-02-04 04:53:49
    简介: A recent poll indicates that most Americans oppose new tariffs on Mexico and Canada.
    Image
    阅读更多

  2. 首次成功尝试!"中山大学极地"号在渤海冰区完成星-机-船协同观测
    时间: 2025-02-04 04:51:21
    简介: The Zhongshan University Polar vessel successfully completed a collaborative observation in the Bohai Sea ice region, marking a first in the Northern Hemisphere's lowest latitude sea ice area.
    Image
    阅读更多

  3. 目前仍处于流感季节性流行期 肺炎是流感最常见的并发症
    时间: 2025-02-04 04:43:18
    简介: During the peak of flu season, pneumonia remains the most common complication; timely treatment is advised within 48 hours of diagnosis.
    Image
    阅读更多

  4. 新春走基层|立春日,返岗专列奔赴新程
    时间: 2025-02-04 04:30:47
    简介: On the day of the Spring Festival, workers in Guangdong are returning to their jobs, highlighting family and education convenience.
    Image
    阅读更多

页面历史

在 CC-BY-SA-4.0 许可下发布