Loading...
Loading...
Compare original and translation side by side
curl http://localhost:11434/api/chat -d '{
"model": "gemma3",
"messages": [
{
"role": "user",
"content": "Why is the sky blue?"
}
]
}'curl http://localhost:11434/api/chat -d '{
"model": "gemma3",
"messages": [
{
"role": "user",
"content": "Why is the sky blue?"
}
]
}'curl http://localhost:11434/api/generate -d '{
"model": "gemma3",
"prompt": "Why is the sky blue?"
}'curl http://localhost:11434/api/generate -d '{
"model": "gemma3",
"prompt": "Why is the sky blue?"
}'from openai import OpenAI
client = OpenAI(
base_url='http://localhost:11434/v1/',
api_key='ollama', # required but ignored
)
chat_completion = client.chat.completions.create(
messages=[
{
'role': 'user',
'content': 'Say this is a test',
}
],
model='llama3.2',
)from openai import OpenAI
client = OpenAI(
base_url='http://localhost:11434/v1/',
api_key='ollama', # required but ignored
)
chat_completion = client.chat.completions.create(
messages=[
{
'role': 'user',
'content': 'Say this is a test',
}
],
model='llama3.2',
)from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1/", api_key="ollama")
response = client.chat.completions.create(
model="llava",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "What's in this image?"},
{
"type": "image_url",
"image_url": "data:image/png;base64,iVBORw0KG...",
},
],
}
],
max_tokens=300,
)from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1/", api_key="ollama")
response = client.chat.completions.create(
model="llava",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "What's in this image?"},
{
"type": "image_url",
"image_url": "data:image/png;base64,iVBORw0KG...",
},
],
}
],
max_tokens=300,
)client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
embeddings = client.embeddings.create(
model="all-minilm",
input=["why is the sky blue?", "why is the grass green?"],
)client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
embeddings = client.embeddings.create(
model="all-minilm",
input=["why is the sky blue?", "why is the grass green?"],
)from pydantic import BaseModel
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
class FriendInfo(BaseModel):
name: str
age: int
is_available: bool
class FriendList(BaseModel):
friends: list[FriendInfo]
completion = client.beta.chat.completions.parse(
temperature=0,
model="llama3.1:8b",
messages=[
{"role": "user", "content": "Return a list of friends in JSON format"}
],
response_format=FriendList,
)
friends_response = completion.choices[0].message
if friends_response.parsed:
print(friends_response.parsed)from pydantic import BaseModel
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
class FriendInfo(BaseModel):
name: str
age: int
is_available: bool
class FriendList(BaseModel):
friends: list[FriendInfo]
completion = client.beta.chat.completions.parse(
temperature=0,
model="llama3.1:8b",
messages=[
{"role": "user", "content": "Return a list of friends in JSON format"}
],
response_format=FriendList,
)
friends_response = completion.choices[0].message
if friends_response.parsed:
print(friends_response.parsed)import OpenAI from "openai";
const openai = new OpenAI({
baseURL: "http://localhost:11434/v1/",
apiKey: "ollama", // required but ignored
});
const chatCompletion = await openai.chat.completions.create({
messages: [{ role: "user", content: "Say this is a test" }],
model: "llama3.2",
});import OpenAI from "openai";
const openai = new OpenAI({
baseURL: "http://localhost:11434/v1/",
apiKey: "ollama", // required but ignored
});
const chatCompletion = await openai.chat.completions.create({
messages: [{ role: "user", content: "Say this is a test" }],
model: "llama3.2",
});undefinedundefined
Or use API keys for direct cloud access:
```bash
export OLLAMA_API_KEY=your_api_key
curl https://ollama.com/api/generate \
-H "Authorization: Bearer $OLLAMA_API_KEY" \
-d '{
"model": "gpt-oss:120b",
"prompt": "Why is the sky blue?",
"stream": false
}'
或使用API密钥直接访问云:
```bash
export OLLAMA_API_KEY=your_api_key
curl https://ollama.com/api/generate \
-H "Authorization: Bearer $OLLAMA_API_KEY" \
-d '{
"model": "gpt-oss:120b",
"prompt": "Why is the sky blue?",
"stream": false
}'undefinedundefined
**Linux (systemd):**
```bash
**Linux (systemd):**
```bash
**Windows:**undefined
**Windows:**undefinedollama ps100% GPU100% CPU48%/52% CPU/GPUollama ps100% GPU100% CPU48%/52% CPU/GPUhttp://localhost:11434/apihttps://ollama.com/api/v1/http://localhost:11434/apihttps://ollama.com/api/v1/http://localhost:11434ollama signinhttps://ollama.com/apihttp://localhost:11434ollama signinhttps://ollama.com/apigemma3llama3.2qwen3-cloudgpt-oss:120b-cloudqwen3-coder:480b-cloudllavagemma3llama3.2qwen3-cloudgpt-oss:120b-cloudqwen3-coder:480b-cloudllavaOLLAMA_HOST127.0.0.1:11434OLLAMA_CONTEXT_LENGTH2048OLLAMA_MODELSOLLAMA_ORIGINSHTTPS_PROXYOLLAMA_HOST127.0.0.1:11434OLLAMA_CONTEXT_LENGTH2048OLLAMA_MODELSOLLAMA_ORIGINSHTTPS_PROXY200400404429500502{
"error": "the model failed to generate a response"
}200400404429500502{
"error": "the model failed to generate a response"
}"stream": false"stream": falsereferences//api/generate/api/chat/api/embedreferences//api/generate/api/chat/api/embed/api/generate/api/chatbase_url='http://localhost:11434/v1/'ollama psllms-txt.md/api/generate/api/chatbase_url='http://localhost:11434/v1/'ollama psllms-txt.mdllms-txt.mdllms-txt.mdllms.mdllms-txt.mdllms.mdllms-txt.md/api/chat/api/embedHTTPS_PROXYollama signin-cloud/api/chat/api/embedHTTPS_PROXYollama signin-cloudollama psollama psundefinedundefined
See "How do I configure Ollama server?" in `llms-txt.md` for platform-specific instructions.
查看`llms-txt.md`中的"如何配置Ollama服务器?"获取平台特定说明。undefinedundefined
See "How do I use Ollama behind a proxy?" in `llms-txt.md`.
查看`llms-txt.md`中的"如何在代理后使用Ollama?"。undefinedundefined
See "How can I allow additional web origins?" in `llms-txt.md`.
查看`llms-txt.md`中的"如何允许额外的Web来源?"。undefinedundefinedundefinedundefined