Class: Apologist::Evaluators::Client
- Inherits:
-
Object
- Object
- Apologist::Evaluators::Client
- Defined in:
- lib/Apologist/evaluators/client.rb
Instance Method Summary collapse
-
#evaluate_content(request_options: {}, **params) ⇒ Apologist::Evaluators::Types::EvaluateContentResponse
Runs an evaluation on the provided content using the specified evaluator.
-
#get_evaluation(request_options: {}, **params) ⇒ Apologist::Evaluators::Types::GetEvaluationResponse
Returns a single evaluation for the evaluator, scoped to the requesting agent.
- #initialize(client:) ⇒ void constructor
-
#list_evaluations(request_options: {}, **params) ⇒ Apologist::Evaluators::Types::ListEvaluationsResponse
Returns a paginated list of evaluations for the evaluator, scoped to the requesting agent.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/Apologist/evaluators/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#evaluate_content(request_options: {}, **params) ⇒ Apologist::Evaluators::Types::EvaluateContentResponse
Runs an evaluation on the provided content using the specified evaluator
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/Apologist/evaluators/client.rb', line 95 def evaluate_content(request_options: {}, **params) params = Apologist::Internal::Types::Utils.normalize_keys(params) request_data = Apologist::Evaluators::Types::EvaluatorRequest.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: "evaluators/#{URI.encode_uri_component(params[:id].to_s)}/evaluations", body: body, 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::Evaluators::Types::EvaluateContentResponse.load(response.body) else error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#get_evaluation(request_options: {}, **params) ⇒ Apologist::Evaluators::Types::GetEvaluationResponse
Returns a single evaluation for the evaluator, scoped to the requesting agent.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/Apologist/evaluators/client.rb', line 141 def get_evaluation(request_options: {}, **params) params = Apologist::Internal::Types::Utils.normalize_keys(params) request = Apologist::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "evaluators/#{URI.encode_uri_component(params[:id].to_s)}/evaluations/#{URI.encode_uri_component(params[:evaluation_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::Evaluators::Types::GetEvaluationResponse.load(response.body) else error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list_evaluations(request_options: {}, **params) ⇒ Apologist::Evaluators::Types::ListEvaluationsResponse
Returns a paginated list of evaluations for the evaluator, scoped to the requesting agent.
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 75 |
# File 'lib/Apologist/evaluators/client.rb', line 40 def list_evaluations(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["benchmark"] = params[:benchmark] if params.key?(:benchmark) query_params["benchmark_run_id"] = params[:benchmark_run_id] if params.key?(:benchmark_run_id) query_params["benchmark_question_id"] = params[:benchmark_question_id] if params.key?(:benchmark_question_id) request = Apologist::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "evaluators/#{URI.encode_uri_component(params[:id].to_s)}/evaluations", 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::Evaluators::Types::ListEvaluationsResponse.load(response.body) else error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |