|
1 | 1 | import {Construct} from "constructs" |
2 | | -import {BedrockFoundationModel, Prompt, PromptVariant} from "@cdklabs/generative-ai-cdk-constructs/lib/cdk-lib/bedrock" |
| 2 | +import { |
| 3 | + BedrockFoundationModel, |
| 4 | + Prompt, |
| 5 | + PromptVariant |
| 6 | +} from "@cdklabs/generative-ai-cdk-constructs/lib/cdk-lib/bedrock" |
| 7 | +import {BedrockPromptSettings} from "./BedrockPromptSettings" |
3 | 8 |
|
4 | 9 | export interface BedrockPromptResourcesProps { |
5 | 10 | readonly stackName: string |
| 11 | + readonly settings: BedrockPromptSettings |
6 | 12 | } |
7 | 13 |
|
8 | 14 | export class BedrockPromptResources extends Construct { |
9 | 15 | public readonly queryReformulationPrompt: Prompt |
| 16 | + public readonly ragResponsePrompt: Prompt |
10 | 17 |
|
11 | 18 | constructor(scope: Construct, id: string, props: BedrockPromptResourcesProps) { |
12 | 19 | super(scope, id) |
13 | 20 |
|
14 | | - const claudeModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0 |
15 | | - const promptVariant = PromptVariant.text({ |
| 21 | + const claudeHaikuModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0 |
| 22 | + const claudeSonnetModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0 |
| 23 | + |
| 24 | + const queryReformulationPromptVariant = PromptVariant.text({ |
16 | 25 | variantName: "default", |
17 | | - model: claudeModel, |
| 26 | + model: claudeHaikuModel, |
18 | 27 | promptVariables: ["topic"], |
19 | | - promptText: `Return the user query exactly as provided without any modifications, changes, or reformulations. |
20 | | -Do not alter, rephrase, or modify the input in any way. |
21 | | -Simply return: {{user_query}} |
22 | | -
|
23 | | -User Query: {{user_query}}` |
| 28 | + promptText: props.settings.reformulationPrompt.text |
24 | 29 | }) |
| 30 | + |
25 | 31 | const queryReformulationPrompt = new Prompt(this, "QueryReformulationPrompt", { |
26 | 32 | promptName: `${props.stackName}-queryReformulation`, |
27 | 33 | description: "Prompt for reformulating user queries to improve RAG retrieval", |
28 | | - defaultVariant: promptVariant, |
29 | | - variants: [promptVariant] |
| 34 | + defaultVariant: queryReformulationPromptVariant, |
| 35 | + variants: [queryReformulationPromptVariant] |
| 36 | + }) |
| 37 | + |
| 38 | + const ragResponsePromptVariant = PromptVariant.chat({ |
| 39 | + variantName: "default", |
| 40 | + model: claudeSonnetModel, |
| 41 | + promptVariables: ["query", "search_results"], |
| 42 | + system: props.settings.systemPrompt.text, |
| 43 | + messages: [props.settings.userPrompt] |
| 44 | + }) |
| 45 | + |
| 46 | + ragResponsePromptVariant.inferenceConfiguration = { |
| 47 | + text: props.settings.inferenceConfig |
| 48 | + } |
| 49 | + |
| 50 | + const ragPrompt = new Prompt(this, "ragResponsePrompt", { |
| 51 | + promptName: `${props.stackName}-ragResponse`, |
| 52 | + description: "Prompt for generating RAG responses with knowledge base context and system instructions", |
| 53 | + defaultVariant: ragResponsePromptVariant, |
| 54 | + variants: [ragResponsePromptVariant] |
30 | 55 | }) |
31 | 56 |
|
32 | 57 | this.queryReformulationPrompt = queryReformulationPrompt |
| 58 | + this.ragResponsePrompt = ragPrompt |
33 | 59 | } |
34 | 60 | } |
0 commit comments