Class: Leva::WorkbenchController

Inherits:
ApplicationController show all
Includes:
ApplicationHelper
Defined in:
app/controllers/leva/workbench_controller.rb

Instance Method Summary collapse

Methods included from ApplicationHelper

#load_evaluators, #load_predefined_prompts, #load_runners

Instance Method Details

#createvoid

This method returns an undefined value.

POST /workbench



31
32
33
34
35
36
37
38
# File 'app/controllers/leva/workbench_controller.rb', line 31

def create
  @prompt = Prompt.new(prompt_params)
  if @prompt.save
    redirect_to workbench_index_path(prompt_id: @prompt.id), notice: 'Prompt was successfully created.'
  else
    render :new
  end
end

#editvoid

This method returns an undefined value.

GET /workbench/1



42
43
# File 'app/controllers/leva/workbench_controller.rb', line 42

def edit
end

#indexvoid

This method returns an undefined value.

GET /workbench



13
14
15
16
17
18
19
20
# File 'app/controllers/leva/workbench_controller.rb', line 13

def index
  @prompts = Prompt.all
  @selected_prompt = @prompt || Prompt.first
  @evaluators = load_evaluators
  @runners = load_runners
  @selected_runner = params[:runner] || @runners.first&.name
  @selected_dataset_record = params[:dataset_record_id] || DatasetRecord.first&.id
end

#newvoid

This method returns an undefined value.

GET /workbench/new



24
25
26
27
# File 'app/controllers/leva/workbench_controller.rb', line 24

def new
  @prompt = Prompt.new
  @predefined_prompts = load_predefined_prompts
end

#runObject



56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/leva/workbench_controller.rb', line 56

def run
  return redirect_to workbench_index_path, alert: 'Please select a record and a runner' unless @dataset_record && run_params[:runner]

  runner_class = run_params[:runner].constantize
  return redirect_to workbench_index_path, alert: 'Invalid runner selected' unless runner_class < Leva::BaseRun

  runner = runner_class.new
  runner_result = runner.execute_and_store(nil, @dataset_record, @prompt)

  redirect_to workbench_index_path(prompt_id: @prompt.id, dataset_record_id: @dataset_record.id, runner: run_params[:runner]), notice: 'Run completed successfully'
end

#run_all_evalsObject



68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/leva/workbench_controller.rb', line 68

def run_all_evals
  return redirect_to workbench_index_path, alert: 'No runner result available' unless @runner_result

  load_evaluators.each do |evaluator_class|
    evaluator = evaluator_class.new
    evaluator.evaluate_and_store(nil, @runner_result)
  end

  redirect_to workbench_index_path(prompt_id: @prompt.id, dataset_record_id: @dataset_record.id, runner: params[:runner]), notice: 'All evaluations completed successfully'
end

#run_evaluatorObject



79
80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/leva/workbench_controller.rb', line 79

def run_evaluator
  return redirect_to workbench_index_path, alert: 'No runner result available' unless @runner_result

  evaluator_class = params[:evaluator].constantize
  return redirect_to workbench_index_path, alert: 'Invalid evaluator selected' unless evaluator_class < Leva::BaseEval

  evaluator = evaluator_class.new
  evaluator.evaluate_and_store(nil, @runner_result)

  redirect_to workbench_index_path(prompt_id: @prompt.id, dataset_record_id: @dataset_record.id, runner: params[:runner]), notice: 'Evaluator run successfully'
end

#updatevoid

This method returns an undefined value.

PATCH/PUT /workbench/1



47
48
49
50
51
52
53
54
# File 'app/controllers/leva/workbench_controller.rb', line 47

def update
  @prompt = Prompt.find(params[:id])
  if @prompt.update(prompt_params)
    render json: { status: 'success', message: 'Prompt updated successfully' }
  else
    render json: { status: 'error', errors: @prompt.errors.full_messages }, status: :unprocessable_entity
  end
end