Class: CompletionKit::ResponseQuery

Inherits:
Object
  • Object
show all
Defined in:
app/services/completion_kit/response_query.rb

Overview

Filtering, score-ordering and field projection for a run's responses, shared by the REST endpoint and the MCP tool so both surfaces answer "show me the worst rows, without the full bodies" the same way.

Constant Summary collapse

SORTS =
%w[id score_asc score_desc].freeze
REVIEW_FIELD_PREFIX =
"reviews.".freeze

Instance Method Summary collapse

Constructor Details

#initialize(run, status: nil, min_score: nil, max_score: nil, sort: nil, fields: nil) ⇒ ResponseQuery

Returns a new instance of ResponseQuery.



9
10
11
12
13
14
15
16
# File 'app/services/completion_kit/response_query.rb', line 9

def initialize(run, status: nil, min_score: nil, max_score: nil, sort: nil, fields: nil)
  @run = run
  @status = status.presence
  @min_score = min_score.presence&.to_f
  @max_score = max_score.presence&.to_f
  @sort = SORTS.include?(sort.to_s) ? sort.to_s : "id"
  @fields = parse_fields(fields)
end

Instance Method Details

#relationObject



18
19
20
21
22
23
# File 'app/services/completion_kit/response_query.rb', line 18

def relation
  return base.order(:id) unless score_scoped?

  ids = ordered_ids
  base.where(id: ids).in_order_of(:id, ids)
end

#serialize(response) ⇒ Object



25
26
27
# File 'app/services/completion_kit/response_query.rb', line 25

def serialize(response)
  project(response.as_json)
end