Class: CompletionKit::RunsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- CompletionKit::RunsController
- Includes:
- ResponseOrdering, TagFiltering
- Defined in:
- app/controllers/completion_kit/runs_controller.rb
Constant Summary collapse
- RESPONSES_PER_PAGE =
100- RESPONSE_PREVIEW_CHARS =
700
Constants inherited from ApplicationController
ApplicationController::ONBOARDING_DISMISS_COOKIE
Instance Method Summary collapse
- #compare ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #generate ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
-
#refresh_status ⇒ Object
The web process drives the live run page, because worker-side Turbo broadcasts do not reliably publish in production.
- #regrade ⇒ Object
- #rerun ⇒ Object
- #retry_failures ⇒ Object
- #show ⇒ Object
- #suggest ⇒ Object
- #update ⇒ Object
Instance Method Details
#compare ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/controllers/completion_kit/runs_controller.rb', line 89 def compare other_id = params[:with] if other_id.blank? @other_runs = Run.where(dataset_id: @run.dataset_id, prompt_id: @run.prompt_id) .where.not(id: @run.id) .display_scoped .order(created_at: :desc) .limit(50) return render(:compare_picker) end @other_run = Run.find(other_id) @comparison = build_run_comparison(@run, @other_run) render(:compare) end |
#create ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/completion_kit/runs_controller.rb', line 42 def create @run = Run.new(run_params.except(:metric_ids)) if @run.save @run.replace_metrics!(params[:run][:metric_ids]) redirect_to run_path(@run), notice: "Run was successfully created." else load_form_collections render :new, status: :unprocessable_entity end end |
#destroy ⇒ Object
76 77 78 79 |
# File 'app/controllers/completion_kit/runs_controller.rb', line 76 def destroy @run.destroy redirect_to runs_path, notice: "Run was successfully destroyed." end |
#edit ⇒ Object
39 40 |
# File 'app/controllers/completion_kit/runs_controller.rb', line 39 def edit end |
#generate ⇒ Object
81 82 83 84 85 86 87 |
# File 'app/controllers/completion_kit/runs_controller.rb', line 81 def generate if @run.start! redirect_to run_path(@run) else redirect_to run_path(@run), alert: @run.failure_summary || @run.errors..to_sentence end end |
#index ⇒ Object
8 9 10 11 12 |
# File 'app/controllers/completion_kit/runs_controller.rb', line 8 def index scope = Run.includes(:prompt, :dataset, :tags).order(created_at: :desc).display_scoped @runs = apply_tag_filter(scope).load Run.preload_summaries(@runs) end |
#new ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'app/controllers/completion_kit/runs_controller.rb', line 30 def new @run = Run.new(prompt_id: params[:prompt_id]) prompt = Prompt.find_by(id: @run.prompt_id) if prompt last_run = Run.where(prompt_id: prompt.family_versions.ids).display_scoped.order(created_at: :desc).first @run.tag_names = last_run.tag_names if last_run end end |
#refresh_status ⇒ Object
The web process drives the live run page, because worker-side Turbo broadcasts do not reliably publish in production. Since a run is now started asynchronously, this has to carry the rows and the progress panel too, not just the status badge, or the page sits empty until a reload.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/controllers/completion_kit/runs_controller.rb', line 126 def refresh_status show respond_to do |format| format.turbo_stream do render turbo_stream: [ turbo_stream.replace("run_status_header", partial: "completion_kit/runs/status_header", locals: { run: @run }), turbo_stream.replace("run_config", partial: "completion_kit/runs/run_config", locals: { run: @run }), turbo_stream.replace("run_status_panel", partial: "completion_kit/runs/status_panel", locals: { run: @run }), turbo_stream.replace("run_responses_region", partial: "completion_kit/runs/responses_region", locals: { run: @run, responses: @responses, responses_offset: @responses_offset }) ] end end end |
#regrade ⇒ Object
105 106 107 108 109 110 111 |
# File 'app/controllers/completion_kit/runs_controller.rb', line 105 def regrade if @run.regrade! redirect_to run_path(@run), notice: "Re-grading existing responses against the current metrics." else redirect_to run_path(@run), alert: "Nothing to re-grade. The run has no succeeded responses or no metrics attached." end end |
#rerun ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'app/controllers/completion_kit/runs_controller.rb', line 113 def rerun new_run = @run.rerun! if new_run.start! redirect_to run_path(new_run), notice: "Re-running with the same configuration." else redirect_to run_path(new_run), alert: new_run.failure_summary || "Could not start the new run." end end |
#retry_failures ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 |
# File 'app/controllers/completion_kit/runs_controller.rb', line 157 def retry_failures if @run.stale_review_summary.any? redirect_to run_path(@run), alert: "A metric has a newer version than the one this run was scored against. Retrying failed cases would mix scores from two versions in the same run. Use 'Re-run from scratch' to refresh everything against the current metrics." return end @run.retry_failures!(only: params[:only]) @run.broadcast_ui redirect_to run_path(@run) end |
#show ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/completion_kit/runs_controller.rb', line 17 def show @responses_total = @run.responses.count @responses_per_page = RESPONSES_PER_PAGE @responses_total_pages = [(@responses_total.to_f / RESPONSES_PER_PAGE).ceil, 1].max @responses_page = params[:page].to_s.to_i.clamp(1, @responses_total_pages) @responses_offset = (@responses_page - 1) * RESPONSES_PER_PAGE @responses = ordered_responses_relation(@run, params[:sort]) .with_body_preview(RESPONSE_PREVIEW_CHARS) .includes(:reviews) .limit(RESPONSES_PER_PAGE) .offset(@responses_offset) end |
#suggest ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'app/controllers/completion_kit/runs_controller.rb', line 142 def suggest if @run.prompt.nil? redirect_to run_path(@run), alert: "A run that only scores existing outputs has no prompt to improve." return end suggestion = @run.suggestions.create!( prompt: @run.prompt, original_template: @run.prompt.template, status: "pending" ) PromptSuggestionJob.perform_later(suggestion.id) redirect_to suggestion_path(suggestion, from: "run") end |
#update ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/completion_kit/runs_controller.rb', line 53 def update if @run.responses.any? && run_generation_changed? attrs = run_params.except(:metric_ids).to_h attrs.delete("name") if attrs["name"].to_s == @run.name.to_s new_run = Run.new(attrs.merge(status: "pending")) if new_run.save new_run.replace_metrics!(params[:run][:metric_ids]) if params[:run].key?(:metric_ids) redirect_to run_path(new_run), notice: "Saved as a new run. The previous run and its results are preserved." else @run.assign_attributes(run_params.except(:metric_ids)) new_run.errors.each { |error| @run.errors.add(error.attribute, error.) } load_form_collections render :edit, status: :unprocessable_entity end elsif @run.update(run_params.except(:metric_ids)) @run.replace_metrics!(params[:run][:metric_ids]) if params[:run].key?(:metric_ids) redirect_to run_path(@run), notice: "Run saved." else load_form_collections render :edit, status: :unprocessable_entity end end |