Class: RubyLLM::Connection
- Inherits:
-
Object
- Object
- RubyLLM::Connection
- Defined in:
- lib/ruby_llm/connection.rb
Overview
Connection class for managing API connections to various providers.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
Class Method Summary collapse
Instance Method Summary collapse
- #get(url) ⇒ Object
-
#initialize(provider, config) ⇒ Connection
constructor
A new instance of Connection.
- #instance_variables ⇒ Object
- #post(url, payload) ⇒ Object
Constructor Details
#initialize(provider, config) ⇒ Connection
Returns a new instance of Connection.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ruby_llm/connection.rb', line 27 def initialize(provider, config) @provider = provider @config = config ensure_configured! @connection ||= Faraday.new(provider.api_base) do |faraday| setup_timeout(faraday) setup_logging(faraday) setup_retry(faraday) setup_middleware(faraday) setup_http_proxy(faraday) end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/ruby_llm/connection.rb', line 12 def config @config end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
12 13 14 |
# File 'lib/ruby_llm/connection.rb', line 12 def connection @connection end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
12 13 14 |
# File 'lib/ruby_llm/connection.rb', line 12 def provider @provider end |
Class Method Details
Instance Method Details
#get(url) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/ruby_llm/connection.rb', line 50 def get(url, &) instrument_request(:get, url) do @connection.get url do |req| req.headers.merge! provider_headers yield req if block_given? end end end |
#instance_variables ⇒ Object
59 60 61 |
# File 'lib/ruby_llm/connection.rb', line 59 def instance_variables super - %i[@config @connection] end |
#post(url, payload) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/ruby_llm/connection.rb', line 41 def post(url, payload, &) instrument_request(:post, url) do @connection.post url, payload do |req| req.headers.merge! provider_headers yield req if block_given? end end end |