一、docker安装
- docker安装和exe安装的区别?
docker pull mintplexlabs/anythingllm
docker images
windows:
$env:STORAGE_LOCATION="$HOME\Documents\anythingllm"; `
If(!(Test-Path $env:STORAGE_LOCATION)) {New-Item $env:STORAGE_LOCATION -ItemType Directory}; `
If(!(Test-Path "$env:STORAGE_LOCATION\.env")) {New-Item "$env:STORAGE_LOCATION\.env" -ItemType File}; `
docker run -d -p 3001:3001 `
--cap-add SYS_ADMIN `
-v "$env:STORAGE_LOCATION`:/app/server/storage" `
-v "$env:STORAGE_LOCATION\.env:/app/server/.env" `
-e STORAGE_DIR="/app/server/storage" `
mintplexlabs/anythingllm;
参考:https://docs.anythingllm.com/installation-docker/local-docker
二、配置AnythingLLM
三、使用API调用AnythingLLM
1. 生成API密钥
2. “Authorize”API密钥
复制API秘钥,点击“阅读API文档”打开API接口文档,点击右边的“Authorize”按钮,把API秘钥复制进去,然后就可以调试接口了。
运行第一个接口/v1/auth
,如果返回截图中的结果,即调用成功。
查看工作区信息:
3. python调用
import requests
def ask_anythingllm(question, slug, api_key):
url = f"http://localhost:3001/api/v1/workspace/{slug}/chat"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
"accept": "application/json"
}
data = {
"message": question,
"mode": "query" # 可选chat/query模式
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
result = response.json()
# 提取有效回答(去除思考过程)
# answer = result['textResponse'].split('</think>')[-1].strip()
answer = result
sources = result.get('sources', [])
return answer, sources
else:
return f"Error: {response.text}", []
# 示例调用
api_key = "Your-Api-Key"
slug = "Your-Slug"
question = "你是谁?"
answer, sources = ask_anythingllm(question, slug, api_key)
print("回答:", answer)
print("来源:", [src['title'] for src in sources])