Class: OmniAgent::Providers::Base
- Inherits:
-
Object
- Object
- OmniAgent::Providers::Base
- Defined in:
- lib/omni_agent/providers/base.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #chat(messages:, tools: [], **_options) ⇒ Object
-
#initialize(api_key: nil, model: nil) ⇒ Base
constructor
A new instance of Base.
- #validate_messages!(messages, allowed_roles:) ⇒ Object
Constructor Details
#initialize(api_key: nil, model: nil) ⇒ Base
Returns a new instance of Base.
7 8 9 10 |
# File 'lib/omni_agent/providers/base.rb', line 7 def initialize(api_key: nil, model: nil) @api_key = api_key || default_api_key @model = model || default_model end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/omni_agent/providers/base.rb', line 5 def model @model end |
Instance Method Details
#chat(messages:, tools: [], **_options) ⇒ Object
12 13 14 |
# File 'lib/omni_agent/providers/base.rb', line 12 def chat(messages:, tools: [], **) raise NotImplementedError, "Providers must implement #chat" end |
#validate_messages!(messages, allowed_roles:) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/omni_agent/providers/base.rb', line 16 def (, allowed_roles:) unless .is_a?(Array) raise OmniAgent::Error, "messages must be an array" end normalized_roles = Array(allowed_roles).map(&:to_s) .each_with_index do |, index| unless .is_a?(Hash) raise OmniAgent::Error, "message at index #{index} must be a hash" end role = [:role] || ["role"] if role.nil? raise OmniAgent::Error, "message at index #{index} is missing role" end role_name = role.to_s unless normalized_roles.include?(role_name) raise OmniAgent::Error, "invalid message role '#{role_name}' at index #{index}" end (, index, role_name) end end |