Class: Apologist::Benchmarks::Client
- Inherits:
-
Object
- Object
- Apologist::Benchmarks::Client
- Defined in:
- lib/Apologist/benchmarks/client.rb
Instance Method Summary collapse
-
#get_benchmark_run(request_options: {}, **params) ⇒ Apologist::Benchmarks::Types::GetBenchmarkRunResponse
Returns a single benchmark run by id or UUID, scoped to the requesting agent, including nested evaluators, questions, and evaluations.
- #initialize(client:) ⇒ void constructor
-
#list_benchmark_runs(request_options: {}, **params) ⇒ Apologist::Benchmarks::Types::ListBenchmarkRunsResponse
Returns a paginated list of runs for a benchmark, scoped to the requesting agent.
-
#run_benchmark(request_options: {}, **params) ⇒ Hash[String, Object]
Executes a benchmark run and returns the aggregated result with nested evaluators, questions, and a flat evaluations array.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/Apologist/benchmarks/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#get_benchmark_run(request_options: {}, **params) ⇒ Apologist::Benchmarks::Types::GetBenchmarkRunResponse
Returns a single benchmark run by id or UUID, scoped to the requesting agent, including nested evaluators, questions, and evaluations.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/Apologist/benchmarks/client.rb', line 137 def get_benchmark_run(request_options: {}, **params) params = Apologist::Internal::Types::Utils.normalize_keys(params) request = Apologist::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "benchmarks/#{URI.encode_uri_component(params[:id].to_s)}/runs/#{URI.encode_uri_component(params[:run_id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Apologist::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Apologist::Benchmarks::Types::GetBenchmarkRunResponse.load(response.body) else error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list_benchmark_runs(request_options: {}, **params) ⇒ Apologist::Benchmarks::Types::ListBenchmarkRunsResponse
Returns a paginated list of runs for a benchmark, scoped to the requesting agent. Each run carries nested evaluators, questions, and a flat evaluations array.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/Apologist/benchmarks/client.rb', line 40 def list_benchmark_runs(request_options: {}, **params) params = Apologist::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["page"] = params[:page] if params.key?(:page) query_params["per_page"] = params[:per_page] if params.key?(:per_page) query_params["min_timestamp"] = params[:min_timestamp] if params.key?(:min_timestamp) query_params["max_timestamp"] = params[:max_timestamp] if params.key?(:max_timestamp) query_params["min_duration"] = params[:min_duration] if params.key?(:min_duration) query_params["max_duration"] = params[:max_duration] if params.key?(:max_duration) query_params["min_score"] = params[:min_score] if params.key?(:min_score) query_params["max_score"] = params[:max_score] if params.key?(:max_score) query_params["passed"] = params[:passed] if params.key?(:passed) query_params["min_responses"] = params[:min_responses] if params.key?(:min_responses) query_params["max_responses"] = params[:max_responses] if params.key?(:max_responses) request = Apologist::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "benchmarks/#{URI.encode_uri_component(params[:id].to_s)}/runs", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Apologist::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Apologist::Benchmarks::Types::ListBenchmarkRunsResponse.load(response.body) else error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#run_benchmark(request_options: {}, **params) ⇒ Hash[String, Object]
Executes a benchmark run and returns the aggregated result with nested evaluators, questions, and a flat evaluations array.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/Apologist/benchmarks/client.rb', line 92 def run_benchmark(request_options: {}, **params) params = Apologist::Internal::Types::Utils.normalize_keys(params) request_data = Apologist::Benchmarks::Types::BenchmarkRunRequest.new(params).to_h non_body_param_names = %w[id] body = request_data.except(*non_body_param_names) request = Apologist::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "benchmarks/#{URI.encode_uri_component(params[:id].to_s)}/runs", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Apologist::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |