Class: LightGptProxy::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/light_gpt_proxy/provider.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#endpointsObject (readonly)

Returns the value of attribute endpoints.



7
8
9
# File 'lib/light_gpt_proxy/provider.rb', line 7

def endpoints
  @endpoints
end

#loggerObject (readonly)

Returns the value of attribute logger.



7
8
9
# File 'lib/light_gpt_proxy/provider.rb', line 7

def logger
  @logger
end

#nameObject (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 }

#indexObject



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

Raises:

  • (ArgumentError)


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