# Anythingllm on/in Docker
### 1. 下載 Docker
https://www.docker.com/
先下載、開啟、登錄就好
### 2. 在本地 terminal 輸入
```=
docker pull mintplexlabs/anythingllm
```
```=
docker run -d -p 3001:3001 --name anything-llm mintplexlabs/anythingllm
```
### 3. 開啟本地 http://localhost:3001
設定 Anythingllm
### 4. 新增 workspace
```python=
import requests
# 設定 API 端點和標頭
url = 'http://localhost:3001/api/v1/workspace/new'
headers = {
'Authorization': 'Bearer your_api_key', #改成自己的 api_key
'Content-Type': 'application/json',
'accept': 'application/json'
}
# 設定工作區名稱
data = {
'name': 'workspace_name' #輸入 workspace name
}
# 發送 POST 請求
response = requests.post(url, json=data, headers=headers)
# 檢查回應狀態
if response.status_code == 200:
print('工作區創建成功:', response.json())
else:
print('工作區創建失敗:', response.text)
```
### 5. 上傳檔案
先利用 https://hackmd.io/@k0217/rk_xOsa3ke 的方式取得資料網址,以下實作就可以使用資料網址去上傳資料到 anythingLLM
```python=
import requests
# 設定 API 端點和標頭
url = 'http://localhost:3001/api/v1/document/upload'
headers = {
'Authorization': 'Bearer your_api_key', #改成自己的 api_key
'accept': 'application/json'
}
file_url = 'https://cms-carrier.ntpu.edu.tw/uploads/113_04_24_56_0626_3057cfcce2.pdf' # 替換 PDF 文件網址
response = requests.get(file_url)
if response.status_code == 200:
# 下載文件到內存
file_content = response.content
else:
print(f"無法下載文件,狀態碼:{response.status_code}")
exit()
files = {'file': ('filename.pdf', file_content, 'application/pdf')}
data = {
'workspace': 'workspace_name' #輸入 workspace name
}
# 發送 POST 請求
response = requests.post(url, files=files, data=data, headers=headers)
# 檢查回應狀態
if response.status_code == 200:
print('文件上傳成功:', response.json())
else:
print('文件上傳失敗:', response.text)
```
### 6. 檢查上傳
```python=
import requests
# 設定 API 端點和標頭
url = 'http://localhost:3001/api/v1/documents'
headers = {
'Authorization': 'Bearer your_api_key', #改成自己的 api_key
'accept': 'application/json'
}
# 發送 GET 請求
response = requests.get(url, headers=headers)
# 檢查回應狀態
if response.status_code == 200:
documents = response.json()
print('已上傳的文件列表:')
for doc in documents:
print(doc)
else:
print('無法獲取文件列表:', response.text)
```
### 7. 與 anythingLLM 對話
```python=
import requests
# 設定 API 端點和標頭
url = 'http://localhost:3001/api/v1/workspace/{workspace_name}/chat' #換成自己的 workspace 名
headers = {
'Authorization': 'Bearer your_api_key',
'Accept': 'application/json'
}
data = {
'message': '你是誰?',
'mode': 'chat' # 或 'query'
}
# 發送 POST 請求
response = requests.post(url, headers=headers, json=data)
# 檢查回應狀態
if response.status_code == 200:
response_data = response.json()
print('回覆:')
print(response_data.get('textResponse'))
else:
print('無法獲取回覆:', response.text)
```


---
參考資料:
- [手把手教學AnythingLLM](https://hackmd.io/@chrish0729/Hkgggr9WC)
- [AnythingLLM + Ollama輕鬆架設多人用的客製化 RAG](https://medium.com/@pang2258/anythingllm-ollama%E8%BC%95%E9%AC%86%E6%9E%B6%E8%A8%AD%E5%A4%9A%E4%BA%BA%E7%94%A8%E7%9A%84%E5%AE%A2%E8%A3%BD%E5%8C%96-rag-2d05954bf771)
- [AnythingLLM的API使用方法,手把手教你把本地RAG 部署到自己的网页上](https://blog.csdn.net/m0_51242270/article/details/142257192)
- [Day 27:Backstage 專題開發 - 利用 Ollama + AnythingLLM 打造本地 AI 助手](https://ithelp.ithome.com.tw/articles/10364159)