Class: CompletionKit::Api::V1::RunsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/completion_kit/api/v1/runs_controller.rb

Instance Method Summary collapse

Instance Method Details

#compareObject



78
79
80
81
82
83
84
# File 'app/controllers/completion_kit/api/v1/runs_controller.rb', line 78

def compare
  other = Run.find(params[:with])
  comparison = build_run_comparison(@run, other)
  render json: { left_run_id: @run.id, right_run_id: other.id, metric_ids: comparison[:metric_ids], rows: comparison[:rows] }
rescue ActiveRecord::RecordNotFound
  render_error("Other run not found. Pass ?with=<run_id>.", status: :not_found)
end

#createObject



20
21
22
23
24
25
26
27
28
# File 'app/controllers/completion_kit/api/v1/runs_controller.rb', line 20

def create
  run = Run.new(run_params.except(:metric_ids))
  if run.save
    run.replace_metrics!(params[:metric_ids])
    render json: run.reload, status: :created
  else
    render_validation_errors(run)
  end
end

#destroyObject



39
40
41
42
# File 'app/controllers/completion_kit/api/v1/runs_controller.rb', line 39

def destroy
  @run.destroy!
  head :no_content
end

#generateObject



44
45
46
47
48
49
50
# File 'app/controllers/completion_kit/api/v1/runs_controller.rb', line 44

def generate
  if @run.start!
    render json: @run.reload, status: :accepted
  else
    render_error(@run.failure_summary || @run.errors.full_messages.to_sentence, status: :unprocessable_entity)
  end
end

#indexObject



7
8
9
10
11
12
13
14
# File 'app/controllers/completion_kit/api/v1/runs_controller.rb', line 7

def index
  scope = Run.includes(:tags).display_scoped
  scope = scope.where(status: params[:status]) if params[:status].present?
  scope = scope.where(prompt_id: params[:prompt_id]) if params[:prompt_id].present?
  scope = scope.where(dataset_id: params[:dataset_id]) if params[:dataset_id].present?
  scope = filter_by_tags(scope)
  render json: paginate(scope.order(created_at: :desc))
end

#regradeObject



70
71
72
73
74
75
76
# File 'app/controllers/completion_kit/api/v1/runs_controller.rb', line 70

def regrade
  if @run.regrade!
    render json: @run.reload, status: :accepted
  else
    render_error("Nothing to re-grade. The run has no succeeded responses or no metrics attached.", status: :unprocessable_entity)
  end
end

#rerunObject



61
62
63
64
65
66
67
68
# File 'app/controllers/completion_kit/api/v1/runs_controller.rb', line 61

def rerun
  new_run = @run.rerun!
  if new_run.start!
    render json: new_run.reload, status: :accepted
  else
    render_error(new_run.failure_summary || "Could not start the new run.", status: :unprocessable_entity)
  end
end

#retry_failuresObject



52
53
54
55
56
57
58
59
# File 'app/controllers/completion_kit/api/v1/runs_controller.rb', line 52

def retry_failures
  if @run.stale_review_summary.any?
    return render_error("Judge has changed since this run executed. Retry would mix versions in the same run; use POST /api/v1/runs/:id/rerun instead.", status: :conflict)
  end

  @run.retry_failures!(only: params[:only])
  render json: @run.reload, status: :accepted
end

#showObject



16
17
18
# File 'app/controllers/completion_kit/api/v1/runs_controller.rb', line 16

def show
  render json: @run
end

#updateObject



30
31
32
33
34
35
36
37
# File 'app/controllers/completion_kit/api/v1/runs_controller.rb', line 30

def update
  if @run.update(run_params.except(:metric_ids))
    @run.replace_metrics!(params[:metric_ids]) if params.key?(:metric_ids)
    render json: @run.reload
  else
    render_validation_errors(@run)
  end
end