Class: ActiveAgent::Providers::OpenAIProvider
- Inherits:
-
ActiveAgent::Providers::OpenAI::Base
- Object
- BaseProvider
- ActiveAgent::Providers::OpenAI::Base
- ActiveAgent::Providers::OpenAIProvider
- Defined in:
- lib/active_agent/providers/open_ai_provider.rb
Overview
Router for OpenAI’s API versions based on supported features.
This provider acts as a thin wrapper that routes requests between different versions of OpenAI’s API (Chat API and Responses API) depending on the features used in the prompt. It automatically selects the appropriate API version based on:
-
Explicit API version specification (
:api_versionoption) -
Presence of audio content in the request
Class Method Summary collapse
-
.embed_request_type ⇒ ActiveModel::Type::Value
Returns the embedding request type for OpenAI.
Instance Method Summary collapse
-
#initialize(kwargs = {}) ⇒ OpenAIProvider
constructor
Initializes the OpenAI provider router.
-
#preview ⇒ String
Generates a preview by routing to the appropriate OpenAI API version.
-
#prompt ⇒ Object
Generates a response by routing to the appropriate OpenAI API version.
Methods inherited from ActiveAgent::Providers::OpenAI::Base
Methods inherited from BaseProvider
#embed, namespace, options_klass, prompt_request_type, service_name, tag_name
Methods included from ToolChoiceClearing
Methods included from Previewable
Methods included from Instrumentation
#instrumentation_prompt_payload
Methods included from ExceptionHandler
#configure_exception_handler, #rescue_with_handler, #with_exception_handling
Constructor Details
#initialize(kwargs = {}) ⇒ OpenAIProvider
Initializes the OpenAI provider router.
Since this layer is just routing based on API version, we want to wait to cast values into their types.
44 45 46 47 48 49 50 |
# File 'lib/active_agent/providers/open_ai_provider.rb', line 44 def initialize(kwargs = {}) # For Routing Prompt APIs self.api_version = kwargs.delete(:api_version) self. = kwargs.deep_dup super end |
Class Method Details
.embed_request_type ⇒ ActiveModel::Type::Value
Returns the embedding request type for OpenAI.
29 30 31 |
# File 'lib/active_agent/providers/open_ai_provider.rb', line 29 def self. OpenAI::Embedding::RequestType.new end |
Instance Method Details
#preview ⇒ String
Generates a preview by routing to the appropriate OpenAI API version.
Routes to Chat API or Responses API using the same logic as #prompt.
75 76 77 78 79 80 81 |
# File 'lib/active_agent/providers/open_ai_provider.rb', line 75 def preview if api_version == :chat || context[:audio].present? OpenAI::ChatProvider.new().preview else # api_version == :responses || true OpenAI::ResponsesProvider.new().preview end end |
#prompt ⇒ Object
Generates a response by routing to the appropriate OpenAI API version.
This method determines which API version to use based on the prompt context:
-
Uses Chat API if api_version: :chat is specified or audio is present
-
Uses Responses API otherwise (default)
61 62 63 64 65 66 67 |
# File 'lib/active_agent/providers/open_ai_provider.rb', line 61 def prompt if api_version == :chat || context[:audio].present? OpenAI::ChatProvider.new().prompt else # api_version == :responses || true OpenAI::ResponsesProvider.new().prompt end end |