Ollama (स्थानीय मॉडल)

LLMs को स्थानीय रूप से पूर्ण गोपनीयता के साथ चलाएँ - कोई API कुंजी नहीं, कोई इंटरनेट नहीं, कोई लागत नहीं।

अवलोकन

┌─────────────────────────────────────────────────────────────────────┐
│                         Ollama Local Setup                          │
├─────────────────────────────────────────────────────────────────────┤
│                                                                     │
│   Your Machine                                                      │
│   ┌─────────────────────────────────────────────────────────────┐  │
│   │                                                             │  │
│   │   ┌──────────────┐      ┌──────────────┐                   │  │
│   │   │  ADK-Rust    │ ───▶ │   Ollama     │                   │  │
│   │   │  Agent       │      │   Server     │                   │  │
│   │   └──────────────┘      └──────┬───────┘                   │  │
│   │                                │                            │  │
│   │                         ┌──────▼───────┐                   │  │
│   │                         │  Local LLM   │                   │  │
│   │                         │  (llama3.2)  │                   │  │
│   │                         └──────────────┘                   │  │
│   │                                                             │  │
│   └─────────────────────────────────────────────────────────────┘  │
│                                                                     │
│   🔒 100% Private - Data never leaves your machine                 │
│                                                                     │
└─────────────────────────────────────────────────────────────────────┘

Ollama क्यों?

लाभविवरण
🆓 मुफ़्तकभी कोई API लागत नहीं
🔒 निजीडेटा आपके मशीन पर रहता है
📴 ऑफ़लाइनइंटरनेट के बिना काम करता है
🎛️ नियंत्रणकोई भी मॉडल चुनें, सेटिंग्स को अनुकूलित करें
तेज़कोई नेटवर्क विलंबता नहीं

चरण 1: Ollama स्थापित करें

macOS

brew install ollama

Linux

curl -fsSL https://ollama.com/install.sh | sh

Windows

ollama.com से डाउनलोड करें


चरण 2: सर्वर प्रारंभ करें

ollama serve

आपको यह दिखना चाहिए:

Couldn't find '/Users/you/.ollama/id_ed25519'. Generating new private key.
Your new public key is: ssh-ed25519 AAAA...
time=2024-01-05T12:00:00.000Z level=INFO source=server.go msg="Listening on 127.0.0.1:11434"

चरण 3: एक मॉडल पुल करें

एक नए टर्मिनल में:

# Recommended starter model (3B parameters, fast)
ollama pull llama3.2:3b

# Other popular models
ollama pull qwen3.6:35b-a3b   # Latest Qwen — 73.4% SWE-bench, MoE 35B/3B active
ollama pull qwen3.5            # Strong multilingual and coding
ollama pull qwen3-coder:30b    # Code-focused with tool calling
ollama pull mistral:7b        # Good for code
ollama pull deepseek-r1:14b   # Reasoning model
ollama pull devstral:24b      # Optimized for coding
ollama pull gemma3:9b         # Google's efficient model
ollama pull codellama:13b     # Code generation

चरण 4: अपने प्रोजेक्ट में जोड़ें

[dependencies]
adk-model = { version = "2.0.0", features = ["ollama"] }

चरण 5: कोड में उपयोग करें

use adk_model::ollama::{OllamaModel, OllamaConfig};
use adk_agent::LlmAgentBuilder;
use std::sync::Arc;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // No API key needed!
    let model = OllamaModel::new(OllamaConfig::new("llama3.2"))?;

    let agent = LlmAgentBuilder::new("local_assistant")
        .instruction("You are a helpful assistant running locally.")
        .model(Arc::new(model))
        .build()?;

    // Use the agent...
    Ok(())
}

पूर्ण कार्यशील उदाहरण

use adk_rust::prelude::*;
use adk_rust::Launcher;
use std::sync::Arc;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    dotenvy::dotenv().ok();
    
    // No API key needed!
    let model = OllamaModel::new(OllamaConfig::new("llama3.2"))?;

    let agent = LlmAgentBuilder::new("ollama_assistant")
        .description("Ollama-powered local assistant")
        .instruction("You are a helpful assistant running locally via Ollama. Be concise.")
        .model(Arc::new(model))
        .build()?;

    // Run interactive session
    Launcher::new(Arc::new(agent)).run().await?;
    
    Ok(())
}

Cargo.toml

[dependencies]
adk-rust = { version = "2.0.0", features = ["ollama"] }
tokio = { version = "1", features = ["full"] }
dotenvy = "0.15"
anyhow = "1.0"

कॉन्फ़िगरेशन विकल्प

use adk_model::ollama::{OllamaModel, OllamaConfig};

