Skip to content

Commit

Permalink
fix(bedrock): chat template compile issues
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-rafams committed Jan 6, 2025
1 parent 39c6440 commit 1683b09
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/cdk-lib/bedrock/prompts/prompt-variant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,29 @@ export interface ToolConfiguration {

export class ToolChoice {
/** The model must request at least one tool (no text is generated) */
public static readonly ANY = {
any: {},
};
public static readonly ANY = new ToolChoice({}, undefined, undefined);
/** (Default). The Model automatically decides if a tool should be called or whether to generate text instead.*/
public static readonly AUTO = {
auto: {},
};
public static readonly AUTO = new ToolChoice(undefined, {}, undefined);
/** The Model must request the specified tool. Only supported by some models like Anthropic Claude 3 models. */
public static specificTool(toolName: string) {
return new ToolChoice(undefined, undefined, toolName);
}
public readonly any?: any;
public readonly auto?: any;
public readonly tool?: string;

constructor(any: any, auto: any, tool?: string) {
(this.any = any), (this.auto = auto), (this.tool = tool);
}
/**
*
* @internal
*/
public __render(): CfnPrompt.ToolChoiceProperty {
return {
tool: { name: toolName },
any: this.any,
auto: this.auto,
tool: this.tool ? { name: this.tool } : undefined,
};
}
}
Expand Down Expand Up @@ -212,7 +224,12 @@ export abstract class PromptVariant {
}),
messages: props.messages?.flatMap(m => m.__render()),
system: props.system ? [{ text: props.system }] : undefined,
toolConfiguration: props.toolConfiguration,
toolConfiguration: props.toolConfiguration
? {
toolChoice: props.toolConfiguration.toolChoice.__render(),
tools: props.toolConfiguration.tools,
}
: undefined,
},
},
};
Expand Down

0 comments on commit 1683b09

Please sign in to comment.