AnythingLLM 开发者接口 API 说明文档

AnythingLLM 是一个功能强大的知识库管理工具,提供了丰富的 API 接口,方便开发者进行集成和扩展。本文档将详细介绍 AnythingLLM 的 API 接口及其使用方法。


一、API 基础信息

  • API 地址: http://localhost:5000/api(默认地址)

  • 认证方式: API Key

  • 请求格式: JSON

  • 响应格式: JSON


二、API 接口列表

1. 获取知识库列表
  • URL: /api/knowledge_bases

  • 方法: GET

  • 描述: 获取所有知识库的列表。

  • 请求示例:

    curl -X GET "http://localhost:5000/api/knowledge_bases" -H "Authorization: Bearer YOUR_API_KEY"
  • 响应示例:

    {
      "knowledge_bases": [
        {
          "id": 1,
          "name": "Knowledge Base 1",
          "description": "This is the first knowledge base",
          "created_at": "2023-10-01T12:00:00Z"
        },
        {
          "id": 2,
          "name": "Knowledge Base 2",
          "description": "This is the second knowledge base",
          "created_at": "2023-10-02T12:00:00Z"
        }
      ]
    }
2. 创建知识库
  • URL: /api/knowledge_bases

  • 方法: POST

  • 描述: 创建一个新的知识库。

  • 请求参数:

    参数名类型必填描述
    namestring知识库名称
    descriptionstring知识库描述
  • 请求示例:

    curl -X POST "http://localhost:5000/api/knowledge_bases" -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d '{
      "name": "New Knowledge Base",
      "description": "This is a new knowledge base"
    }'
  • 响应示例:

    {
      "id": 3,
      "name": "New Knowledge Base",
      "description": "This is a new knowledge base",
      "created_at": "2023-10-03T12:00:00Z"
    }
3. 获取知识库详情
  • URL: /api/knowledge_bases/{knowledge_base_id}

  • 方法: GET

  • 描述: 获取指定知识库的详细信息。

  • 请求示例:

    curl -X GET "http://localhost:5000/api/knowledge_bases/1" -H "Authorization: Bearer YOUR_API_KEY"
  • 响应示例:

    {
      "id": 1,
      "name": "Knowledge Base 1",
      "description": "This is the first knowledge base",
      "created_at": "2023-10-01T12:00:00Z",
      "documents": [
        {
          "id": 1,
          "title": "Document 1",
          "content": "This is the content of document 1",
          "created_at": "2023-10-01T12:00:00Z"
        },
        {
          "id": 2,
          "title": "Document 2",
          "content": "This is the content of document 2",
          "created_at": "2023-10-02T12:00:00Z"
        }
      ]
    }
4. 添加文档到知识库
  • URL: /api/knowledge_bases/{knowledge_base_id}/documents

  • 方法: POST

  • 描述: 向指定知识库添加文档。

  • 请求参数:

    参数名类型必填描述
    titlestring文档标题
    contentstring文档内容
  • 请求示例:

    curl -X POST "http://localhost:5000/api/knowledge_bases/1/documents" -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d '{
      "title": "New Document",
      "content": "This is the content of the new document"
    }'
  • 响应示例:

    {
      "id": 3,
      "title": "New Document",
      "content": "This is the content of the new document",
      "created_at": "2023-10-03T12:00:00Z"
    }
5. 查询知识库
  • URL: /api/knowledge_bases/{knowledge_base_id}/query

  • 方法: POST

  • 描述: 在指定知识库中查询相关内容。

  • 请求参数:

    参数名类型必填描述
    querystring查询语句
  • 请求示例:

    curl -X POST "http://localhost:5000/api/knowledge_bases/1/query" -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d '{
      "query": "How to use AnythingLLM?"
    }'
  • 响应示例:

    {
      "results": [
        {
          "id": 1,
          "title": "Document 1",
          "content": "This is the content of document 1",
          "score": 0.95
        },
        {
          "id": 2,
          "title": "Document 2",
          "content": "This is the content of document 2",
          "score": 0.85
        }
      ]
    }

三、错误处理

API 请求可能会返回以下错误码:

错误码描述
400请求参数错误
401未授权
404资源未找到
500服务器内部错误

错误响应示例:

{
  "error": "Unauthorized",
  "message": "API key is missing or invalid"
}

四、总结

AnythingLLM 提供了丰富的 API 接口,方便开发者进行知识库的管理和查询。通过本文档,您可以快速上手并使用这些接口,实现知识库的集成和扩展。如果您有任何问题或建议,欢迎联系我们的支持团队。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值