Skip to content

Commit

Permalink
fix(bedrock): eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-rafams committed Jan 6, 2025
1 parent 5dc7370 commit 39c6440
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 39 deletions.
42 changes: 21 additions & 21 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ project.github?.actions.set('actions/checkout@v3', 'actions/checkout@b4ffde65f46
project.github?.actions.set('actions/checkout@v4', 'actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11');
project.github?.actions.set(
'actions/download-artifact@v3',
'actions/download-artifact@b4aefff88e83a2676a730654e1ce3dce61880379'
'actions/download-artifact@b4aefff88e83a2676a730654e1ce3dce61880379',
); // https://github.com/projen/projen/issues/3529
project.github?.actions.set(
'actions/download-artifact@v4',
'actions/download-artifact@b4aefff88e83a2676a730654e1ce3dce61880379'
'actions/download-artifact@b4aefff88e83a2676a730654e1ce3dce61880379',
);
project.github?.actions.set(
'actions/github-script@v6',
'actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410'
'actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410',
);
project.github?.actions.set('actions/setup-dotnet@v3', 'actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3');
project.github?.actions.set('actions/setup-dotnet@v4', 'actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3');
Expand All @@ -186,64 +186,64 @@ project.github?.actions.set('actions/setup-java@v4', 'actions/setup-java@99b8673
project.github?.actions.set('actions/stale@v4', 'actions/stale@a20b814fb01b71def3bd6f56e7494d667ddf28da');
project.github?.actions.set(
'actions/upload-artifact@v3',
'actions/upload-artifact@18bf333cd2249fbbbdb605fd9d9ed57efd7adf34'
'actions/upload-artifact@18bf333cd2249fbbbdb605fd9d9ed57efd7adf34',
); // https://github.com/projen/projen/issues/3529
project.github?.actions.set(
'actions/upload-artifact@v4',
'actions/upload-artifact@18bf333cd2249fbbbdb605fd9d9ed57efd7adf34'
'actions/upload-artifact@18bf333cd2249fbbbdb605fd9d9ed57efd7adf34',
);
project.github?.actions.set(
'amannn/[email protected]',
'amannn/action-semantic-pull-request@01d5fd8a8ebb9aafe902c40c53f0f4744f7381eb'
'amannn/action-semantic-pull-request@01d5fd8a8ebb9aafe902c40c53f0f4744f7381eb',
);
project.github?.actions.set(
'amannn/[email protected]',
'amannn/action-semantic-pull-request@e9fabac35e210fea40ca5b14c0da95a099eff26f'
'amannn/action-semantic-pull-request@e9fabac35e210fea40ca5b14c0da95a099eff26f',
);
project.github?.actions.set(
'aws-github-ops/github-merit-badger@main',
'aws-github-ops/github-merit-badger@70d1c47f7051d6e324d4ddc48d676ba61ef69a3e'
'aws-github-ops/github-merit-badger@70d1c47f7051d6e324d4ddc48d676ba61ef69a3e',
);
project.github?.actions.set(
'codecov/codecov-action@v3',
'codecov/codecov-action@84508663e988701840491b86de86b666e8a86bed'
'codecov/codecov-action@84508663e988701840491b86de86b666e8a86bed',
); // https://github.com/projen/projen/issues/3529
project.github?.actions.set(
'codecov/codecov-action@v4',
'codecov/codecov-action@84508663e988701840491b86de86b666e8a86bed'
'codecov/codecov-action@84508663e988701840491b86de86b666e8a86bed',
);
project.github?.actions.set('github/issue-metrics@v2', 'github/issue-metrics@6bc5254e72971dbb7462db077779f1643f772afd');
project.github?.actions.set(
'hmarr/[email protected]',
'hmarr/auto-approve-action@f0939ea97e9205ef24d872e76833fa908a770363'
'hmarr/auto-approve-action@f0939ea97e9205ef24d872e76833fa908a770363',
);
project.github?.actions.set(
'minicli/[email protected]',
'minicli/action-contributors@20ec03af008cb51110a3137fbf77f59a4fd7ff5a'
'minicli/action-contributors@20ec03af008cb51110a3137fbf77f59a4fd7ff5a',
);
project.github?.actions.set(
'oss-review-toolkit/ort-ci-github-action@v1',
'oss-review-toolkit/ort-ci-github-action@7f23c1f8d169dad430e41df223d3b8409c7a156e'
'oss-review-toolkit/ort-ci-github-action@7f23c1f8d169dad430e41df223d3b8409c7a156e',
);
project.github?.actions.set(
'peter-evans/create-issue-from-file@v4',
'peter-evans/create-issue-from-file@433e51abf769039ee20ba1293a088ca19d573b7f'
'peter-evans/create-issue-from-file@433e51abf769039ee20ba1293a088ca19d573b7f',
);
project.github?.actions.set(
'peter-evans/create-pull-request@v4',
'peter-evans/create-pull-request@38e0b6e68b4c852a5500a94740f0e535e0d7ba54'
'peter-evans/create-pull-request@38e0b6e68b4c852a5500a94740f0e535e0d7ba54',
);
project.github?.actions.set(
'peter-evans/create-pull-request@v5',
'peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38'
'peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38',
);
project.github?.actions.set(
'peter-evans/create-pull-request@v6',
'peter-evans/create-pull-request@b1ddad2c994a25fbc81a28b3ec0e368bb2021c50'
'peter-evans/create-pull-request@b1ddad2c994a25fbc81a28b3ec0e368bb2021c50',
);
project.github?.actions.set(
'aws-actions/[email protected]',
'aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502'
'aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502',
);
project.github?.actions.set('imjohnbo/issue-bot@v3', 'imjohnbo/issue-bot@3daae12aa54d38685d7ff8459fc8a2aee8cea98b');

Expand All @@ -268,7 +268,7 @@ project.npmignore?.addPatterns(
'repolinter.json',
'commitlint.config.js',
'.ort.yml',
'.husky'
'.husky',
);

// Add License header automatically
Expand Down Expand Up @@ -296,7 +296,7 @@ new ProjenStruct(project, { name: 'DockerLambdaCustomProps', filePath: 'src/comm
'role',
'layers',
'allowPublicSubnet',
'allowAllOutbound'
'allowAllOutbound',
);

const packageJson = project.tryFindObjectFile('package.json');
Expand Down Expand Up @@ -332,7 +332,7 @@ project.addTask('generate-models-containers', {
const postCompile = project.tasks.tryFind('post-compile');
if (postCompile) {
postCompile.exec(
'npx typedoc --plugin typedoc-plugin-markdown --out apidocs --readme none --categoryOrder "Namespaces,Classes,Interfaces,*" --disableSources ./src/index.ts'
'npx typedoc --plugin typedoc-plugin-markdown --out apidocs --readme none --categoryOrder "Namespaces,Classes,Interfaces,*" --disableSources ./src/index.ts',
);
}

Expand Down
22 changes: 17 additions & 5 deletions src/cdk-lib/bedrock/prompts/prompt-variant.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
* with the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
import { aws_bedrock as bedrock } from 'aws-cdk-lib';
import { IInvokable } from '../models';
import { CfnPrompt } from 'aws-cdk-lib/aws-bedrock';
import { IAgentAlias } from '../agent-alias';
import { IInvokable } from '../models';

// ------------------------------------------------------
// COMMON
Expand Down Expand Up @@ -109,17 +121,17 @@ export class ChatMessage {
}

export interface ToolConfiguration {
toolChoice: ToolChoice;
tools: CfnPrompt.ToolProperty[];
readonly toolChoice: ToolChoice;
readonly tools: CfnPrompt.ToolProperty[];
}

export class ToolChoice {
/** The model must request at least one tool (no text is generated) */
public static ANY = {
public static readonly ANY = {
any: {},
};
/** (Default). The Model automatically decides if a tool should be called or whether to generate text instead.*/
public static AUTO = {
public static readonly AUTO = {
auto: {},
};
/** The Model must request the specified tool. Only supported by some models like Anthropic Claude 3 models. */
Expand Down
4 changes: 2 additions & 2 deletions src/cdk-lib/bedrock/prompts/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export class Prompt extends Construct implements IPrompt {
const matchesPattern = /^([0-9a-zA-Z][_-]?){1,100}$/.test(this.promptName);
if (!matchesPattern) {
errors.push(
'Valid characters are a-z, A-Z, 0-9, _ (underscore) and - (hyphen). And must not begin with a hyphen'
'Valid characters are a-z, A-Z, 0-9, _ (underscore) and - (hyphen). And must not begin with a hyphen',
);
}
if (errors.length > 0) {
Expand All @@ -259,7 +259,7 @@ export class Prompt extends Construct implements IPrompt {
const errors: string[] = [];
if (this.variants.length > MAX_VARIANTS) {
errors.push(
`Error: Too many variants specified. The maximum allowed is ${MAX_VARIANTS}, but you have provided ${this.variants.length} variants.`
`Error: Too many variants specified. The maximum allowed is ${MAX_VARIANTS}, but you have provided ${this.variants.length} variants.`,
);
}
return errors;
Expand Down
22 changes: 11 additions & 11 deletions test/cdk-lib/bedrock/prompts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Prompt', () => {
Name: 'prompt1',
Description: 'my cmk prompt',
CustomerEncryptionKeyArn: cmk.keyArn,
})
}),
);
expect(prompt.promptName).toEqual('prompt1');
});
Expand All @@ -62,7 +62,7 @@ describe('Prompt', () => {
const variant1 = PromptVariant.text({
variantName: 'variant1',
model: BedrockFoundationModel.fromCdkFoundationModelId(
cdk_bedrock.FoundationModelIdentifier.ANTHROPIC_CLAUDE_3_SONNET_20240229_V1_0
cdk_bedrock.FoundationModelIdentifier.ANTHROPIC_CLAUDE_3_SONNET_20240229_V1_0,
),
promptVariables: ['topic'],
promptText: 'This is my first text prompt. Please summarize our conversation on {{topic}}.',
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('Prompt', () => {
TemplateType: 'TEXT',
},
],
})
}),
);
});

Expand Down Expand Up @@ -155,7 +155,7 @@ describe('Prompt', () => {
TemplateType: 'TEXT',
},
],
})
}),
);
});

