Skip to content

Commit 3bc4690

Browse files
feat: Move Inference Config to Prompt Settings
1 parent 25129f5 commit 3bc4690

File tree

3 files changed

+8
-25
lines changed

3 files changed

+8
-25
lines changed

packages/cdk/resources/BedrockPromptResources.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export class BedrockPromptResources extends Construct {
4343
messages: [props.settings.userPrompt]
4444
})
4545

46-
ragResponsePromptVariant["inferenceConfiguration"] = {
47-
"text": props.settings.inferenceConfig
46+
ragResponsePromptVariant.inferenceConfiguration = {
47+
text: props.settings.inferenceConfig
4848
}
4949

5050
const ragPrompt = new Prompt(this, "ragResponsePrompt", {

packages/cdk/resources/BedrockPromptSettings.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
import * as fs from "fs"
22
import {ChatMessage} from "@cdklabs/generative-ai-cdk-constructs/lib/cdk-lib/bedrock"
33
import {Construct} from "constructs"
4+
import {CfnPrompt} from "aws-cdk-lib/aws-bedrock"
45

56
export type BedrockPromptSettingsType = "system" | "user" | "reformulation"
67

7-
export interface BedrockPromptInferenceConfig {
8-
temperature: number,
9-
topP: number,
10-
maxTokens: number,
11-
stopSequences: Array<string>
12-
}
13-
148
/** BedrockPromptSettings is responsible for loading and providing
159
* the system, user, and reformulation prompts along with their
1610
* inference configurations.
@@ -19,7 +13,7 @@ export class BedrockPromptSettings extends Construct {
1913
public readonly systemPrompt: ChatMessage
2014
public readonly userPrompt: ChatMessage
2115
public readonly reformulationPrompt: ChatMessage
22-
public readonly inferenceConfig: BedrockPromptInferenceConfig
16+
public readonly inferenceConfig: CfnPrompt.PromptModelInferenceConfigurationProperty
2317

2418
/**
2519
* @param scope The Construct scope
@@ -38,14 +32,10 @@ export class BedrockPromptSettings extends Construct {
3832
const reformulationPrompt = this.getTypedPrompt("reformulation")
3933
this.reformulationPrompt = ChatMessage.user(reformulationPrompt.text)
4034

41-
const temperature = this.node.tryGetContext("ragTemperature")
42-
const maxTokens = this.node.tryGetContext("ragMaxTokens")
43-
const topP = this.node.tryGetContext("ragTopP")
44-
4535
this.inferenceConfig = {
46-
temperature: parseInt(temperature, 10),
47-
topP: parseInt(topP, 10),
48-
maxTokens: parseInt(maxTokens, 10),
36+
temperature: 0,
37+
topP: 1,
38+
maxTokens: 512,
4939
stopSequences: [
5040
"Human:"
5141
]

packages/cdk/resources/Functions.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ const RAG_MODEL_ID = "anthropic.claude-3-sonnet-20240229-v1:0"
1111
const QUERY_REFORMULATION_MODEL_ID = "anthropic.claude-3-haiku-20240307-v1:0"
1212
const BEDROCK_KB_DATA_SOURCE = "eps-assist-kb-ds"
1313
const LAMBDA_MEMORY_SIZE = "265"
14-
// Claude RAG inference parameters
15-
const RAG_TEMPERATURE = "0"
16-
const RAG_MAX_TOKENS = "512"
17-
const RAG_TOP_P = "1"
1814

1915
export interface FunctionsProps {
2016
readonly stackName: string
@@ -75,10 +71,7 @@ export class Functions extends Construct {
7571
"QUERY_REFORMULATION_PROMPT_NAME": props.reformulationPromptName,
7672
"RAG_RESPONSE_PROMPT_NAME": props.ragResponsePromptName,
7773
"QUERY_REFORMULATION_PROMPT_VERSION": props.reformulationPromptVersion,
78-
"RAG_RESPONSE_PROMPT_VERSION": props.ragResponsePromptVersion,
79-
"RAG_TEMPERATURE": RAG_TEMPERATURE,
80-
"RAG_MAX_TOKENS": RAG_MAX_TOKENS,
81-
"RAG_TOP_P": RAG_TOP_P
74+
"RAG_RESPONSE_PROMPT_VERSION": props.ragResponsePromptVersion
8275
}
8376
})
8477

0 commit comments

Comments
 (0)