๐ API ์๋ํฌ์ธํธ
์ด ๊ฐ์ด๋๋ API ์๋ํฌ์ธํธ์ ํจ๊ณผ์ ์ผ๋ก ์ํธ์์ฉํ์ฌ ์ฐ๋ฆฌ์ ๋ชจ๋ธ์ ์ฌ์ฉํ ์ํํ ํตํฉ ๋ฐ ์๋ํ๋ฅผ ๋ฌ์ฑํ๋ ๋ฐ ํ์์ ์ธ ์ ๋ณด๋ฅผ ์ ๊ณตํฉ๋๋ค. ์คํ์ ์ธ ์ค์ ์ด๋ฏ๋ก ํฅํ ์ ๋ฐ์ดํธ ๋ฐ ๊ฐ์ ์ด ์ด๋ฃจ์ด์ง ์ ์์ต๋๋ค.
์ธ์ฆโ
API์ ์์ ํ๊ฒ ์ ๊ทผํ๊ธฐ ์ํด ์ธ์ฆ์ด ํ์ํฉ๋๋ค ๐ก๏ธ. Bearer ํ ํฐ ๋ฉ์ปค๋์ฆ์ ์ฌ์ฉํ์ฌ API ์์ฒญ์ ์ธ์ฆํ ์ ์์ต๋๋ค. Open WebUI์ ์ค์ > ๊ณ์ ์์ API ํค๋ฅผ ํ๋ํ๊ฑฐ๋, ํ์์ JSON Web Token(JWT)์ ์ฌ์ฉํ์ฌ ์ธ์ฆํ ์ ์์ต๋๋ค.
์ฃผ์ API ์๋ํฌ์ธํธโ
๐ ๋ชจ๋ ๋ชจ๋ธ ์กฐํโ
-
์๋ํฌ์ธํธ:
GET /api/models
-
์ค๋ช : Open WebUI๋ฅผ ํตํด ์์ฑ๋๊ฑฐ๋ ์ถ๊ฐ๋ ๋ชจ๋ ๋ชจ๋ธ์ ๊ฐ์ ธ์ต๋๋ค.
-
์์:
curl -H "Authorization: Bearer YOUR_API_KEY" http://localhost:3000/api/models
๐ฌ ์ฑํ ์๋ฃโ
-
์๋ํฌ์ธํธ:
POST /api/chat/completions
-
์ค๋ช : Open WebUI ๋ชจ๋ธ, Ollama ๋ชจ๋ธ, OpenAI ๋ชจ๋ธ ๋ฐ Open WebUI ๊ธฐ๋ฅ ๋ชจ๋ธ์ ๋ํด OpenAI API์ ํธํ๋๋ ์ฑํ ์๋ฃ ์๋ํฌ์ธํธ๋ฅผ ์ ๊ณตํฉ๋๋ค.
-
Curl ์์:
curl -X POST http://localhost:3000/api/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d {
"model": "llama3.1",
"messages": [
{
"role": "user",
"content": "์ ํ๋์ ํ๋์์ธ๊ฐ์?"
}
]
} -
Python ์์:
import requests
def chat_with_model(token):
url = http://localhost:3000/api/chat/completions
headers = {
Authorization: fBearer {token},
Content-Type: application/json
}
data = {
"model": "granite3.1-dense:8b",
"messages": [
{
"role": "user",
"content": "์ ํ๋์ ํ๋์์ธ๊ฐ์?"
}
]
}
response = requests.post(url, headers=headers, json=data)
return response.json()
๐ฆ Ollama API ํ๋ก์ ์ง์โ
Ollama ๋ชจ๋ธ๊ณผ ์ง์ ์ํธ์์ฉํ๋ ค๋ฉด(Open WebUI๋ฅผ ํตํ ์๋ฒ ๋ฉ ์์ฑ ๋๋ Raw ํ๋กฌํํธ ์คํธ๋ฆฌ๋ฐ ํฌํจ), Open WebUI๋ ํ๋ก์ ๊ฒฝ๋ก๋ฅผ ํตํด Ollama API๋ก์ ํฌ๋ช ํ ํจ์ค์ค๋ฃจ๋ฅผ ์ ๊ณตํฉ๋๋ค.
- ๊ธฐ๋ณธ URL:
/ollama/<api>
- ์ฐธ๊ณ ์๋ฃ: Ollama API ๋ฌธ์
๐ ์๋ฃ ์์ฑ(์คํธ๋ฆฌ๋ฐ)โ
curl http://localhost:3000/ollama/api/generate -d {
"model": "llama3.2",
"prompt": "์ ํ๋์ ํ๋์์ธ๊ฐ์?"
}
๐ฆ ์ฌ์ฉ ๊ฐ๋ฅํ ๋ชจ๋ธ ๋ชฉ๋ก ์กฐํโ
curl http://localhost:3000/ollama/api/tags
๐ง ์๋ฒ ๋ฉ ์์ฑโ
curl -X POST http://localhost:3000/ollama/api/embed -d {
"model": "llama3.2",
"input": ["Open WebUI๋ ์ ๋ง ๋ฐ์ด๋์!", "์๋ฒ ๋ฉ์ ์์ฑํด๋ด
์๋ค."]
}
์ด๋ ๊ฒ์ ์ธ๋ฑ์ค, ๊ฒ์ ์์คํ ๋๋ Open WebUI ๋ค์์ Ollama ๋ชจ๋ธ์ ์ฌ์ฉํ๋ ๋ง์ถคํ ํ์ดํ๋ผ์ธ์ ๊ตฌ์ถํ ๋ ์ด์์ ์ ๋๋ค.
๐งฉ ๊ฒ์ ์ฆ๊ฐ ์์ฑ(RAG)โ
๊ฒ์ ์ฆ๊ฐ ์์ฑ(RAG) ๊ธฐ๋ฅ์ ์ธ๋ถ ์์ค์์ ๋ฐ์ดํฐ๋ฅผ ํตํฉํ์ฌ ์๋ต์ ํฅ์์ํฌ ์ ์๋๋ก ํฉ๋๋ค. ์๋์๋ ํ์ผ ๋ฐ ์ง์ ์ปฌ๋ ์ ์ API๋ฅผ ํตํด ๊ด๋ฆฌํ๊ณ ์ด๋ฅผ ์ฑํ ์๋ฃ ์ ํจ๊ณผ์ ์ผ๋ก ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช ํฉ๋๋ค.
ํ์ผ ์ ๋ก๋โ
RAG ์๋ต์ ์ธ๋ถ ๋ฐ์ดํฐ๋ฅผ ํ์ฉํ๋ ค๋ฉด ๋จผ์ ํ์ผ์ ์ ๋ก๋ํด์ผ ํฉ๋๋ค. ์ ๋ก๋๋ ํ์ผ์ ๋ด์ฉ์ด ์๋์ผ๋ก ์ถ์ถ๋์ด ๋ฒกํฐ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ์ฅ๋ฉ๋๋ค.
-
์๋ํฌ์ธํธ:
POST /api/v1/files/
-
Curl ์์:
curl -X POST -H "Authorization: Bearer YOUR_API_KEY" -H "Accept: application/json" \
-F "file=@/path/to/your/file" http://localhost:3000/api/v1/files/ -
Python ์์:
import requests
def upload_file(token, file_path):
url = http://localhost:3000/api/v1/files/
headers = {
Authorization: fBearer {token},
Accept: application/json
}
files = {file: open(file_path, rb)}
response = requests.post(url, headers=headers, files=files)
return response.json()
ํ์ผ์ ์ง์ ์ปฌ๋ ์ ์ ์ถ๊ฐโ
์ ๋ก๋ํ ํ ํ์ผ์ ์ง์ ์ปฌ๋ ์ ์ ๊ทธ๋ฃนํํ๊ฑฐ๋ ์ฑํ ์์ ๊ฐ๋ณ์ ์ผ๋ก ์ฐธ์กฐํ ์ ์์ต๋๋ค.
-
์๋ํฌ์ธํธ:
POST /api/v1/knowledge/{id}/file/add
-
Curl ์์:
curl -X POST http://localhost:3000/api/v1/knowledge/{knowledge_id}/file/add \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d {"file_id": "your-file-id-here"} -
Python ์์:
import requests
def add_file_to_knowledge(token, knowledge_id, file_id):
url = fhttp://localhost:3000/api/v1/knowledge/{knowledge_id}/file/add
headers = {
Authorization: fBearer {token},
Content-Type: application/json
}
data = {file_id: file_id}
response = requests.post(url, headers=headers, json=data)
return response.json()
์ฑํ ์๋ฃ์์ ํ์ผ ๋ฐ ์ปฌ๋ ์ ์ฌ์ฉโ
RAG ์ฟผ๋ฆฌ๋ฅผ ํตํด ํ๋ถํ ์๋ต์ ์ป๊ธฐ ์ํด ๊ฐ๋ณ ํ์ผ ๋๋ ์ ์ฒด ์ปฌ๋ ์ ์ ์ฐธ์กฐํ ์ ์์ต๋๋ค.
์ฑํ ์๋ฃ์์ ๊ฐ๋ณ ํ์ผ ์ฌ์ฉโ
์ด ๋ฐฉ๋ฒ์ ํน์ ํ์ผ์ ๋ด์ฉ์ ๊ธฐ๋ฐ์ผ๋ก ์ฑํ ๋ชจ๋ธ์ ์๋ต์ ์ง์คํ๊ณ ์ถ์ ๋ ์ ์ฉํฉ๋๋ค.
-
์๋ํฌ์ธํธ:
POST /api/chat/completions
-
Curl ์์ :
curl -X POST http://localhost:3000/api/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d {
"model": "gpt-4-turbo",
"messages": [
{"role": "user", "content": "์ด ๋ฌธ์์ ๊ฐ๋ ์ ์ค๋ช ํด์ฃผ์ธ์."}
],
"files": [
{"type": "file", "id": "your-file-id-here"}
]
} -
Python ์์ :
import requests
def chat_with_file(token, model, query, file_id):
url = http://localhost:3000/api/chat/completions
headers = {
Authorization: fBearer {token},
Content-Type: application/json
}
payload = {
model: model,
messages: [{role: user, content: query}],
files: [{type: file, id: file_id}]
}
response = requests.post(url, headers=headers, json=payload)
return response.json()
์ฑํ ์๋ฃ์์ ์ง์ ์ปฌ๋ ์ ์ฌ์ฉโ
์ง๋ฌธ์ด ๋ณด๋ค ๋์ ์ปจํ ์คํธ ๋๋ ์ฌ๋ฌ ๋ฌธ์์์ ํํ์ ๋ณผ ์ ์๋ ๊ฒฝ์ฐ ์๋ต์ ๊ฐํํ๋ ค๋ฉด ์ง์ ์ปฌ๋ ์ ์ ํ์ฉํ์ธ์.
-
์๋ํฌ์ธํธ:
POST /api/chat/completions
-
Curl ์์ :
curl -X POST http://localhost:3000/api/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d {
"model": "gpt-4-turbo",
"messages": [
{"role": "user", "content": "์ปฌ๋ ์ ์์ ๋ค๋ฃจ๋ ์ญ์ฌ์ ๊ด์ ์ ๋ํ ํต์ฐฐ๋ ฅ์ ์ ๊ณตํด์ฃผ์ธ์."}
],
"files": [
{"type": "collection", "id": "your-collection-id-here"}
]
} -
Python ์์ :
import requests
def chat_with_collection(token, model, query, collection_id):
url = http://localhost:3000/api/chat/completions
headers = {
Authorization: fBearer {token},
Content-Type: application/json
}
payload = {
model: model,
messages: [{role: user, content: query}],
files: [{type: collection, id: collection_id}]
}
response = requests.post(url, headers=headers, json=payload)
return response.json()
์ด๋ฌํ ๋ฐฉ๋ฒ์ ํตํด ์ ๋ก๋๋ ํ์ผ ๋ฐ ํ๋ ์ด์ ๋ ์ง์ ์ปฌ๋ ์ ์ ํตํด ์ธ๋ถ ์ง์์ ํจ๊ณผ์ ์ผ๋ก ํ์ฉํ ์ ์๋๋ก ํ๋ฉด, Open WebUI API๋ฅผ ์ฌ์ฉํ ์ฑํ ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ธฐ๋ฅ์ ๊ฐ์ ํ ์ ์์ต๋๋ค. ํ์ผ์ ๊ฐ๋ณ์ ์ผ๋ก ์ฌ์ฉํ๊ฑฐ๋ ์ปฌ๋ ์ ๋ด์์ ์ฌ์ฉํ์ฌ ํน์ ์๊ตฌ์ ๋ฐ๋ผ ํตํฉ์ ๋ง์ถคํํ ์ ์์ต๋๋ค.
ํตํฉ์ ์ธ LLM ์ ๊ณต์๋ก์์ Open WebUI ์ฌ์ฉ ์ด์ โ
Open WebUI๋ ๊ฐ๋ฐ์์ ๊ธฐ์ ๋ชจ๋์๊ฒ ํ์ ๋๊ตฌ๊ฐ ๋๋ ๋ค์ํ ์ด์ ์ ์ ๊ณตํฉ๋๋ค:
- ํตํฉ ์ธํฐํ์ด์ค: ๋จ์ผ ํตํฉ ํ๋ซํผ์ ํตํด ๋ค์ํ LLM๊ณผ์ ์ํธ์์ฉ์ ๊ฐ์ํํฉ๋๋ค.
- ์ฌ์ด ๊ตฌํ: ํฌ๊ด์ ์ธ ๋ฌธ์ ๋ฐ ์ปค๋ฎค๋ํฐ ์ง์์ ํตํด ๋น ๋ฅด๊ฒ ํตํฉ์ ์์ํ ์ ์์ต๋๋ค.
Swagger ๋ฌธ์ ๋งํฌโ
์ด ์๋น์ค๋ฅผ ์ํ Swagger ๋ฌธ์๋ฅผ ์ก์ธ์คํ๋ ค๋ฉด ENV
ํ๊ฒฝ ๋ณ์๋ฅผ dev
๋ก ์ค์ ํด์ผ ํฉ๋๋ค. ์ด ์ค์ ์์ด๋ ๋ฌธ์๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
Open WebUI๊ฐ ์ ๊ณตํ๋ ๋ค์ํ ์๋น์ค์ ๋ํ ์์ธํ API ๋ฌธ์์ ์ก์ธ์คํ์ธ์:
์ ํ๋ฆฌ์ผ์ด์ | ๋ฌธ์ ๊ฒฝ๋ก |
---|---|
๋ฉ์ธ | /docs |
์ ์ง์นจ์ ๋ฐ๋ฅด๋ฉด Open WebUI API๋ฅผ ์ ์ํ๊ฒ ํตํฉํ๊ณ ํ์ฉ์ ์์ํ ์ ์์ต๋๋ค. ๋ฌธ์ ๊ฐ ๋ฐ์ํ๊ฑฐ๋ ์ง๋ฌธ์ด ์์ผ๋ฉด Discord ์ปค๋ฎค๋ํฐ์ ๋ฌธ์ํ๊ฑฐ๋ FAQ๋ฅผ ์ฐธ์กฐํ์ธ์. ์ฆ๊ฑฐ์ด ์ฝ๋ฉ ๋์ธ์! ๐