Skip to content

Commit c99ff3a

Browse files
committed
Refactor connection setup to use Connection.basic for Parsera API
1 parent 5622d3d commit c99ff3a

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

lib/ruby_llm/connection.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ module RubyLLM
55
class Connection
66
attr_reader :provider, :connection, :config
77

8-
def self.basic
9-
Faraday.new do |faraday|
10-
faraday.response :logger,
11-
RubyLLM.logger,
12-
bodies: false,
13-
response: false,
14-
errors: true,
15-
headers: false,
16-
log_level: :debug
17-
faraday.use Faraday::Response::RaiseError
8+
def self.basic(&)
9+
Faraday.new do |f|
10+
f.response :logger,
11+
RubyLLM.logger,
12+
bodies: false,
13+
response: false,
14+
errors: true,
15+
headers: false,
16+
log_level: :debug
17+
f.response :raise_error
18+
yield f if block_given?
1819
end
1920
end
2021

lib/ruby_llm/models.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,11 @@ def respond_to_missing?(method, include_private = false)
8585
def fetch_from_parsera
8686
RubyLLM.logger.info 'Fetching models from Parsera API...'
8787

88-
connection = Faraday.new('https://api.parsera.org') do |f|
88+
connection = Connection.basic do |f|
8989
f.request :json
9090
f.response :json, parser_options: { symbolize_names: true }
91-
f.response :raise_error
92-
f.adapter Faraday.default_adapter
9391
end
94-
95-
response = connection.get('/v1/llm-specs')
92+
response = connection.get 'https://api.parsera.org/v1/llm-specs'
9693
response.body.map { |data| Model::Info.new(data) }
9794
end
9895

0 commit comments

Comments
 (0)