Class: RouterBase::Client
- Inherits:
-
Object
- Object
- RouterBase::Client
- Defined in:
- lib/routerbase/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
Instance Method Summary collapse
- #chat_completion(messages:, model: DEFAULT_MODEL, **options) ⇒ Object
-
#initialize(api_key: ENV["ROUTERBASE_API_KEY"], base_url: BASE_URL, transport: nil) ⇒ Client
constructor
A new instance of Client.
- #list_models ⇒ Object
Constructor Details
#initialize(api_key: ENV["ROUTERBASE_API_KEY"], base_url: BASE_URL, transport: nil) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 |
# File 'lib/routerbase/client.rb', line 11 def initialize(api_key: ENV["ROUTERBASE_API_KEY"], base_url: BASE_URL, transport: nil) raise ArgumentError, "RouterBase API key is required" if api_key.nil? || api_key.empty? @api_key = api_key @base_url = base_url.sub(%r{/+\z}, "") @transport = transport || NetHTTPTransport.new end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
9 10 11 |
# File 'lib/routerbase/client.rb', line 9 def api_key @api_key end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
9 10 11 |
# File 'lib/routerbase/client.rb', line 9 def base_url @base_url end |
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
9 10 11 |
# File 'lib/routerbase/client.rb', line 9 def transport @transport end |
Instance Method Details
#chat_completion(messages:, model: DEFAULT_MODEL, **options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/routerbase/client.rb', line 19 def chat_completion(messages:, model: DEFAULT_MODEL, **) raise ArgumentError, "messages must be a non-empty array" if .nil? || .empty? post_json( "/chat/completions", { model: model, messages: }.merge() ) end |
#list_models ⇒ Object
31 32 33 |
# File 'lib/routerbase/client.rb', line 31 def list_models request_json(:get, "/models") end |