Class: Legate::LLM::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/legate/llm/adapter.rb

Overview

Abstract base for LLM provider adapters.

Direct Known Subclasses

Gemini, Ollama

Instance Method Summary collapse

Instance Method Details

#available?Boolean

Returns whether the adapter can make calls (e.g. an API key is present and the client constructed successfully).

Returns:

  • (Boolean)

    whether the adapter can make calls (e.g. an API key is present and the client constructed successfully).



14
15
16
# File 'lib/legate/llm/adapter.rb', line 14

def available?
  false
end

#generate(prompt, json: false, schema: nil) ⇒ String?

Generates a text completion for a single user prompt.

Parameters:

  • prompt (String)

    the user prompt

  • json (Boolean) (defaults to: false)

    request raw-JSON output where the provider supports it

  • schema (Hash, nil) (defaults to: nil)

    an optional response schema (provider-native structured output) to constrain the JSON shape. Ignored by adapters that don’t support it; see #supports_structured_output?.

Returns:

  • (String, nil)

    the model’s text output, or nil if unavailable

Raises:

  • (StandardError)

    on a non-retryable provider error



32
33
34
# File 'lib/legate/llm/adapter.rb', line 32

def generate(prompt, json: false, schema: nil)
  raise NotImplementedError, "#{self.class} must implement #generate"
end

#generate_with_tools(prompt, tools:) ⇒ Hash

Chooses the next action with the given tool schemas available to the model, using native function calling. Only meaningful when #supports_function_calling? is true.

Parameters:

  • prompt (String)

    instructions + context + observation transcript

  • tools (Array<Hash>)

    each { name:, description:, parameters: <JSON Schema> }

Returns:

  • (Hash)

    a provider-neutral choice, one of:

    • ‘{ kind: :tool, name: String, arguments: Hash, thought: String }`

    • ‘{ kind: :final, text: String, thought: String }`

Raises:

  • (StandardError)

    on a non-retryable provider error



64
65
66
# File 'lib/legate/llm/adapter.rb', line 64

def generate_with_tools(prompt, tools:)
  raise NotImplementedError, "#{self.class} must implement #generate_with_tools"
end

#model_nameString?

The resolved model identifier, or nil if the adapter is unavailable.

Returns:

  • (String, nil)


20
21
22
# File 'lib/legate/llm/adapter.rb', line 20

def model_name
  nil
end

#supports_function_calling?Boolean

Whether this adapter can use the provider’s native function/tool-calling API. When true, the agentic loop selects its next action via #generate_with_tools (structured, reliable) instead of parsing JSON out of prose; when false it falls back to the JSON-prompt path. Default false.

Returns:

  • (Boolean)


50
51
52
# File 'lib/legate/llm/adapter.rb', line 50

def supports_function_calling?
  false
end

#supports_structured_output?Boolean

Whether this adapter can constrain output to a schema (structured output) via the ‘schema:` argument to #generate. When true, the planner uses it to guarantee valid plan JSON instead of parsing it out of prose. Default false (the prompt-and-parse path).

Returns:

  • (Boolean)


41
42
43
# File 'lib/legate/llm/adapter.rb', line 41

def supports_structured_output?
  false
end