任意 API 请求
此工具会将 OpenAPI 规范转换为模型工具。使得模型可以调用工具请求外部的 API。
配置
- 参考 介绍 中的配置方法,启用
plugin-common
插件。 - 按照下图配置在
plugin-common
插件中启用action
功能。
- 完成后,还需要参考下图在
plugin-common
插件中配置action
功能。
由上图,我们能知道在 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
询问模型调用工具,当模型回复相关信息时,说明命令执行工具配置成功。
聊天记录