Class: ActiveAgent::GenerationProvider::OpenAIProvider
- Includes:
- MessageFormatting, StreamProcessing, ToolManagement
- Defined in:
- lib/active_agent/generation_provider/open_ai_provider.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Base
#access_token, #client, #config, #model_name, #prompt, #response
Instance Method Summary collapse
- #embed(prompt) ⇒ Object
- #generate(prompt) ⇒ Object
-
#initialize(config) ⇒ OpenAIProvider
constructor
A new instance of OpenAIProvider.
Methods included from ToolManagement
#format_tools, #handle_actions
Methods included from MessageFormatting
Methods included from StreamProcessing
Methods included from ParameterBuilder
Methods included from ErrorHandling
Constructor Details
#initialize(config) ⇒ OpenAIProvider
Returns a new instance of OpenAIProvider.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/active_agent/generation_provider/open_ai_provider.rb', line 22 def initialize(config) super @host = config["host"] || nil @access_token ||= config["api_key"] || config["access_token"] || OpenAI.configuration.access_token || ENV["OPENAI_ACCESS_TOKEN"] @organization_id = config["organization_id"] || OpenAI.configuration.organization_id || ENV["OPENAI_ORGANIZATION_ID"] @admin_token = config["admin_token"] || OpenAI.configuration.admin_token || ENV["OPENAI_ADMIN_TOKEN"] @client = OpenAI::Client.new( access_token: @access_token, uri_base: @host, organization_id: @organization_id, admin_token: @admin_token, log_errors: Rails.env.development? ) @model_name = config["model"] || "gpt-4o-mini" end |
Instance Method Details
#embed(prompt) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/active_agent/generation_provider/open_ai_provider.rb', line 51 def (prompt) @prompt = prompt with_error_handling do (parameters: ) end end |
#generate(prompt) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/active_agent/generation_provider/open_ai_provider.rb', line 39 def generate(prompt) @prompt = prompt with_error_handling do if @prompt.multimodal? || @prompt.content_type == "multipart/mixed" responses_prompt(parameters: responses_parameters) else chat_prompt(parameters: prompt_parameters) end end end |