let config = OllamaConfig::new("llama3.2")
    .with_base_url("http://localhost:11434")  // Custom server URL
    .with_temperature(0.7)                     // Creativity (0.0-1.0)
    .with_max_tokens(2048);                    // Max response length

let model = OllamaModel::new(config)?;

मॉडलआकारआवश्यक RAMइसके लिए सबसे अच्छा
llama3.2:3b3B4GBतेज़, सामान्य-उद्देश्य
llama3.1:8b8B8GBलोकप्रिय संतुलित मॉडल
qwen3.6:35b-a3b35B (3B active)24GBसर्वश्रेष्ठ एजेंटिक कोडिंग — 73.4% SWE-bench
qwen3.5variesvariesमजबूत बहुभाषी और कोडिंग
qwen3-coder:30b30B19GBटूल कॉलिंग के साथ कोड-केंद्रित
qwen2.5:7b7B8GBअच्छा टूल कॉलिंग, हल्का
mistral:7b7B8GBकोड और तर्क
mistral-nemo:12b12B12GBउन्नत मिस्ट्रल (128K संदर्भ)
deepseek-r1:14b14B16GBडिस्टिल्ड तर्क
deepseek-r1:32b32B32GBबड़ा तर्क मॉडल
gemma3:9b9B10GBगूगल का कुशल ओपन मॉडल
devstral:24b24B24GBकोडिंग के लिए अनुकूलित
codellama:13b13B16GBकोड जनरेशन
llama3.3:70b70B48GBउच्चतम गुणवत्ता

एक मॉडल चुनना

  • सीमित RAM (8GB)?llama3.2:3b
  • सर्वश्रेष्ठ एजेंटिक कोडिंग?qwen3.6:35b-a3b (24GB, MoE — केवल 3B सक्रिय)
  • टूल कॉलिंग की आवश्यकता है?qwen3.5 या qwen3-coder:30b
  • कोड लिख रहे हैं?devstral:24b या qwen3-coder:30b
  • तर्क की आवश्यकता है?deepseek-r1:14b या deepseek-r1:32b
  • सर्वोत्तम गुणवत्ता?llama3.3:70b (48GB+ RAM की आवश्यकता है)

Ollama के साथ टूल कॉलिंग

Ollama संगत मॉडलों के साथ फ़ंक्शन कॉलिंग का समर्थन करता है:

use adk_model::ollama::{OllamaModel, OllamaConfig};
use adk_agent::LlmAgentBuilder;
use adk_tool::FunctionTool;
use std::sync::Arc;

// qwen2.5 has excellent tool calling support
let model = OllamaModel::new(OllamaConfig::new("qwen2.5:7b"))?;

let weather_tool = Arc::new(FunctionTool::new(
    "get_weather",
    "Get weather for a location",
    |_ctx, args| async move {
        let location = args.get("location").and_then(|v| v.as_str()).unwrap_or("unknown");
        Ok(serde_json::json!({
            "location": location,
            "temperature": "72°F",
            "condition": "Sunny"
        }))
    },
));

let agent = LlmAgentBuilder::new("weather_assistant")
    .instruction("Help users check the weather.")
    .model(Arc::new(model))
    .tool(weather_tool)
    .build()?;

ध्यान दें: स्थानीय मॉडलों के साथ विश्वसनीयता के लिए टूल कॉलिंग नॉन-स्ट्रीमिंग मोड का उपयोग करती है।


उदाहरण आउटपुट

👤 User: Hello! What can you do?

🤖 Ollama (llama3.2): Hello! I'm a local AI assistant running on your 
machine. I can help with:
- Answering questions
- Writing and editing text
- Explaining concepts
- Basic coding help

All completely private - nothing leaves your computer!

समस्या निवारण

"कनेक्शन अस्वीकृत"

# Make sure Ollama is running
ollama serve

"मॉडल नहीं मिला"

# Pull the model first
ollama pull llama3.2

धीमी प्रतिक्रियाएँ

  • एक छोटे मॉडल का उपयोग करें (llama3.2 llama3.1:70b के बजाय)
  • RAM खाली करने के लिए अन्य एप्लिकेशन बंद करें
  • यदि उपलब्ध हो तो GPU त्वरण पर विचार करें

उपलब्ध मॉडल जांचें

ollama list

उदाहरण चलाना

cargo check -p adk-rust --no-default-features --features ollama

ollama serve चलाएँ और इस प्रदाता का उपयोग करने वाले एजेंट को शुरू करने से पहले मॉडल को पुल करें।



पिछला: ← मॉडल प्रदाता | अगला: स्थानीय मॉडल (mistral.rs) →

Ollama (स्थानीय मॉडल) - ADK-Rust दस्तावेज़ीकरण | ADK-Rust