Module: Smith::Providers::OpenAI::Routing
- Defined in:
- lib/smith/providers/openai/routing.rb
Overview
Prepended onto RubyLLM::Providers::OpenAI. Intercepts the chat
complete call and routes to /v1/responses when the rendered
payload's openai_api_mode hint (set by the normalizer via
chat.with_params(openai_api_mode: :responses)) requests it.
Does NOT rename RubyLLM::Providers::OpenAI::Chat#completion_url
(PR #770 does; Smith diverges to keep the surface narrower).
The instance_of? check prevents routing on OpenAI-compatible
subclasses (OpenRouter, Azure, Bedrock).
The full /v1/responses payload assembly lives in
Smith::Providers::OpenAI::Responses (vendored from
crmne/ruby_llm PR #770 at SHA a84517db65d3774c6b129dc88032fe32c8dbc722).
When the PR merges upstream, Smith bumps the ruby_llm dep and
deletes the vendored files. The defined? guard in
route_via_responses keeps the routing safe even if a host pins
an older Smith without the vendored adapter, raising a clear
NotImplementedError rather than silently falling through to
chat-completions (which would still fail with the original
tools+reasoning combo error).
Instance Method Summary collapse
Instance Method Details
#complete(messages, tools:, temperature:, model:, params: {}, headers: {}, schema: nil, thinking: nil, tool_prefs: nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/smith/providers/openai/routing.rb', line 29 def complete(, tools:, temperature:, model:, params: {}, headers: {}, schema: nil, thinking: nil, tool_prefs: nil, &) mode = params[:openai_api_mode] || params["openai_api_mode"] if mode.to_s == "responses" && instance_of?(::RubyLLM::Providers::OpenAI) route_via_responses( , tools: tools, temperature: temperature, model: model, params: params.except(:openai_api_mode, "openai_api_mode"), headers: headers, schema: schema, thinking: thinking, tool_prefs: tool_prefs, & ) else super end end |