Module: RubyPi::LLM

Defined in:
lib/ruby_pi.rb,
lib/ruby_pi/llm/model.rb,
lib/ruby_pi/llm/gemini.rb,
lib/ruby_pi/llm/openai.rb,
lib/ruby_pi/llm/fallback.rb,
lib/ruby_pi/llm/response.rb,
lib/ruby_pi/llm/anthropic.rb,
lib/ruby_pi/llm/tool_call.rb,
lib/ruby_pi/llm/stream_event.rb,
lib/ruby_pi/llm/base_provider.rb

Overview

Namespace for large language model providers and related abstractions.

Defined Under Namespace

Classes: Anthropic, BaseProvider, Fallback, Gemini, Model, OpenAI, Response, StreamEvent, ToolCall

Class Method Summary collapse

Class Method Details

.model(provider, name, **options) ⇒ RubyPi::LLM::BaseProvider

Factory method for constructing a provider instance from a provider name and model identifier.

Examples:

Build a Gemini model

model = RubyPi::LLM.model(:gemini, "gemini-2.0-flash")

Parameters:

  • provider (Symbol, String)

    provider identifier (:gemini, :anthropic, :openai)

  • name (String)

    the model name to use with the provider

  • options (Hash)

    provider-specific initialization options

Returns:

Raises:

  • (ArgumentError)

    if the provider is unsupported



98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/ruby_pi.rb', line 98

def model(provider, name, **options)
  case provider.to_sym
  when :gemini
    Gemini.new(model: name, **options)
  when :anthropic
    Anthropic.new(model: name, **options)
  when :openai
    OpenAI.new(model: name, **options)
  else
    raise ArgumentError, "Unsupported provider: #{provider}"
  end
end