API 端点
默认端口:http://localhost:11434
对话接口
curl http://localhost:11434/api/chat -d '{
"model": "llama3.1",
"messages": [{"role": "user", "content": "你好"}]
}'生成接口
curl http://localhost:11434/api/generate -d '{
"model": "llama3.1",
"prompt": "写一首诗",
"stream": false
}'OpenAI 兼容
curl http://localhost:11434/v1/chat/completions -d '{
"model": "llama3.1",
"messages": [{"role": "user", "content": "Hello"}]
}'
# Python OpenAI SDK
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
response = client.chat.completions.create(
model="llama3.1",
messages=[{"role": "user", "content": "Hello"}]
)