28 lines
9.9 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>OpenAPI 接口文档 on FastGPT</title><link>https://doc.tryfastgpt.ai/docs/development/openapi/</link><description>Recent content in OpenAPI 接口文档 on FastGPT</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><atom:link href="https://doc.tryfastgpt.ai/docs/development/openapi/index.xml" rel="self" type="application/rss+xml"/><item><title>OpenAPI 介绍</title><link>https://doc.tryfastgpt.ai/docs/development/openapi/intro/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://doc.tryfastgpt.ai/docs/development/openapi/intro/</guid><description>使用说明 linkFasGPT OpenAPI 接口允许你使用 Api Key 进行鉴权,从而操作 FastGPT 上的相关服务和资源,例如:调用应用对话接口、上传知识库数据、搜索测试等等。出于兼容性和安全考虑,并不是所有的接口都允许通过 Api Key 访问。
如何查看 BaseURL link注意BaseURL 不是接口地址,而是所有接口的根地址,直接请求 BaseURL 是没有用的。
如何获取 Api Key linkFastGPT 的 API Key 有 2 类,一类是全局通用的 key (无法直接调用应用对话);一类是携带了 AppId 也就是有应用标记的 key (可直接调用应用对话)。
我们建议,仅操作应用或者对话的相关接口使用 应用特定key其他接口使用 通用key。
通用key 应用特定 key 基本配置 linkOpenAPI 中,所有的接口都通过 Header.Authorization 进行鉴权。
baseUrl: &amp;#34;https://api.fastgpt.in/api&amp;#34; headers: { Authorization: &amp;#34;Bearer {{apikey}}&amp;#34; } 发起应用对话示例
curl --location --request POST &amp;#39;https://api.fastgpt.in/api/v1/chat/completions&amp;#39; \ --header &amp;#39;Authorization: Bearer fastgpt-xxxxxx&amp;#39; \ --header &amp;#39;Content-Type: application/json&amp;#39; \ --data-raw &amp;#39;{ &amp;#34;chatId&amp;#34;: &amp;#34;111&amp;#34;, &amp;#34;stream&amp;#34;: false, &amp;#34;detail&amp;#34;: false, &amp;#34;messages&amp;#34;: [ { &amp;#34;content&amp;#34;: &amp;#34;导演是谁&amp;#34;, &amp;#34;role&amp;#34;: &amp;#34;user&amp;#34; } ] }&amp;#39; 自定义用户 ID linkv4.</description></item><item><title>对话接口</title><link>https://doc.tryfastgpt.ai/docs/development/openapi/chat/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://doc.tryfastgpt.ai/docs/development/openapi/chat/</guid><description>如何获取 AppId link可在应用详情的路径里获取 AppId。
发起对话 link 🤖
该接口的 API Key 需使用应用特定的 key否则会报错。 有些包调用时BaseUrl需要添加v1路径有些不需要如果出现404情况可补充v1重试。
请求简易应用和工作流 linkv1对话接口兼容GPT的接口如果你的项目使用的是标准的GPT官方接口可以直接通过修改BaseUrl和 Authorization来访问 FastGpt 应用,不过需要注意下面几个规则:
🤖
传入的modeltemperature等参数字段均无效这些字段由编排决定不会根据 API 参数改变。
不会返回实际消耗Token值如果需要可以设置detail=true并手动计算 responseData 里的tokens值。
请求 link 基础请求示例 图片/文件请求示例 参数说明 curl --location --request POST &amp;#39;http://localhost:3000/api/v1/chat/completions&amp;#39; \ --header &amp;#39;Authorization: Bearer fastgpt-xxxxxx&amp;#39; \ --header &amp;#39;Content-Type: application/json&amp;#39; \ --data-raw &amp;#39;{ &amp;#34;chatId&amp;#34;: &amp;#34;my_chatId&amp;#34;, &amp;#34;stream&amp;#34;: false, &amp;#34;detail&amp;#34;: false, &amp;#34;responseChatItemId&amp;#34;: &amp;#34;my_responseChatItemId&amp;#34;, &amp;#34;variables&amp;#34;: { &amp;#34;uid&amp;#34;: &amp;#34;asdfadsfasfd2323&amp;#34;, &amp;#34;name&amp;#34;: &amp;#34;张三&amp;#34; }, &amp;#34;messages&amp;#34;: [ { &amp;#34;role&amp;#34;: &amp;#34;user&amp;#34;, &amp;#34;content&amp;#34;: &amp;#34;导演是谁&amp;#34; } ] }&amp;#39; 仅messages有部分区别其他参数一致。 目前不支持上传文件,需上传到自己的对象存储中,获取对应的文件链接。 curl --location --request POST &amp;#39;http://localhost:3000/api/v1/chat/completions&amp;#39; \ --header &amp;#39;Authorization: Bearer fastgpt-xxxxxx&amp;#39; \ --header &amp;#39;Content-Type: application/json&amp;#39; \ --data-raw &amp;#39;{ &amp;#34;chatId&amp;#34;: &amp;#34;abcd&amp;#34;, &amp;#34;stream&amp;#34;: false, &amp;#34;messages&amp;#34;: [ { &amp;#34;role&amp;#34;: &amp;#34;user&amp;#34;, &amp;#34;content&amp;#34;: [ { &amp;#34;type&amp;#34;: &amp;#34;text&amp;#34;, &amp;#34;text&amp;#34;: &amp;#34;导演是谁&amp;#34; }, { &amp;#34;type&amp;#34;: &amp;#34;image_url&amp;#34;, &amp;#34;image_url&amp;#34;: { &amp;#34;url&amp;#34;: &amp;#34;图片链接&amp;#34; } }, { &amp;#34;type&amp;#34;: &amp;#34;file_url&amp;#34;, &amp;#34;name&amp;#34;: &amp;#34;文件名&amp;#34;, &amp;#34;url&amp;#34;: &amp;#34;文档链接,支持 txt md html word pdf ppt csv excel&amp;#34; } ] } ] }&amp;#39; info headers.</description></item><item><title>知识库接口</title><link>https://doc.tryfastgpt.ai/docs/development/openapi/dataset/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://doc.tryfastgpt.ai/docs/development/openapi/dataset/</guid><description>如何获取知识库IDdatasetId 如何获取文件集合IDcollection_id 创建训练订单 link 请求示例 响应示例 新例子
curl --location --request POST &amp;#39;http://localhost:3000/api/support/wallet/usage/createTrainingUsage&amp;#39; \ --header &amp;#39;Authorization: Bearer {{apikey}}&amp;#39; \ --header &amp;#39;Content-Type: application/json&amp;#39; \ --data-raw &amp;#39;{ &amp;#34;datasetId&amp;#34;: &amp;#34;知识库 ID&amp;#34;, &amp;#34;name&amp;#34;: &amp;#34;可选,自定义订单名称,例如:文档训练-fastgpt.docx&amp;#34; }&amp;#39; data 为 billId可用于添加知识库数据时进行账单聚合。
{ &amp;#34;code&amp;#34;: 200, &amp;#34;statusText&amp;#34;: &amp;#34;&amp;#34;, &amp;#34;message&amp;#34;: &amp;#34;&amp;#34;, &amp;#34;data&amp;#34;: &amp;#34;65112ab717c32018f4156361&amp;#34; } 知识库 link创建一个知识库 link 请求示例 参数说明 响应示例 curl --location --request POST &amp;#39;http://localhost:3000/api/core/dataset/create&amp;#39; \ --header &amp;#39;Authorization: Bearer {{authorization}}&amp;#39; \ --header &amp;#39;Content-Type: application/json&amp;#39; \ --data-raw &amp;#39;{ &amp;#34;parentId&amp;#34;: null, &amp;#34;type&amp;#34;: &amp;#34;dataset&amp;#34;, &amp;#34;name&amp;#34;:&amp;#34;测试&amp;#34;, &amp;#34;intro&amp;#34;:&amp;#34;介绍&amp;#34;, &amp;#34;avatar&amp;#34;: &amp;#34;&amp;#34;, &amp;#34;vectorModel&amp;#34;: &amp;#34;text-embedding-ada-002&amp;#34;, &amp;#34;agentModel&amp;#34;: &amp;#34;gpt-3.</description></item><item><title>分享链接身份鉴权</title><link>https://doc.tryfastgpt.ai/docs/development/openapi/share/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://doc.tryfastgpt.ai/docs/development/openapi/share/</guid><description>介绍 link在 FastGPT V4.6.4 中,我们修改了分享链接的数据读取方式,为每个用户生成一个 localId用于标识用户从云端拉取对话记录。但是这种方式仅能保障用户在同一设备同一浏览器中使用如果切换设备或者清空浏览器缓存则会丢失这些记录。这种方式存在一定的风险因此我们仅允许用户拉取近30天的20条记录。
分享链接身份鉴权设计的目的在于,将 FastGPT 的对话框快速、安全的接入到你现有的系统中,仅需 2 个接口即可实现。该功能目前只在商业版中提供。
使用说明 link免登录链接配置中你可以选择填写身份验证栏。这是一个POST请求的根地址。在填写该地址后分享链接的初始化、开始对话以及对话结束都会向该地址的特定接口发送一条请求。下面以host来表示凭身份验证根地址。服务器接口仅需返回是否校验成功即可不需要返回其他数据格式如下
接口统一响应格式 link { &amp;#34;success&amp;#34;: true, &amp;#34;message&amp;#34;: &amp;#34;错误提示&amp;#34;, &amp;#34;msg&amp;#34;: &amp;#34;同message, 错误提示&amp;#34;, &amp;#34;data&amp;#34;: { &amp;#34;uid&amp;#34;: &amp;#34;用户唯一凭证&amp;#34; } } FastGPT 将会判断success是否为true决定是允许用户继续操作。message与msg是等同的你可以选择返回其中一个当success不为true时将会提示这个错误。
uid是用户的唯一凭证将会用于拉取对话记录以及保存对话记录。可参考下方实践案例。
触发流程 link 配置教程 link1. 配置身份校验地址 link 配置校验地址后,在每次分享链接使用时,都会向对应的地址发起校验和上报请求。
🤖
这里仅需配置根地址,无需具体到完整请求路径。
2. 分享链接中增加额外 query link在分享链接的地址中增加一个额外的参数: authToken。例如
原始的链接https://share.tryfastgpt.ai/chat/share?shareId=648aaf5ae121349a16d62192
完整链接: https://share.tryfastgpt.ai/chat/share?shareId=648aaf5ae121349a16d62192&amp;amp;authToken=userid12345
这个authToken通常是你系统生成的用户唯一凭证Token之类的。FastGPT 会在鉴权接口的body中携带 token={{authToken}} 的参数。
3. 编写聊天初始化校验接口 link 请求示例 鉴权成功 鉴权失败 curl --location --request POST &amp;#39;{{host}}/shareAuth/init&amp;#39; \ --header &amp;#39;Content-Type: application/json&amp;#39; \ --data-raw &amp;#39;{ &amp;#34;token&amp;#34;: &amp;#34;{{authToken}}&amp;#34; }&amp;#39; { &amp;#34;success&amp;#34;: true, &amp;#34;data&amp;#34;: { &amp;#34;uid&amp;#34;: &amp;#34;用户唯一凭证&amp;#34; } } 系统会拉取该分享链接下uid 为 username123 的对话记录。</description></item></channel></rss>