💡 受 imClumsyPanda 的项目 langchain-ChatGLM 启发,采用flask、uvicorn建立了基于开源模型实现的文档与查询embedding转换库
Embedding 选用的是 GanymedeNil/text2vec-large-chinese
-
Embedding 模型硬件需求
本项目中默认选用的 Embedding 模型 GanymedeNil/text2vec-large-chinese 约占用显存 3GB,也可修改为在 CPU 中运行。v0版本大小18.7GB,相比于v1版本的4.74GB增加了Ernie模型等依赖,v1版本直接访问接口即可自动下载模型。
localhost:port/v1/doc_embeddings
method: 'POST'
'doc_path', default='./static/FastGPT.html', type=str, 含义是文件路径
'loader_type', default='UnstructuredHTMLLoader', type=str, 含义是loader类型,参考这里
'model', default='ernie-base', type=str, 含义是嵌入模型,目前支持"ernie-tiny"、"ernie-base"、"text2vec"
{'doc_vec':vec, 'chunks':chunks}
doc_vec含义是文档向量
chunks含义是向量的语义,和doc_vec同dim0大小
localhost:port/v1/embeddings
method: 'POST'
'message', type=str, 含义是查询语句
'model', default='ernie-base', type=str, 含义是嵌入模型,目前支持"ernie-tiny"、"ernie-base"、"text2vec"
{'message_vec':vec, 'message':message}
message_vec含义是查询向量
message
localhost:/v1/chat/completions
method: 'POST'
'message', type=str, 含义是prompt更新后的问题
'history', type=list, default=[], 含义是历史对话信息
'context', type=list, default=[], 含义是相似度匹配出的上下文
'stream', type=bool, default=False, 含义是是否采用流式返回,如为True则返回 SSE 数据流
'model', default='chatglm-6b-int4', type=str, 含义是llm模型, 目前支持"chatglm-6b-int4-qe"、"chatglm-6b-int4"、"chatglm-6b"
'config_str', default='{}', type=str, 含义是模型配置信息, 目前支持max_token: int、temperature: float、top_p: float、history_len: int
{'answer':resp}
命令行访问示例
curl -X POST "http://127.0.0.1:5001/v1/chat/completions" -H 'Content-Type: application/json' -d '{"message": "什么是aha?","history":[["Aha是一个校园企业,专注竞赛分享,你记住了吗","我记住了"]]}'
curl -X POST "localhost:5001/v1/embeddings" -H 'Content-Type: application/json' -d '{"input": "aha_pocket"}' -o /home/user/fastgpt/test_gpt.txt
curl -X POST "localhost:5001/v1/doc_embeddings" -H 'Content-Type: application/json' -d '{"doc_path": "./static/FastGPT.html","loader_type":"UnstructuredHTMLLoader","model":"ernie-base"}' -o /home/user/fastgpt/test_gpt.txt
docker pull ccr.ccs.tencentyun.com/aha_zjut/fastgpt:v0