Class: Leva::WorkbenchController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Leva::WorkbenchController
- Includes:
- ApplicationHelper
- Defined in:
- app/controllers/leva/workbench_controller.rb
Instance Method Summary collapse
-
#create ⇒ void
POST /workbench.
-
#edit ⇒ void
GET /workbench/1.
-
#index ⇒ void
GET /workbench.
-
#new ⇒ void
GET /workbench/new.
- #run ⇒ Object
- #run_all_evals ⇒ Object
- #run_evaluator ⇒ Object
-
#update ⇒ void
PATCH/PUT /workbench/1.
Methods included from ApplicationHelper
#load_evaluators, #load_predefined_prompts, #load_runners
Instance Method Details
#create ⇒ void
This method returns an undefined value.
POST /workbench
42 43 44 45 46 47 48 49 |
# File 'app/controllers/leva/workbench_controller.rb', line 42 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 |
#edit ⇒ void
This method returns an undefined value.
GET /workbench/1
53 54 |
# File 'app/controllers/leva/workbench_controller.rb', line 53 def edit end |
#index ⇒ void
This method returns an undefined value.
GET /workbench
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# 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 # Get merged context if runner and dataset record are available if @selected_runner && @dataset_record runner_class = @selected_runner.constantize rescue nil if runner_class && runner_class < Leva::BaseRun runner = runner_class.new @record_context = @dataset_record.recordable.to_llm_context @runner_context = runner.to_llm_context(@dataset_record.recordable) @merged_context = @record_context.merge(@runner_context) end end end |
#new ⇒ void
This method returns an undefined value.
GET /workbench/new
35 36 37 38 |
# File 'app/controllers/leva/workbench_controller.rb', line 35 def new @prompt = Prompt.new @predefined_prompts = load_predefined_prompts end |
#run ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/controllers/leva/workbench_controller.rb', line 67 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_evals ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'app/controllers/leva/workbench_controller.rb', line 79 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_evaluator ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/controllers/leva/workbench_controller.rb', line 90 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 |
#update ⇒ void
This method returns an undefined value.
PATCH/PUT /workbench/1
58 59 60 61 62 63 64 65 |
# File 'app/controllers/leva/workbench_controller.rb', line 58 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. }, status: :unprocessable_entity end end |