ScavioScavio
ProductoPreciosDocumentación
Iniciar sesionComenzar
  1. Inicio
  2. Tutoriales
  3. Cómo agregar búsqueda web a un modelo de llama local
Tutorial

Cómo agregar búsqueda web a un modelo de llama local

Conecte un modelo Llama local que se ejecute en Ollama o webui de generación de texto a una API de búsqueda en vivo. Muestra la configuración de llamadas a funciones y la integración de herramientas en Python.

Obtener clave API gratisDocumentacion API

Puede agregar búsqueda web a un modelo Llama local definiendo una función de búsqueda como herramienta y llamando a la API de búsqueda de Scavio cuando el modelo decida usarla. Esto funciona con el punto final compatible con OpenAI de Ollama y cualquier marco que admita la llamada a herramientas.

Requisitos previos

  • Ollama con llama3.2 o llama3.3 instalado
  • Python 3.9+
  • Openai SDK de Python
  • Clave API de Scavio

Guia paso a paso

Paso 1: Inicie Ollama y verifique el soporte de la herramienta

Llama 3.2 y versiones posteriores admiten llamadas a funciones. Ejecute una prueba rápida para confirmar.

Bash
# Pull and start the model
ollama pull llama3.3
ollama serve

# Verify the OpenAI-compatible endpoint
curl http://localhost:11434/v1/models

Paso 2: Definir el esquema de la herramienta de búsqueda

Las herramientas se definen como esquemas JSON. Esto le dice a Llama cuándo y cómo llamar a la función de búsqueda.

Python
SEARCH_TOOL = {
    "type": "function",
    "function": {
        "name": "web_search",
        "description": "Search the web for current information. Use this when you need up-to-date facts, prices, or news.",
        "parameters": {
            "type": "object",
            "properties": {
                "query": {
                    "type": "string",
                    "description": "The search query"
                },
                "platform": {
                    "type": "string",
                    "enum": ["google", "amazon", "reddit", "youtube"],
                    "description": "Search platform. Defaults to google."
                }
            },
            "required": ["query"]
        }
    }
}

Paso 3: Implementar el ejecutor de herramientas

Cuando Llama llame a la herramienta, ejecute la solicitud API real y devuelva el resultado.

Python
import json
import requests
from openai import OpenAI

SCAVIO_KEY = "your-scavio-api-key"

def execute_web_search(query: str, platform: str = "google") -> str:
    r = requests.post(
        "https://api.scavio.dev/api/v1/search",
        json={"query": query, "platform": platform, "num_results": 5},
        headers={"x-api-key": SCAVIO_KEY},
        timeout=15
    )
    r.raise_for_status()
    results = r.json().get("organic_results", [])
    lines = [f"- {res['title']}: {res.get('snippet', '')}" for res in results[:5]]
    return "\n".join(lines) or "No results found."

Paso 4: Ejecute el bucle de llamada de herramientas

Envíe el mensaje del usuario con herramientas, verifique si Llama quiere llamar a una herramienta, ejecútela y envíe el resultado.

Python
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")

def chat_with_search(user_message: str) -> str:
    messages = [{"role": "user", "content": user_message}]

    response = client.chat.completions.create(
        model="llama3.3",
        messages=messages,
        tools=[SEARCH_TOOL],
        tool_choice="auto"
    )
    choice = response.choices[0]

    if choice.finish_reason == "tool_calls":
        tool_call = choice.message.tool_calls[0]
        args = json.loads(tool_call.function.arguments)
        search_result = execute_web_search(**args)

        messages.append(choice.message)
        messages.append({
            "role": "tool",
            "tool_call_id": tool_call.id,
            "content": search_result
        })

        final = client.chat.completions.create(
            model="llama3.3",
            messages=messages
        )
        return final.choices[0].message.content

    return choice.message.content

print(chat_with_search("What are the current prices for Anthropic Claude API in 2026?"))

Ejemplo en Python

Python
import json
import requests
from openai import OpenAI

SCAVIO_KEY = "your-scavio-api-key"

SEARCH_TOOL = {
    "type": "function",
    "function": {
        "name": "web_search",
        "description": "Search the web for current information, prices, news, or product data.",
        "parameters": {
            "type": "object",
            "properties": {
                "query": {"type": "string", "description": "Search query"},
                "platform": {"type": "string", "enum": ["google", "amazon", "reddit", "youtube"], "description": "Platform to search"}
            },
            "required": ["query"]
        }
    }
}

def web_search(query: str, platform: str = "google") -> str:
    r = requests.post(
        "https://api.scavio.dev/api/v1/search",
        json={"query": query, "platform": platform, "num_results": 5},
        headers={"x-api-key": SCAVIO_KEY},
        timeout=15
    )
    r.raise_for_status()
    items = r.json().get("organic_results", [])
    return "\n".join(f"- {it['title']}: {it.get('snippet','')}" for it in items[:5]) or "No results."

client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")

def chat(user_message: str) -> str:
    messages = [{"role": "user", "content": user_message}]
    resp = client.chat.completions.create(model="llama3.3", messages=messages, tools=[SEARCH_TOOL], tool_choice="auto")
    choice = resp.choices[0]

    if choice.finish_reason == "tool_calls":
        tc = choice.message.tool_calls[0]
        args = json.loads(tc.function.arguments)
        result = web_search(**args)
        messages += [choice.message, {"role": "tool", "tool_call_id": tc.id, "content": result}]
        final = client.chat.completions.create(model="llama3.3", messages=messages)
        return final.choices[0].message.content

    return choice.message.content

