Skip to content

Commit fee0224

Browse files
feat: creates new prompt resources
1 parent 9d633db commit fee0224

File tree

1 file changed

+74
-6
lines changed

1 file changed

+74
-6
lines changed
Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
import {Construct} from "constructs"
2-
import {BedrockFoundationModel, Prompt, PromptVariant} from "@cdklabs/generative-ai-cdk-constructs/lib/cdk-lib/bedrock"
2+
import {
3+
BedrockFoundationModel,
4+
ChatMessage,
5+
Prompt,
6+
PromptVariant
7+
} from "@cdklabs/generative-ai-cdk-constructs/lib/cdk-lib/bedrock"
38

49
export interface BedrockPromptResourcesProps {
510
readonly stackName: string
611
}
712

813
export class BedrockPromptResources extends Construct {
914
public readonly queryReformulationPrompt: Prompt
15+
public readonly ragResponsePrompt: Prompt
1016

1117
constructor(scope: Construct, id: string, props: BedrockPromptResourcesProps) {
1218
super(scope, id)
1319

14-
const claudeModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0
15-
const promptVariant = PromptVariant.text({
20+
const claudeHaikuModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0
21+
const claudeSonnetModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0
22+
23+
const queryReformulationPromptVariant = PromptVariant.text({
1624
variantName: "default",
17-
model: claudeModel,
25+
model: claudeHaikuModel,
1826
promptVariables: ["topic"],
1927
promptText: `Return the user query exactly as provided without any modifications, changes, or reformulations.
2028
Do not alter, rephrase, or modify the input in any way.
@@ -25,10 +33,70 @@ User Query: {{user_query}}`
2533
const queryReformulationPrompt = new Prompt(this, "QueryReformulationPrompt", {
2634
promptName: `${props.stackName}-queryReformulation`,
2735
description: "Prompt for reformulating user queries to improve RAG retrieval",
28-
defaultVariant: promptVariant,
29-
variants: [promptVariant]
36+
defaultVariant: queryReformulationPromptVariant,
37+
variants: [queryReformulationPromptVariant]
38+
})
39+
40+
const ragResponsePromptVariant = PromptVariant.chat({
41+
variantName: "default",
42+
model: claudeSonnetModel,
43+
promptVariables: ["query", "search_results"],
44+
system: `System Instructions:
45+
You are an AI assistant designed to provide helpful information and guidance related to healthcare systems,
46+
data integration and user setup.
47+
48+
Requirements:
49+
1. Break down the question(s) based on the context
50+
2. Examine the information provided in the question(s) or requirement(s).
51+
3. Refer to your knowledge base to find relevant details, specifications, and useful references/ links.
52+
4. The knowledge base is your source of truth before anything else
53+
5. Provide critical thinking before replying to make the direction actionable and authoritative
54+
6. Provide a clear and comprehensive answer by drawing inferences,
55+
making logical connections from the available information, comparing previous messages,
56+
and providing users with link and/ or references to follow.
57+
6. Be clear in answers, direct actions are preferred (eg., "Check Postcode" > "Refer to documentation")
58+
59+
Constraints:
60+
1. Quotes should be italic
61+
2. Document titles and document section names should be bold
62+
3. If there is a single question, or the user is asking for direction, do not list items
63+
4. If the query has multiple questions *and* the answer includes multiple answers for multiple questions
64+
(as lists or bullet points), the list items must be formatted as "*<question>*\n - <answer(s)>".
65+
4a. If there are multiple questions in the query, shorten the question to less than 50 characters
66+
4b. If questions are listed, *do not* include the list number/ letter in the question
67+
(i.e., "1. Question" -> "Question")
68+
69+
Output:
70+
- Structured, informative, and tailored to the specific context of the question.
71+
- Acknowledging any assumptions or limitations in your knowledge or understanding.
72+
73+
Tone:
74+
Professional, helpful, authoritative.
75+
76+
Examples:
77+
---
78+
Q: Should alerts be automated?
79+
A: *Section 1.14.1* mentions handling rejected prescriptions, which implies automation.
80+
---
81+
`,
82+
messages: [ChatMessage.user(`
83+
- Using your knowledge around the National Health Service (NHS), Electronic Prescription Service (EPS) and
84+
the Fast Healthcare Intereperability Resources' (FHIR) onboarding, Supplier Conformance Assessment List (SCAL),
85+
APIs, developer guides and error resolution; please answer the following question and cite direct quotes
86+
and document sections.
87+
- If my query is asking for instructions (i.e., "How to...", "How do I...") provide step by steps instructions
88+
- Do not provide general advice or external instructions
89+
90+
<user_query>{{user_query}}<user_query>`)]
91+
})
92+
const ragPrompt = new Prompt(this, "ragResponsePrompt", {
93+
promptName: `${props.stackName}-ragResponse`,
94+
description: "Prompt for generating RAG responses with knowledge base context and system instructions",
95+
defaultVariant: ragResponsePromptVariant,
96+
variants: [ragResponsePromptVariant]
3097
})
3198

3299
this.queryReformulationPrompt = queryReformulationPrompt
100+
this.ragResponsePrompt = ragPrompt
33101
}
34102
}

0 commit comments

Comments
 (0)