langchain-chatchat api server 怎么用
时间: 2025-05-22 16:16:03 浏览: 15
### Langchain-Chatchat API Server 的使用教程
#### 初始化项目
为了启动并运行 `Langchain-Chatchat`,首先需要克隆其仓库到本地环境。通过以下命令完成此操作:
```bash
git clone https://github.com/chatchat-space/Langchain-Chatchat.git [^1]
```
接着进入项目的子目录,并初始化配置文件以及创建必要的数据存储路径:
```bash
cd libs/chatchat-server
python chatchat/cli.py init [^2]
```
#### 下载预训练模型
在实际应用之前,还需要下载所需的大型语言模型及其嵌入向量模型。具体来说,可以从 Hugging Face 平台获取这些资源:
- 嵌入向量模型:访问链接 [BGE-Large-ZH](https://huggingface.co/BAAI/bge-large-zh),下载对应的权重文件[^3]。
- 对话生成模型:前往页面 [ChatGLM3-6B](https://huggingface.co/THUDM/chatglm3-6b) 获取对话生成器的相关参数和结构定义。
#### 启动服务端口
一旦上述准备工作全部就绪,则可以按照如下方式开启 API 服务器来提供对外接口调用支持功能。通常情况下,默认监听地址为 localhost 上的某个指定端口号(比如8000)。以下是启动脚本的一个例子:
```bash
uvicorn main:app --host 0.0.0.0 --port 8000
```
这里假设主程序入口位于名为 `main.py` 文件中的 FastAPI 实例变量 `app` 中。
#### 请求示例代码
下面给出了一段 Python 脚本来演示如何利用 requests 库发送 POST 请求至该 API endpoint 来实现问答交互过程:
```python
import json
import requests
url = 'http://localhost:8000/api/v1/qwen'
headers = {'Content-Type': 'application/json'}
data = {
"question": "你好",
"history": []
}
response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.json())
```
阅读全文
相关推荐

















