-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bedrock basic answer strategy #27
Conversation
26279fd
to
c75e7f0
Compare
c75e7f0
to
6442a60
Compare
6442a60
to
e1bd956
Compare
f1cc88e
to
09bdd47
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great Chae, sorry for taking a while to get this review together.
I think the other thing to add which we discussed was a system test similar to https://github.com/alphagov/govuk-chat/blob/main/spec/system/conversation_with_open_ai_with_structured_answer_spec.rb
lib/answer_composition/pipeline/bedrock_structured_answer_composer.rb
Outdated
Show resolved
Hide resolved
lib/answer_composition/pipeline/bedrock_structured_answer_composer.rb
Outdated
Show resolved
Hide resolved
spec/lib/answer_composition/pipeline/bedrock_structured_answer_composer_spec.rb
Outdated
Show resolved
Hide resolved
lib/answer_composition/pipeline/bedrock_structured_answer_composer.rb
Outdated
Show resolved
Hide resolved
spec/lib/answer_composition/pipeline/bedrock_structured_answer_composer_spec.rb
Outdated
Show resolved
Hide resolved
spec/lib/answer_composition/pipeline/bedrock_structured_answer_composer_spec.rb
Outdated
Show resolved
Hide resolved
spec/lib/answer_composition/pipeline/bedrock_structured_answer_composer_spec.rb
Outdated
Show resolved
Hide resolved
09bdd47
to
cdd74c1
Compare
cdd74c1
to
e7a2a7e
Compare
7589e94
to
1cd13cb
Compare
1cd13cb
to
e824b5c
Compare
e824b5c
to
f166e5f
Compare
1fe111c
to
6b5c3a7
Compare
6b5c3a7
to
df027e7
Compare
df027e7
to
54fb7ce
Compare
Changes the approach to setting the answer strategy when a new Question is created to now be configured via an env var. Currently this defaults to `openai_structured_answer`, but allows for the creation of an `ANSWER_STRATEGY` variable in `.env` which can be set to `"claude_structured_answer"` in order to switch to using Claude via Bedrock as an answer service.
The `OpenAIAnswer` class has minimal code that is specific to OpenAI so has been renamed to the more generic `PipelineRunner`. This class will be used to execute the pipeline regardless of which answer service is configured by the answer strategy. Currently catches errors separately for both OpenAI and AWS, but these may be abstracted in the future.
54fb7ce
to
f90e696
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of little comments but looks great to me.
lib/answer_composition/pipeline/claude/structured_answer_composer.rb
Outdated
Show resolved
Hide resolved
Creates a `StructuredAnswerComposer` class for Claude that makes use of the AWS BedrockRuntime SDK to use Claude as an answer service. In order to force a JSON output from Claude it uses a tool call, this is configured to always be used via the `tool_choice` configuration option for the Bedrock request.
f90e696
to
6271202
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, just made a suggestion to the stub_bedrock comment to clear it up then good to merge.
I've tried it out locally and it works great.
This sets up testing for the Claude structured answer composer. It creates an initial set of tests. It also creates a set of helpers in StubBedrock. The helpers include a general task to stub the Bedrock converse endpoint, and then high and low level tasks for stubbing the Claude tool call responses.
This creates system tests for a conversation with Claude using structured answers. It also adds a new system spec helper to allow a scenario where Rails configuration is set to use Claude as an answer strategy.
6271202
to
40b1146
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, let's go 🚀
This PR implements a basic answer strategy using Claude 3.5 Sonnet on Bedrock. In this initial implementation we simply have Claude provide a structured JSON response directly, without rephrasing, guardrails or RAG.
It does four things:
OpenAIAnswer
class to a more genericPipelineRunner
class, this can be used to run the pipeline for both Claude and OpenAI.StructuredAnswerComposer
for Claude that returns a JSON response via a tool call.Trello: https://trello.com/c/wB5dUyQ7/2257-integrate-a-very-basic-answer-strategy-no-rag-with-aws-bedrock