Class: PlatformSdk::LlmGateway::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/platform_sdk/llm_gateway/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_url:, api_key:, timeout: 30, conn: nil) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/platform_sdk/llm_gateway/client.rb', line 6

def initialize(base_url:, api_key:, timeout: 30, conn: nil)
  @connection = conn || Faraday.new(url: base_url) do |f|
    f.request :json
    f.request :retry, max: 2, interval: 0.5, backoff_factor: 2,
                      exceptions: [Faraday::TimeoutError, Faraday::ConnectionFailed]
    f.response :json
    f.adapter Faraday.default_adapter
    f.headers["Authorization"] = "Bearer #{api_key}"
    f.options.timeout = timeout
    f.options.open_timeout = timeout
  end
end

Instance Method Details

#score_response(question_content:, grading_rubric:, max_score:, min_score:, student_response:) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/platform_sdk/llm_gateway/client.rb', line 19

def score_response(question_content:, grading_rubric:, max_score:, min_score:, student_response:)
  response = @connection.post("assessments/grade") do |req|
    req.body = {
      question_content:,
      grading_rubric:,
      max_score:,
      min_score:,
      student_response:
    }
  end

  handle_response(response)
rescue Faraday::TimeoutError => e
  raise NetworkError, "Request timeout: #{e.message}"
rescue Faraday::ConnectionFailed => e
  raise NetworkError, "Connection failed: #{e.message}"
end