Module: LlmGateway

Defined in:
lib/llm_gateway.rb,
lib/llm_gateway/tool.rb,
lib/llm_gateway/utils.rb,
lib/llm_gateway/client.rb,
lib/llm_gateway/errors.rb,
lib/llm_gateway/prompt.rb,
lib/llm_gateway/version.rb,
lib/llm_gateway/base_client.rb,
lib/llm_gateway/clients/groq.rb,
lib/llm_gateway/clients/openai.rb,
lib/llm_gateway/adapters/adapter.rb,
lib/llm_gateway/clients/anthropic.rb,
lib/llm_gateway/provider_registry.rb,
lib/llm_gateway/adapters/option_mapper.rb,
lib/llm_gateway/adapters/stream_mapper.rb,
lib/llm_gateway/adapters/groq/input_mapper.rb,
lib/llm_gateway/adapters/groq/option_mapper.rb,
lib/llm_gateway/clients/claude_code/oauth_flow.rb,
lib/llm_gateway/adapters/anthropic/input_mapper.rb,
lib/llm_gateway/clients/openai_codex/oauth_flow.rb,
lib/llm_gateway/adapters/anthropic/output_mapper.rb,
lib/llm_gateway/adapters/anthropic/stream_mapper.rb,
lib/llm_gateway/adapters/anthropic_option_mapper.rb,
lib/llm_gateway/adapters/input_message_sanitizer.rb,
lib/llm_gateway/adapters/openai/responses_adapter.rb,
lib/llm_gateway/clients/claude_code/token_manager.rb,
lib/llm_gateway/adapters/openai/file_output_mapper.rb,
lib/llm_gateway/adapters/openai_codex/input_mapper.rb,
lib/llm_gateway/clients/openai_codex/token_manager.rb,
lib/llm_gateway/adapters/anthropic/messages_adapter.rb,
lib/llm_gateway/adapters/openai/acts_like_responses.rb,
lib/llm_gateway/adapters/openai_codex/option_mapper.rb,
lib/llm_gateway/adapters/anthropic/acts_like_messages.rb,
lib/llm_gateway/adapters/groq/chat_completions_adapter.rb,
lib/llm_gateway/adapters/normalized_stream_accumulator.rb,
lib/llm_gateway/adapters/openai/responses/input_mapper.rb,
lib/llm_gateway/adapters/openai/responses/option_mapper.rb,
lib/llm_gateway/adapters/openai/responses/stream_mapper.rb,
lib/llm_gateway/adapters/openai_codex/responses_adapter.rb,
lib/llm_gateway/adapters/openai/chat_completions_adapter.rb,
lib/llm_gateway/adapters/openai/acts_like_chat_completions.rb,
lib/llm_gateway/adapters/openai/prompt_cache_option_mapper.rb,
lib/llm_gateway/adapters/openai/chat_completions/input_mapper.rb,
lib/llm_gateway/adapters/openai/chat_completions/option_mapper.rb,
lib/llm_gateway/adapters/openai/chat_completions/stream_mapper.rb,
lib/llm_gateway/adapters/openai/chat_completions/input_message_sanitizer.rb

Defined Under Namespace

Modules: Adapters, Clients, Errors, Utils Classes: BaseClient, Client, Error, Prompt, ProviderRegistry, Tool

Constant Summary collapse

VERSION =
"0.5.0"

Class Method Summary collapse

Class Method Details

.build_provider(config) ⇒ Object



100
101
102
103
104
105
106
107
# File 'lib/llm_gateway.rb', line 100

def self.build_provider(config)
  config = config.transform_keys(&:to_sym)
  provider_name = config.delete(:provider)
  entry = ProviderRegistry.resolve(provider_name)

  client = entry[:client].new(**config)
  entry[:adapter].new(client)
end

.configure(configs) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/llm_gateway.rb', line 109

def self.configure(configs)
  @configured_clients ||= {}

  configs.each do |entry|
    name = entry[:name] || entry["name"]
    config = entry[:config] || entry["config"]

    raise ArgumentError, "Each config entry must have a :name" unless name

    client = build_provider(config)
    @configured_clients[name.to_sym] = client

    define_singleton_method(name.to_sym) { @configured_clients[name.to_sym] }
  end
end

.configured_clientsObject



125
126
127
# File 'lib/llm_gateway.rb', line 125

def self.configured_clients
  @configured_clients ||= {}
end

.reset_configuration!Object



129
130
131
132
133
134
# File 'lib/llm_gateway.rb', line 129

def self.reset_configuration!
  @configured_clients&.each_key do |name|
    singleton_class.remove_method(name) if respond_to?(name)
  end
  @configured_clients = {}
end