-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
115 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module StubClaudeConverse | ||
def stub_claude_structured_answer_reponse(answer) | ||
[ | ||
{ | ||
output: { | ||
message: { | ||
role: "assistant", | ||
content: [ | ||
{ | ||
tool_use: { | ||
input: { "answer" => answer }, | ||
tool_use_id: "tool_id", | ||
name: "tool_name", | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
stop_reason: "end_turn", | ||
usage: { | ||
input_tokens: 10, | ||
output_tokens: 20, | ||
total_tokens: 30, | ||
}, | ||
metrics: { | ||
latency_ms: 999, | ||
}, | ||
}, | ||
] | ||
end | ||
end |
82 changes: 82 additions & 0 deletions
82
spec/system/conversation_with_claude_structured_answer_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
RSpec.describe "Conversation with Claude with a structured answer" do | ||
scenario do | ||
given_i_am_a_signed_in_early_access_user | ||
and_i_have_confirmed_i_understand_chat_risks | ||
when_i_visit_the_conversation_page | ||
and_i_enter_a_question | ||
then_i_see_the_answer_is_pending | ||
|
||
when_the_first_answer_is_generated | ||
and_i_click_on_the_check_answer_button | ||
then_i_see_my_question_on_the_page | ||
and_i_can_see_the_first_answer | ||
|
||
when_i_enter_a_second_question | ||
then_i_see_the_answer_is_pending | ||
|
||
when_the_second_answer_is_generated | ||
and_i_click_on_the_check_answer_button | ||
then_i_see_my_second_question_on_the_page | ||
and_i_can_see_the_second_answer | ||
end | ||
|
||
def when_i_visit_the_conversation_page | ||
visit show_conversation_path | ||
end | ||
|
||
def and_i_enter_a_question | ||
@first_question = "How much tax should I be paying?" | ||
fill_in "Message", with: @first_question | ||
click_on "Send" | ||
end | ||
|
||
def then_i_see_the_answer_is_pending | ||
expect(page).to have_content("GOV.UK Chat is generating an answer") | ||
end | ||
|
||
def when_the_first_answer_is_generated | ||
@first_answer = "Lots of tax." | ||
stub_bedrock_request( | ||
:converse, | ||
stub_claude_structured_answer_reponse(@first_answer), | ||
) | ||
|
||
execute_queued_sidekiq_jobs | ||
end | ||
|
||
def when_the_second_answer_is_generated | ||
@second_answer = "Even more tax." | ||
stub_bedrock_request( | ||
:converse, | ||
stub_claude_structured_answer_reponse(@second_answer), | ||
) | ||
|
||
execute_queued_sidekiq_jobs | ||
end | ||
|
||
def and_i_click_on_the_check_answer_button | ||
click_on "Check if an answer has been generated" | ||
end | ||
|
||
def then_i_see_my_question_on_the_page | ||
expect(page).to have_content(@first_question) | ||
end | ||
|
||
def then_i_see_my_second_question_on_the_page | ||
expect(page).to have_content(@second_question) | ||
end | ||
|
||
def and_i_can_see_the_first_answer | ||
expect(page).to have_content(@first_answer) | ||
end | ||
|
||
def and_i_can_see_the_second_answer | ||
expect(page).to have_content(@second_answer) | ||
end | ||
|
||
def when_i_enter_a_second_question | ||
@second_question = "Are you sure?" | ||
fill_in "Message", with: @second_question | ||
click_on "Send" | ||
end | ||
end |