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.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby_llm/connection.rb', line 21 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.
6 7 8 |
# File 'lib/ruby_llm/connection.rb', line 6 def config @config end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
6 7 8 |
# File 'lib/ruby_llm/connection.rb', line 6 def connection @connection end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
6 7 8 |
# File 'lib/ruby_llm/connection.rb', line 6 def provider @provider end |
Class Method Details
Instance Method Details
#get(url) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/ruby_llm/connection.rb', line 42 def get(url, &) @connection.get url do |req| req.headers.merge! @provider.headers if @provider.respond_to?(:headers) yield req if block_given? end end |
#instance_variables ⇒ Object
49 50 51 |
# File 'lib/ruby_llm/connection.rb', line 49 def instance_variables super - %i[@config @connection] end |
#post(url, payload) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/ruby_llm/connection.rb', line 35 def post(url, payload, &) @connection.post url, payload do |req| req.headers.merge! @provider.headers if @provider.respond_to?(:headers) yield req if block_given? end end |