Class: CompletionKit::PromptsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/completion_kit/prompts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
# File 'app/controllers/completion_kit/prompts_controller.rb', line 22

def create
  @prompt = Prompt.new(prompt_params)

  if @prompt.save
    redirect_to prompt_path(@prompt), notice: "Prompt version was successfully created."
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



44
45
46
47
# File 'app/controllers/completion_kit/prompts_controller.rb', line 44

def destroy
  @prompt.destroy
  redirect_to prompts_path, notice: "Prompt version was successfully destroyed."
end

#editObject



19
20
# File 'app/controllers/completion_kit/prompts_controller.rb', line 19

def edit
end

#indexObject



5
6
7
# File 'app/controllers/completion_kit/prompts_controller.rb', line 5

def index
  @prompts = Prompt.current_versions.includes(:runs).order(created_at: :desc)
end

#newObject



15
16
17
# File 'app/controllers/completion_kit/prompts_controller.rb', line 15

def new
  @prompt = Prompt.new
end

#publishObject



49
50
51
52
# File 'app/controllers/completion_kit/prompts_controller.rb', line 49

def publish
  @prompt.publish!
  redirect_to prompt_path(@prompt), notice: "#{@prompt.display_name} is now the current version."
end

#showObject



9
10
11
12
13
# File 'app/controllers/completion_kit/prompts_controller.rb', line 9

def show
  @runs = Run.where(prompt_id: @prompt.family_versions.select(:id))
             .includes(:prompt, :dataset, responses: :reviews)
             .order(created_at: :desc)
end

#updateObject



32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/completion_kit/prompts_controller.rb', line 32

def update
  if @prompt.runs.exists?
    new_prompt = @prompt.clone_as_new_version(prompt_params.to_h)
    new_prompt.publish!
    redirect_to prompt_path(new_prompt), notice: "Saved as #{new_prompt.version_label}."
  elsif @prompt.update(prompt_params)
    redirect_to prompt_path(@prompt), notice: "Prompt saved."
  else
    render :edit, status: :unprocessable_entity
  end
end