Module: Ollama::Client::WebSearch

Defined in:
lib/ollama/client/web_search.rb

Overview

Ollama Cloud web search & fetch endpoints.

Both require an Ollama Cloud API key (config.api_key / OLLAMA_API_KEY) and a client configured against the cloud host, e.g.:

config.base_url = "https://ollama.com"

Instance Method Summary collapse

Instance Method Details

#web_fetch(url:) ⇒ Hash

Fetch and extract content from a URL via Ollama Cloud.

Parameters:

  • url (String)

    URL to fetch (required)

Returns:

  • (Hash)

    "title", "content", "links"



31
32
33
34
35
36
# File 'lib/ollama/client/web_search.rb', line 31

def web_fetch(url:)
  res = execute_management_request("/api/web_fetch", body: { url: url })
  JSON.parse(res.body)
rescue JSON::ParserError => e
  raise InvalidJSONError, "Failed to parse web_fetch response: #{e.message}"
end

#web_search(query:, max_results: nil) ⇒ Array<Hash>

Search the web via Ollama Cloud.

Parameters:

  • query (String)

    Search query (required)

  • max_results (Integer, nil) (defaults to: nil)

    Max results to return (server default 5, max 10)

Returns:

  • (Array<Hash>)

    Results, each with "title", "url", "content"



18
19
20
21
22
23
24
25
# File 'lib/ollama/client/web_search.rb', line 18

def web_search(query:, max_results: nil)
  body = { query: query }
  body[:max_results] = max_results if max_results
  res = execute_management_request("/api/web_search", body: body)
  JSON.parse(res.body)["results"] || []
rescue JSON::ParserError => e
  raise InvalidJSONError, "Failed to parse web_search response: #{e.message}"
end