Expand Down Expand Up @@ -294,7 +294,7 @@ describe('Prompt', () => {
TemplateType: 'CHAT',
},
],
})
}),
);
});

Expand Down Expand Up @@ -349,7 +349,7 @@ describe('Prompt', () => {
TemplateType: 'TEXT',
},
],
})
}),
);
});

Expand All @@ -368,12 +368,12 @@ describe('Prompt', () => {
haveResource('AWS::Bedrock::Prompt', {
Name: 'prompt1',
Description: 'my versioned prompt',
})
}),
);
cdkExpect(stack).to(
haveResource('AWS::Bedrock::PromptVersion', {
Description: 'first version',
})
}),
);
});

Expand All @@ -395,7 +395,7 @@ describe('Prompt', () => {
PromptVariant.text({
variantName: `variant${id}`,
model: BedrockFoundationModel.fromCdkFoundationModelId(
cdk_bedrock.FoundationModelIdentifier.ANTHROPIC_CLAUDE_3_SONNET_20240229_V1_0
cdk_bedrock.FoundationModelIdentifier.ANTHROPIC_CLAUDE_3_SONNET_20240229_V1_0,
),
promptVariables: ['topic'],
promptText: `This is my text prompt ${id}. Please summarize our conversation on {{topic}}.`,
Expand All @@ -404,7 +404,7 @@ describe('Prompt', () => {
topP: 0.999,
maxTokens: 2000,
},
})
}),
);
new Prompt(stack, 'prompt1', {
promptName: 'my-prompt',
Expand All @@ -413,7 +413,7 @@ describe('Prompt', () => {
});
// THEN
expect(() => app.synth()).toThrow(
'Error: Too many variants specified. The maximum allowed is 3, but you have provided 4 variants.'
'Error: Too many variants specified. The maximum allowed is 3, but you have provided 4 variants.',
);
});
});
Expand Down

0 comments on commit 39c6440

Please sign in to comment.