Class: LightGptProxy::Provider
- Inherits:
-
Object
- Object
- LightGptProxy::Provider
- Defined in:
- lib/light_gpt_proxy/provider.rb
Instance Attribute Summary collapse
-
#endpoints ⇒ Object
readonly
Returns the value of attribute endpoints.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #find_endpoint(name) ⇒ Object
- #index ⇒ Object
-
#initialize(name:, config:) ⇒ Provider
constructor
A new instance of Provider.
- #perform_request(endpoint_name, payload = {}) ⇒ Object
Constructor Details
#initialize(name:, config:) ⇒ Provider
Returns a new instance of Provider.
9 10 11 12 13 14 15 |
# File 'lib/light_gpt_proxy/provider.rb', line 9 def initialize(name:, config:) @name = name @host = config['host'] @key = config['api_key'] @global_header_options = config['header_options'] || {} @endpoints = build_endpoints(config) end |
Instance Attribute Details
#endpoints ⇒ Object (readonly)
Returns the value of attribute endpoints.
7 8 9 |
# File 'lib/light_gpt_proxy/provider.rb', line 7 def endpoints @endpoints end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/light_gpt_proxy/provider.rb', line 7 def logger @logger end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/light_gpt_proxy/provider.rb', line 7 def name @name end |
Instance Method Details
#find_endpoint(name) ⇒ Object
36 |
# File 'lib/light_gpt_proxy/provider.rb', line 36 def find_endpoint(name) = endpoints.find { |ep| ep.name == name.to_s } |
#index ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/light_gpt_proxy/provider.rb', line 25 def index @endpoints.map do |endpoint| { name: endpoint.name, method: endpoint.method, path: endpoint.path, schema: endpoint.body_schema } end end |
#perform_request(endpoint_name, payload = {}) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/light_gpt_proxy/provider.rb', line 17 def perform_request(endpoint_name, payload = {}) endpoint = find_endpoint(endpoint_name) raise ArgumentError, "Endpoint '#{endpoint_name}' not found" unless endpoint validated_payload = endpoint.validate_and_apply_defaults(payload) if endpoint.body_schema endpoint.execute_request(validated_payload || payload) end |