ओलामा मौजूदा एप्लिकेशनों को ओलामा से कनेक्ट करने में मदद के लिए एंथ्रोपिक मैसेजेज API के साथ अनुकूलता प्रदान करता है, जिसमें क्लॉड कोड जैसे टूल्स शामिल हैं।
उपयोग
पर्यावरण चर
ऐसे टूल्स के साथ ओलामा का उपयोग करने के लिए जो एंथ्रोपिक API (जैसे क्लॉड कोड) की अपेक्षा रखते हैं, इन पर्यावरण चरों को सेट करें:
shell
export ANTHROPIC_AUTH_TOKEN=ollama # आवश्यक लेकिन अनदेखा किया जाता है
export ANTHROPIC_BASE_URL=http://localhost:11434सरल /v1/messages उदाहरण
python
client = anthropic.Anthropic(
base_url='http://localhost:11434',
api_key='ollama', # required but ignored
)
message = client.messages.create(
model='qwen3-coder',
max_tokens=1024,
messages=[
{'role': 'user', 'content': 'Hello, how are you?'}
]
)
print(message.content[0].text)javascript
const anthropic = new Anthropic({
baseURL: "http://localhost:11434",
apiKey: "ollama", // required but ignored
});
const message = await anthropic.messages.create({
model: "qwen3-coder",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello, how are you?" }],
});
console.log(message.content[0].text);shell
curl -X POST http://localhost:11434/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: ollama" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "qwen3-coder",
"max_tokens": 1024,
"messages": [{ "role": "user", "content": "Hello, how are you?" }]
}'स्ट्रीमिंग उदाहरण
python
client = anthropic.Anthropic(
base_url='http://localhost:11434',
api_key='ollama',
)
with client.messages.stream(
model='qwen3-coder',
max_tokens=1024,
messages=[{'role': 'user', 'content': 'Count from 1 to 10'}]
) as stream:
for text in stream.text_stream:
print(text, end='', flush=True)javascript
const anthropic = new Anthropic({
baseURL: "http://localhost:11434",
apiKey: "ollama",
});
const stream = await anthropic.messages.stream({
model: "qwen3-coder",
max_tokens: 1024,
messages: [{ role: "user", content: "Count from 1 to 10" }],
});
for await (const event of stream) {
if (
event.type === "content_block_delta" &&
event.delta.type === "text_delta"
) {
process.stdout.write(event.delta.text);
}
}shell
curl -X POST http://localhost:11434/v1/messages \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-coder",
"max_tokens": 1024,
"stream": true,
"messages": [{ "role": "user", "content": "Count from 1 to 10" }]
}'टूल कॉलिंग उदाहरण
python
client = anthropic.Anthropic(
base_url='http://localhost:11434',
api_key='ollama',
)
message = client.messages.create(
model='qwen3-coder',
max_tokens=1024,
tools=[
{
'name': 'get_weather',
'description': 'Get the current weather in a location',
'input_schema': {
'type': 'object',
'properties': {
'location': {
'type': 'string',
'description': 'The city and state, e.g. San Francisco, CA'
}
},
'required': ['location']
}
}
],
messages=[{'role': 'user', 'content': "What's the weather in San Francisco?"}]
)
for block in message.content:
if block.type == 'tool_use':
print(f'Tool: {block.name}')
print(f'Input: {block.input}')javascript
const anthropic = new Anthropic({
baseURL: "http://localhost:11434",
apiKey: "ollama",
});
const message = await anthropic.messages.create({
model: "qwen3-coder",
max_tokens: 1024,
tools: [
{
name: "get_weather",
description: "Get the current weather in a location",
input_schema: {
type: "object",
properties: {
location: {
type: "string",
description: "The city and state, e.g. San Francisco, CA",
},
},
required: ["location"],
},
},
],
messages: [{ role: "user", content: "What's the weather in San Francisco?" }],
});
for (const block of message.content) {
if (block.type === "tool_use") {
console.log("Tool:", block.name);
console.log("Input:", block.input);
}
}shell
curl -X POST http://localhost:11434/v1/messages \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-coder",
"max_tokens": 1024,
"tools": [
{
"name": "get_weather",
"description": "Get the current weather in a location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state"
}
},
"required": ["location"]
}
}
],
"messages": [{ "role": "user", "content": "What is the weather in San Francisco?" }]
}'क्लॉड कोड के साथ उपयोग
क्लॉड कोड को इसे अपने बैकएंड के रूप में उपयोग करने के लिए कॉन्फ़िगर किया जा सकता है।
अनुशंसित मॉडल
कोडिंग उपयोग के मामलों के लिए glm-4.7, minimax-m2.1 और qwen3-coder जैसे मॉडलों की अनुशंसा की जाती है।
उपयोग से पहले मॉडल डाउनलोड करें:
shell
ollama pull qwen3-coderनोट: क्यूएन 3 कोडर एक 30B पैरामीटर वाला मॉडल है जिसे सुचारू रूप से चलाने के लिए कम से कम 24GB VRAM की आवश्यकता होती है। लंबे कॉन्टेक्स्ट लंबाई के लिए अधिक VRAM की आवश्यकता होती है।
shell
ollama pull glm-4.7:cloudत्वरित सेटअप
shell
ollama launch claudeयह आपसे मॉडल चुनने, क्लॉड कोड को स्वचालित रूप से कॉन्फ़िगर करने और इसे लॉन्च करने के लिए पूछेगा। लॉन्च किए बिना कॉन्फ़िगर करने के लिए:
shell
ollama launch claude --configमैन्युअल सेटअप
पर्यावरण चर सेट करें और क्लॉड कोड चलाएं:
shell
ANTHROPIC_AUTH_TOKEN=ollama ANTHROPIC_BASE_URL=http://localhost:11434 claude --model qwen3-coderया अपने शैल प्रोफाइल में पर्यावरण चर सेट करें:
shell
export ANTHROPIC_AUTH_TOKEN=ollama # आवश्यक लेकिन अनदेखा किया जाता है
export ANTHROPIC_BASE_URL=http://localhost:11434फिर किसी भी ओलामा मॉडल के साथ क्लॉड कोड चलाएं:
shell
claude --model qwen3-coderएंडपॉइंट्स
/v1/messages
समर्थित सुविधाएँ
- [x] Messages
- [x] Streaming
- [x] System prompts
- [x] Multi-turn conversations
- [x] Vision (images)
- [x] Tools (function calling)
- [x] Tool results
- [x] Thinking/extended thinking
समर्थित अनुरोध फ़ील्ड्स
- [x]
model - [x]
max_tokens - [x]
messages- [x] Text
content - [x] Image
content(base64) - [x] Array of content blocks
- [x]
tool_useblocks - [x]
tool_resultblocks - [x]
thinkingblocks
- [x] Text
- [x]
system(string or array) - [x]
stream - [x]
temperature - [x]
top_p - [x]
top_k - [x]
stop_sequences - [x]
tools - [x]
thinking - [ ]
tool_choice - [ ]
metadata
समर्थित प्रतिक्रिया फ़ील्ड्स
- [x]
id - [x]
type - [x]
role - [x]
model - [x]
content(text, tool_use, thinking blocks) - [x]
stop_reason(end_turn, max_tokens, tool_use) - [x]
usage(input_tokens, output_tokens)
स्ट्रीमिंग इवेंट्स
- [x]
message_start - [x]
content_block_start - [x]
content_block_delta(text_delta, input_json_delta, thinking_delta) - [x]
content_block_stop - [x]
message_delta - [x]
message_stop - [x]
ping - [x]
error
मॉडल
ओलामा स्थानीय और क्लाउड दोनों प्रकार के मॉडलों का समर्थन करता है।
स्थानीय मॉडल
उपयोग से पहले स्थानीय मॉडल पुल करें:
shell
ollama pull qwen3-coderअनुशंसित स्थानीय मॉडल:
qwen3-coder- कोडिंग कार्यों के लिए उत्कृष्टgpt-oss:20b- मजबूत सामान्य-उद्देश्य मॉडल
क्लाउड मॉडल
क्लाउड मॉडल पुल किए बिना तुरंत उपलब्ध होते हैं:
glm-4.7:cloud- उच्च-प्रदर्शन वाला क्लाउड मॉडलminimax-m2.1:cloud- तेज़ क्लाउड मॉडल
डिफ़ॉल्ट मॉडल नाम
ऐसे टूलिंग के लिए जो claude-3-5-sonnet जैसे डिफ़ॉल्ट एंथ्रोपिक मॉडल नामों पर निर्भर करते हैं, मौजूदा मॉडल नाम को कॉपी करने के लिए ollama cp का उपयोग करें:
shell
ollama cp qwen3-coder claude-3-5-sonnetइसके बाद, इस नए मॉडल नाम को model फ़ील्ड में निर्दिष्ट किया जा सकता है:
shell
curl http://localhost:11434/v1/messages \
-H "Content-Type: application/json" \
-d '{
"model": "claude-3-5-sonnet",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Hello!"
}
]
}'एंथ्रोपिक API से अंतर
व्यवहार अंतर
- API कुंजी स्वीकार की जाती है लेकिन सत्यापित नहीं की जाती
anthropic-versionहेडर स्वीकार किया जाता है लेकिन उपयोग में नहीं लिया जाता- टोकन गणना मूल मॉडल के टोकनाइज़र पर आधारित अनुमान हैं
समर्थित नहीं
निम्नलिखित एंथ्रोपिक API सुविधाएँ वर्तमान में समर्थित नहीं हैं:
| सुविधा | विवरण |
|---|---|
/v1/messages/count_tokens | टोकन गणना एंडपॉइंट |
tool_choice | विशिष्ट टूल उपयोग को बाध्य करना या टूल्स को अक्षम करना |
metadata | अनुरोध मेटाडेटा (user_id) |
| Prompt caching | कैशिंग प्रifix के लिए cache_control ब्लॉक |
| Batches API | एसिंक बैच प्रोसेसिंग के लिए /v1/messages/batches |
| Citations | citations कंटेंट ब्लॉक |
| PDF support | PDF फाइलों के साथ document कंटेंट ब्लॉक |
| Server-sent errors | स्ट्रीमिंग के दौरान error इवेंट (त्रुटियाँ HTTP स्टेटस लौटाती हैं) |
आंशिक समर्थन
| सुविधा | स्थिति |
|---|---|
| Image content | Base64 इमेज समर्थित; URL इमेज समर्थित नहीं |
| Extended thinking | बुनियादी समर्थन; budget_tokens स्वीकार किया जाता है लेकिन लागू नहीं किया जाता |