Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
6 of 7 tasks
JV-X opened this issue Feb 5, 2025 · 2 comments
Open
6 of 7 tasks

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

JV-X opened this issue Feb 5, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@JV-X
Copy link

JV-X commented Feb 5, 2025

例行检查

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

你的版本

  • 公有云版本
  • 私有部署版本, 具体版本号: 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 JV-X added the bug Something isn't working label Feb 5, 2025
@lzs2000131
Copy link

api_key用的是创建好的应用的key吗

@JV-X
Copy link
Author

JV-X commented Feb 10, 2025

api_key用的是创建好的应用的key吗

是的,是app的key,不是那个通用的key,用通用的key会报错

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants