FastGPT icon indicating copy to clipboard operation
FastGPT copied to clipboard

现在fastgpt可以用api的方式和某个知识库对话吗?

Open JV-X opened this issue 3 weeks ago • 2 comments

例行检查

  • [x] 我已确认目前没有类似 issue
  • [x] 我已完整查看过项目 README,以及项目文档
  • [x] 我使用了自己的 key,并确认我的 key 是可正常使用的
  • [x] 我理解并愿意跟进此 issue,协助测试和提供反馈
  • [x] 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭

你的版本

  • [ ] 公有云版本
  • [x] 私有部署版本, 具体版本号: 4.8.20

问题描述, 日志截图,配置文件等 我在本地安装部署了fastgpt 4.8.20(docker方式部署),并在web界面上成功和指定的知识库对话,现在我想要尝试用api的方式和指定的知识库对话,我在文档里找到了和fastgpt对话的方式( https://doc.tryfastgpt.ai/docs/development/openapi/chat/ ),但这里的对话是没有指定知识库的,请问,如何在对话的时候指定知识库呢?

复现步骤 执行以下代码:


def chat_with_fastgpt():

    # 设置请求的URL
    url = "http://localhost:3000/api/v1/chat/completions"

    # 设置请求头
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }

    # 设置请求体
    data = {
        "chatId": "my_chatId",
        "stream": False,
        "detail": False,
        "responseChatItemId": "my_responseChatItemId",
        "variables": {
            "uid": "asdfadsfasfd2323",
            "name": "张三"
        },
        "messages": [
            {
                "role": "user",
                "content": "病人表 Cehr_Patient 里一共有多少个字段,详细列出每个字段的字段名和中文名"
            }
        ]
    }

    # 发送POST请求
    response = requests.post(url, headers=headers, json=data)

    # 检查响应状态码并输出响应内容
    if response.status_code == 200:
        # 格式化输出响应内容
        formatted_json = json.dumps(response.json(), indent=4, ensure_ascii=False)
        print(formatted_json)
    else:
        print(f"请求失败,状态码:{response.status_code}")
        print(response.text)


if __name__ == '__main__':
    chat_with_fastgpt()

预期结果 和指定的知识库对话

相关截图

Image

JV-X avatar Feb 05 '25 10:02 JV-X