Qwen2-7b+AnythingLLM+ollama 部署API调用

一、ollama 安装

下载地址:Ollama

ollama常用命令

ollama serve 启动ollama

ollama create 从模型文件创建模型

ollama show 显示模型信息

ollama run 运行模型

ollama pull 从注册表中拉取模型

ollama push 将模型推送到注册表

ollama list 列出模型

ollama cp 复制模型

ollama rm 删除模型

ollama help 获取有关任何命令的帮助信息

二、AnythingLLM安装

下载地址:AnythingLLM | The all-in-one AI application for everyone

三、下载Qwen2-7b

1、安装ollama完成后,在window环境下,打开CMD窗口输入以下命令,开始自动下载安装

ollama run qwen2:7b

安装好qwen2-7b可以关掉了,顺便先在CMD窗口下载一个embedding模型

ollama pull nomic-embed-text

四、AnythingLLM配置Qwen2-7b

点击配置

选择刚刚我们在ollama安装的模型

Embedder模型配置

选择刚才安装好的nomic-embed-text模型

向量数据库默认

五、创建聊天窗口

基本的聊天的窗口已经部署好了,可以随意的对话。 

以下是创建的聊天空间的一些基本设置说明讲解

六、创建基于文件的知识库

根据文件大小和电脑性能,来embedding文件

提问文档中的相关内容,会直接根据文档返回

六、API接口生成

创建密钥

七、接口文档访问

 http://localhost:3001/api/docs/#/

八、常用接口列表CURL

获取所有上传的文档
curl --location --request GET 'http://localhost:3001/api/v1/documents' \
--header 'accept: application/json' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxx'

删除文档
curl --location --request DELETE 'http://localhost:3001/api/v1/system/remove-documents' \
--header 'accept: application/json' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
  "names": [
    "custom-documents/file.txt-fc4beeeb-e436-454d-8bb4-e5b8979cb48f.json"
  ]
}'

上传文档
curl --location --request POST 'http://localhost:3001/api/v1/document/upload' \
--header 'accept: application/json' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxx' \
--header 'Content-Type: multipart/form-data' \
--form 'file="@用户服务协议【模板】.docx;type=application/vnd.openxmlformats-officedocument.wordprocessingml.document"'

创建空间
curl --location --request POST 'http://localhost:3001/api/v1/workspace/new' \
--header 'accept: application/json' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
  "name": "qwen2-7b-api-test"
}'

查询所有空间
curl --location --request GET 'http://localhost:3001/api/v1/workspaces' \
--header 'accept: application/json' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxx'

查询指定名称空间
curl --location --request GET 'http://localhost:3001/api/v1/workspace/test' \
--header 'accept: application/json' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxx'

空间配置更新
curl --location --request POST 'http://localhost:3001/api/v1/workspace/qwen2-7b-api-test/update' \
--header 'accept: application/json' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
        "openAiTemp": 0.7,
        "openAiHistory": 1,
        "openAiPrompt": "你将饰演一个喝醉酒的酒鬼,你将带着醉意回答问题",
        "similarityThreshold": 0.25,
        "chatProvider": "ollama",
        "chatModel": "qwen2:7b",
        "topN": 4,
        "chatMode": "chat",
        "queryRefusalResponse": "你的问题很刁钻,我答不上"
}
'

删除空间
curl --location --request DELETE 'http://localhost:3001/api/v1/workspace/test' \
--header 'accept: */*' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxx'


获取该空间的聊天记录
curl --location --request GET 'http://localhost:3001/api/v1/workspace/qwen2-7b-prompt/chats' \
--header 'accept: application/json' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxx'

空间添加embedding文件
curl --location --request POST 'http://localhost:3001/api/v1/workspace/qwen2-7b-api-test/update-embeddings' \
--header 'accept: application/json' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
  "adds": [
    "custom-documents/my-pdf.pdf-hash.json"
  ],
  "deletes": [
    "custom-documents/anythingllm.txt-hash.json"
  ]
}'

指定空间聊天
curl --location --request POST 'http://localhost:3001/api/v1/workspace/qwen2-7b-api-test/chat' \
--header 'accept: application/json' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
  "message": "What is AnythingLLM?",
  "mode": "chat"
}'

指定空间聊天-流式
curl --location --request POST 'http://localhost:3001/api/v1/workspace/qwen2-7b-api-test/stream-chat' \
--header 'accept: text/event-stream' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
  "message": "你是谁",
  "mode": "chat"
}'

创建指定空间,新的线程
curl --location --request POST 'http://localhost:3001/api/v1/workspace/qwen2-7b-api-test/thread/new' \
--header 'accept: application/json' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
}'

删除指定空间的线程
curl --location --request DELETE 'http://localhost:3001/api/v1/workspace/qwen2-7b-api-test/thread/59e6261f-1cec-4825-8e6a-05095f46b510' \
--header 'accept: */*' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxx'


指定空间,线程聊天
curl --location --request POST 'http://localhost:3001/api/v1/workspace/qwen2-7b-api-test/thread/b860c495-6894-41cc-82bc-87e6eda784b5/chat' \
--header 'accept: application/json' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
  "message": "你喝了多少酒啊",
  "mode": "chat"
}'

指定空间,线程聊天-流式
curl --location --request POST 'http://localhost:3001/api/v1/workspace/qwen2-7b-api-test/thread/c654d0cb-3550-4c73-913e-cfc1d52fc536/stream-chat' \
--header 'accept: text/event-stream' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
  "message": "如何更新你的知识库",
  "mode": "chat"
}'

评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值