if __name__ == "__main__":
    questions = [
        "What is the price of Claude Sonnet per million tokens in 2026?",
        "What are people saying on Reddit about local LLMs vs cloud APIs?"
    ]
    for q in questions:
        print(f"Q: {q}")
        print(f"A: {chat(q)}\n")

Ejemplo en JavaScript

JavaScript
// Using Ollama's OpenAI-compatible endpoint with the openai npm package
import OpenAI from 'openai';

const SCAVIO_KEY = 'your-scavio-api-key';
const client = new OpenAI({ baseURL: 'http://localhost:11434/v1', apiKey: 'ollama' });

const SEARCH_TOOL = {
  type: 'function',
  function: {
    name: 'web_search',
    description: 'Search the web for current information.',
    parameters: {
      type: 'object',
      properties: {
        query: { type: 'string' },
        platform: { type: 'string', enum: ['google', 'amazon', 'reddit', 'youtube'] }
      },
      required: ['query']
    }
  }
};

async function webSearch(query, platform = 'google') {
  const res = await fetch('https://api.scavio.dev/api/v1/search', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json', 'x-api-key': SCAVIO_KEY },
    body: JSON.stringify({ query, platform, num_results: 5 })
  });
  const data = await res.json();
  return (data.organic_results ?? []).map(r => `- ${r.title}: ${r.snippet ?? ''}`).join('\n') || 'No results.';
}

async function chat(userMessage) {
  const messages = [{ role: 'user', content: userMessage }];
  const resp = await client.chat.completions.create({ model: 'llama3.3', messages, tools: [SEARCH_TOOL], tool_choice: 'auto' });
  const choice = resp.choices[0];

  if (choice.finish_reason === 'tool_calls') {
    const tc = choice.message.tool_calls[0];
    const args = JSON.parse(tc.function.arguments);
    const result = await webSearch(args.query, args.platform);
    messages.push(choice.message, { role: 'tool', tool_call_id: tc.id, content: result });
    const final = await client.chat.completions.create({ model: 'llama3.3', messages });
    return final.choices[0].message.content;
  }
  return choice.message.content;
}

console.log(await chat('What does Claude Sonnet cost per million tokens in 2026?'));

Salida esperada

JSON
Q: What is the price of Claude Sonnet per million tokens in 2026?
A: Based on current search results, Claude Sonnet is priced at $3 per million input tokens and $15 per million output tokens as of early 2026.

Q: What are people saying on Reddit about local LLMs vs cloud APIs?
A: Reddit discussions show a split: developers prefer local LLMs for privacy and cost control, while teams favor cloud APIs for reliability and model quality.

Tutoriales relacionados

  • Cómo conectar OpenWebUI a una API de búsqueda
  • Cómo configurar RAG con búsqueda en lugar de vectores
  • Cómo crear un agente de investigación de fuentes múltiples

Preguntas frecuentes

La mayoria de los desarrolladores completan este tutorial en 15 a 30 minutos. Necesitaras una clave API de Scavio (el plan gratuito funciona) y un entorno de Python o JavaScript.

Ollama con llama3.2 o llama3.3 instalado. Python 3.9+. Openai SDK de Python. Clave API de Scavio. Una clave API de Scavio te da 50 creditos gratuitos al registrarte.

Si. El plan gratuito incluye 50 creditos al registrarte, mas que suficiente para completar este tutorial y crear un prototipo funcional.

Scavio tiene un paquete nativo de LangChain (langchain-scavio), un servidor MCP y una API REST simple que funciona con cualquier cliente HTTP. Este tutorial usa the raw REST API, pero puedes adaptarlo al framework que prefieras.

Recursos relacionados

Use Case

Búsqueda web de agentes para LLM local

Read more
Best Of

La mejor API de búsqueda web para LLM locales en 2026

Read more
Best Of

Las mejores API para pilas de herramientas de investigación locales en 2026

Read more
Solution

Búsqueda local de LLM después de Google Paywall

Read more
Use Case

Base de búsqueda web local de LLM

Read more
Solution

Conexión a tierra web para LLM locales

Read more

Empieza a construir

Conecte un modelo Llama local que se ejecute en Ollama o webui de generación de texto a una API de búsqueda en vivo. Muestra la configuración de llamadas a funciones y la integración de herramientas en Python.

Obtener clave API gratuitaLeer la documentacion
ScavioScavio

API de busqueda en tiempo real para agentes de IA. Busca en todas las plataformas, no solo en Google.

Producto

  • Funciones
  • Precios
  • Panel
  • Afiliados

Desarrolladores

  • Documentacion
  • Referencia de API
  • Inicio rapido
  • Integracion MCP
  • Python SDK

Alternativas

  • Alternativa a Tavily
  • Alternativa a SerpAPI
  • Alternativa a Firecrawl
  • Alternativa a Exa

Herramientas

  • Formateador JSON
  • cURL a codigo
  • Contador de tokens
  • Todas las herramientas

© 2026 Scavio. Todos los derechos reservados.

Featured on TAAFT
Terminos de servicioPolitica de privacidad