Skip to content

Commit 9e19aee

Browse files
committed
Add coherence to the question show page in the admin UI
This adds the coherence evaluation runs to the analysis tab of the question show page in the admin interface. It mirrors the existing answer relevancy runs display.
1 parent e22f34e commit 9e19aee

6 files changed

Lines changed: 61 additions & 47 deletions

File tree

app/controllers/admin/questions_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def index
77
def show
88
question_scope = Question.includes(
99
conversation: :signon_user,
10-
answer: [{ sources: :chunk }, :feedback, :topics, :answer_relevancy_runs],
10+
answer: [{ sources: :chunk }, :feedback, :topics, :answer_relevancy_runs, :coherence_runs],
1111
)
1212

1313
@question = question_scope.find(params[:id])

app/models/answer.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ def group_used_answer_sources_by_base_path
203203
end
204204

205205
def has_analysis?
206-
topics.present? || answer_relevancy_runs.present?
206+
topics.present? ||
207+
answer_relevancy_runs.present? ||
208+
coherence_runs.present?
207209
end
208210

209211
def question_used

app/views/admin/questions/_analysis_tab.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@
4949
<% if answer_relevancy_runs.present? %>
5050
<%= render "generic_auto_evaluation_runs", runs: answer_relevancy_runs, title: "Answer relevancy" %>
5151
<% end %>
52+
53+
<% if coherence_runs.present? %>
54+
<%= render "generic_auto_evaluation_runs", runs: coherence_runs, title: "Coherence" %>
55+
<% end %>

app/views/admin/questions/show.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ content_for(:active_navigation_item, admin_questions_path)
4040
"analysis_tab",
4141
topics: @answer.topics,
4242
answer_relevancy_runs: @answer.answer_relevancy_runs,
43+
coherence_runs: @answer.coherence_runs,
4344
),
4445
} if @answer&.has_analysis?
4546
%>

spec/models/answer_spec.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,14 @@
360360
expect(answer.has_analysis?).to be(true)
361361
end
362362

363-
it "returns true if answer_relevancy_runs are present" do
364-
answer = build(
365-
:answer, answer_relevancy_runs: [build(:answer_relevancy_run)]
366-
)
367-
expect(answer.has_analysis?).to be(true)
363+
%i[answer_relevancy_runs coherence_runs].each do |association|
364+
it "returns true if #{association} are present" do
365+
answer = build(
366+
:answer, "#{association}": [build(association.to_s.singularize)]
367+
)
368+
369+
expect(answer.has_analysis?).to be(true)
370+
end
368371
end
369372

370373
it "returns false if no analysis is present" do

spec/requests/admin/questions_spec.rb

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@
284284
.and have_content('"id": "call_dqGpbb39drQDafLsjDLtnbGD"')
285285
end
286286

287-
it "doesn't render the tabs component when there are no topics or auto-eval aggregate data" do
287+
it "doesn't render the tabs component there is no analysis data" do
288288
question = create(:question, :with_answer)
289289
get admin_show_question_path(question)
290290

@@ -362,51 +362,55 @@
362362
end
363363
end
364364

365-
context "when answer relevancy aggregate data is present" do
366-
let(:run) do
367-
create(
368-
:answer_relevancy_run,
369-
score: 0.85,
370-
reason: "The answer is relevant to the question.",
371-
llm_responses: {
372-
"statements" => { "statements" => ["The answer is relevant."] },
373-
"verdicts" => { "verdicts" => [{ "verdict" => "yes" }] },
374-
},
375-
metrics: {
376-
"statements" => { duration: 1.55556 },
377-
"verdicts" => { duration: 1.44445 },
378-
},
379-
)
380-
end
381-
let(:question) { run.answer.question }
365+
{
366+
answer_relevancy_run: "Answer relevancy",
367+
coherence_run: "Coherence",
368+
}.each do |model, title|
369+
context "when answer relevancy aggregate data is present" do
370+
let(:run) do
371+
create(
372+
model,
373+
score: 0.85,
374+
reason: "The answer was acceptable.",
375+
llm_responses: {
376+
"statements" => { "statements" => ["The answer was acceptable."] },
377+
"verdicts" => { "verdicts" => [{ "verdict" => "yes" }] },
378+
},
379+
metrics: {
380+
"statements" => { duration: 1.55556 },
381+
"verdicts" => { duration: 1.44445 },
382+
},
383+
)
384+
end
385+
let(:question) { run.answer.question }
382386

383-
it "renders the answer relevancy aggregate and run details" do
384-
get admin_show_question_path(question)
387+
it "renders #{model} details" do
388+
get admin_show_question_path(question)
385389

386-
expect(response.body.squish)
387-
.to have_content("Answer relevancy")
388-
.and have_content("Run 1 score")
389-
.and have_content("0.85")
390-
.and have_content("Run 1 reason")
391-
.and have_content("The answer is relevant to the question.")
392-
end
390+
expect(response.body.squish)
391+
.to have_content(title)
392+
.and have_content("Mean score 0.85")
393+
.and have_content("Run 1 score 0.85")
394+
.and have_content("Run 1 reason The answer was acceptable.")
395+
end
393396

394-
it "renders the runs llm responses" do
395-
get admin_show_question_path(question)
397+
it "renders the runs llm responses" do
398+
get admin_show_question_path(question)
396399

397-
expect(response.body.squish)
398-
.to have_content('{ "statements": [ "The answer is relevant." ] }')
399-
.and have_content('{ "verdicts": [ { "verdict": "yes" } ] }')
400-
end
400+
expect(response.body.squish)
401+
.to have_content('{ "statements": [ "The answer was acceptable." ] }')
402+
.and have_content('{ "verdicts": [ { "verdict": "yes" } ] }')
403+
end
401404

402-
it "renders the runs metrics" do
403-
get admin_show_question_path(question)
405+
it "renders the runs metrics" do
406+
get admin_show_question_path(question)
404407

405-
expect(response.body.squish)
406-
.to have_content("Statements")
407-
.and have_content(/duration.*1\.55556/)
408-
.and have_content("Verdicts")
409-
.and have_content(/duration.*1\.44445/)
408+
expect(response.body.squish)
409+
.to have_content("Statements")
410+
.and have_content(/duration.*1\.55556/)
411+
.and have_content("Verdicts")
412+
.and have_content(/duration.*1\.44445/)
413+
end
410414
end
411415
end
412416
end

0 commit comments

Comments
 (0)