Class: Ace::LLM::Organisms::OpenRouterClient
- Inherits:
-
BaseClient
- Object
- BaseClient
- Ace::LLM::Organisms::OpenRouterClient
- Includes:
- Molecules::OpenAICompatibleParams
- Defined in:
- lib/ace/llm/organisms/openrouter_client.rb
Overview
OpenRouterClient handles interactions with OpenRouter’s API OpenRouter provides unified access to 400+ models through OpenAI-compatible API
Constant Summary collapse
- API_BASE_URL =
"https://openrouter.ai/api/v1"- DEFAULT_MODEL =
"openai/gpt-oss-120b:nitro"- GENERATION_KEYS =
Generation parameters to include in API request
%i[temperature max_tokens top_p frequency_penalty presence_penalty].freeze
Constants inherited from BaseClient
BaseClient::DEFAULT_GENERATION_CONFIG, BaseClient::DEFAULT_SYSTEM_PROMPT_SEPARATOR
Instance Attribute Summary
Attributes inherited from BaseClient
#api_key, #base_url, #generation_config, #http_client, #model
Class Method Summary collapse
-
.provider_name ⇒ String
Get the provider name.
Instance Method Summary collapse
-
#generate(messages, **options) ⇒ Hash
Generate a response from OpenRouter.
-
#initialize(api_key: nil, model: nil, referer: nil, title: nil, **options) ⇒ OpenRouterClient
constructor
Initialize the client.
Methods included from Molecules::OpenAICompatibleParams
#extract_openai_compatible_options
Methods inherited from BaseClient
#needs_credentials?, #provider_name
Constructor Details
#initialize(api_key: nil, model: nil, referer: nil, title: nil, **options) ⇒ OpenRouterClient
Initialize the client
34 35 36 37 38 39 |
# File 'lib/ace/llm/organisms/openrouter_client.rb', line 34 def initialize(api_key: nil, model: nil, referer: nil, title: nil, **) # Store attribution headers separately for explicit dependencies @referer = referer @title = title super(api_key: api_key, model: model, **) end |
Class Method Details
.provider_name ⇒ String
Get the provider name
22 23 24 |
# File 'lib/ace/llm/organisms/openrouter_client.rb', line 22 def self.provider_name "openrouter" end |
Instance Method Details
#generate(messages, **options) ⇒ Hash
Generate a response from OpenRouter
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ace/llm/organisms/openrouter_client.rb', line 45 def generate(, **) = () generation_params = () request_body = build_request_body(, generation_params) response = make_api_request(request_body) parse_response(response) rescue => e # Intentionally catch StandardError to wrap all API/network errors # as ProviderError for consistent error handling upstream handle_api_error(e) end |