实现了OpenAI的Embedding API服务,支持BERT、SBERT和CoSENT模型。🚀
以text2vec-base-chinese-paraphrase
为例,首先拉取镜像:
git lfs install
git clone https://huggingface.co/shibing624/text2vec-base-chinese-paraphrase
克隆项目:
git clone https://github.com/charSLee013/Embedding-API
安装依赖:
pip install -r requirements.txt
启动服务:
python3 server.py --model ./text2vec-base-chinese-paraphrase
构建Docker镜像:
docker build -t embedding_api .
运行容器:
docker run --rm -p 8899:8899 -v /data/text2vec-base-multilingual/:/model embedding_api python server.py --model /model
在项目中运行测试脚本:
bash test_client.sh
输出应类似于:
{
"object": "list",
"model": "text-embedding-ada-002",
"data": [
{
"index": 0,
"object": "embedding",
"embedding": [
0.19880373775959015,
...[1024个字段]
0.18911297619342804
]
}
],
"usage": {
"prompt_tokens": 26,
"total_tokens": 26
}
}
在启动服务器后,直接在浏览器中打开 http://localhost:8899/docs。