54 lines
1.0 KiB
Markdown
54 lines
1.0 KiB
Markdown
# Embedding API 后端服务
|
|
|
|
独立 API 服务,为分析提供 embedding 支持
|
|
|
|
## 配置虚拟环境
|
|
|
|
```
|
|
# 创建虚拟环境
|
|
python -m venv venv
|
|
|
|
# 激活虚拟环境
|
|
./vent/bin/activate
|
|
|
|
# 安装依赖
|
|
pip install -r requirements_version.txt
|
|
# (如果没有代理,使用国内镜像安装依赖)
|
|
pip install -r requirements_version.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
|
|
```
|
|
|
|
## 运行
|
|
|
|
```bash
|
|
python main.py --host 0.0.0.0 --port 7999
|
|
```
|
|
|
|
## 使用服务
|
|
|
|
支持的 model: `acge-large-zh` 与 `text-embedding-ada-002`
|
|
|
|
curl 示例
|
|
|
|
```bashg
|
|
curl http://localhost:7999/v1/embeddings \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"input": "The food was delicious and the waiter...",
|
|
"model": "acge-large-zh"
|
|
}'
|
|
```
|
|
|
|
python 示例
|
|
|
|
```python
|
|
from openai import OpenAI
|
|
client = OpenAI(base_url="http://localhost:7999/v1", api_key='whatever')
|
|
|
|
client.embeddings.create(
|
|
model="acge-large-zh",
|
|
input="The food was delicious and the waiter..."
|
|
)
|
|
```
|
|
|
|
详细 API 文档位于 <http://localhost:7999/docs>
|