Skip to content

Commit

Permalink
Merge branch 'develop' v0.7.12
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Strahan committed Feb 21, 2025
2 parents b6bb5da + a75d4e6 commit 9f89e57
Show file tree
Hide file tree
Showing 20 changed files with 875 additions and 875 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ build
/sample-data
.vscode
/pca-ui/src/witch/witch.zip
.DS_Store
.idea/
pca-ssm/.DS_Store
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.7.12] - 2025-02-21

### Added
- Added support for Amazon Nova models (amazon.nova-micro-v1:0, amazon.nova-lite-v1:0, amazon.nova-pro-v1:0) - PR #295
- Updated Anthropic Claude models to the latest 3.5 versions (anthropic.claude-3-5-haiku-20241022-v1:0, anthropic.claude-3-5-sonnet-20241022-v2:0) - PR #295
- Removed older versions of Amazon Titan and Anthropic Claude models (amazon.titan-text-express-v1, anthropic.claude-v1, anthropic.claude-instant-v1, anthropic.claude-v2) - PR #295
- Refactored Bedrock calls to use the Converse API eliminating the need for custom model specific payloads - PR #295
- Refactored all model invocation to use Inference Profiles. This is required for Nova models. It is also applied to Anthropic models for consistency and improved scalability. - PR #295
- Added adaptive retry configuration to Bedrock api calls to add some tolerance for quota throttling exceptions (at the expense of latency) - PR #295

### Fixed
- Fixed: Only one PCA stack may be sucessfully deployed in a given account/region due to fixed SSM parameter names - PR #291, #293
- Fixed: Current publish.sh does not work with ARM chipsets such as the Apple M series. Set x86_64 arch for local build - PR #288


## [0.7.11] - 2024-10-09

### Added
Expand Down Expand Up @@ -275,6 +290,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Initial release

[Unreleased]: https://github.com/aws-samples/amazon-transcribe-post-call-analytics/compare/main...develop
[0.7.12]: https://github.com/aws-samples/amazon-transcribe-post-call-analytics/releases/tag/v0.7.12
[0.7.11]: https://github.com/aws-samples/amazon-transcribe-post-call-analytics/releases/tag/v0.7.11
[0.7.10]: https://github.com/aws-samples/amazon-transcribe-post-call-analytics/releases/tag/v0.7.10
[0.7.9]: https://github.com/aws-samples/amazon-transcribe-post-call-analytics/releases/tag/v0.7.9
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.11
0.7.12
162 changes: 76 additions & 86 deletions pca-main-nokendra.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AWSTemplateFormatVersion: "2010-09-09"

Description: Amazon Transcribe Post Call Analytics - PCA (v0.7.11) (uksb-1sn29lk73, SO9071)
Description: Amazon Transcribe Post Call Analytics - PCA (v0.7.12) (uksb-1sn29lk73, SO9071)

Parameters:

Expand Down Expand Up @@ -352,10 +352,10 @@ Parameters:
- PROD
Default: PROD

DatabaseName:
GlueDatabaseName:
Type: String
Default: 'pca'
Description: Glue catalog database name used to contain tables/views for SQL integration.
AllowedPattern: "^$|[a-z0-9_-]+"
Description: (Optional) Glue catalog database name in lowercase characters used to contain tables/views for SQL integration.

EnablePcaDashboards:
Type: String
Expand Down Expand Up @@ -384,14 +384,17 @@ Parameters:

GenAIQueryBedrockModelId:
Type: String
Default: anthropic.claude-3-haiku-20240307-v1:0
Default: us.amazon.nova-lite-v1:0
AllowedValues:
- anthropic.claude-3-haiku-20240307-v1:0
- anthropic.claude-3-sonnet-20240229-v1:0
- amazon.titan-text-express-v1
- anthropic.claude-v1
- anthropic.claude-instant-v1
- anthropic.claude-v2
- us.amazon.nova-micro-v1:0
- us.amazon.nova-lite-v1:0
- us.amazon.nova-pro-v1:0
- us.anthropic.claude-3-5-haiku-20241022-v1:0
- us.anthropic.claude-3-5-sonnet-20241022-v2:0
- eu.anthropic.claude-3-5-sonnet-20240620-v1:0
- apac.anthropic.claude-3-5-sonnet-20240620-v1:0
Description: (Optional) If 'GenAIQuery' is BEDROCK, which Bedrock model to use.

CallSummarization:
Expand All @@ -417,14 +420,17 @@ Parameters:

SummarizationBedrockModelId:
Type: String
Default: anthropic.claude-3-haiku-20240307-v1:0
Default: us.amazon.nova-lite-v1:0
AllowedValues:
- anthropic.claude-3-haiku-20240307-v1:0
- anthropic.claude-3-sonnet-20240229-v1:0
- amazon.titan-text-express-v1
- anthropic.claude-v1
- anthropic.claude-instant-v1
- anthropic.claude-v2
- us.amazon.nova-micro-v1:0
- us.amazon.nova-lite-v1:0
- us.amazon.nova-pro-v1:0
- us.anthropic.claude-3-5-haiku-20241022-v1:0
- us.anthropic.claude-3-5-sonnet-20241022-v2:0
- eu.anthropic.claude-3-5-sonnet-20240620-v1:0
- apac.anthropic.claude-3-5-sonnet-20240620-v1:0
Description: (Optional) If 'CallSummarization' is BEDROCK, which Bedrock model to use.

TestBedrockModelId:
Expand Down Expand Up @@ -495,7 +501,7 @@ Metadata:
default: Advanced analytics and reporting
Parameters:
- EnablePcaDashboards
- DatabaseName
- GlueDatabaseName
- Label:
default: S3 Bucket Names and Retention Policy
Parameters:
Expand Down Expand Up @@ -673,6 +679,19 @@ Resources:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256

########################################################
# Glue Database
########################################################

PCADatabase:
Type: AWS::Glue::Database
Properties:
CatalogId: !Ref AWS::AccountId
DatabaseInput:
Name: !Ref GlueDatabaseName
Description: Post Call Analytics
LocationUri: !Sub 's3://${OutputBucket}/${OutputBucketParsedResults}/'

########################################################
# If Bedrock Models are selected, verify that Bedrock
# is available in the region, and that models are enabled
Expand Down Expand Up @@ -701,6 +720,12 @@ Resources:
Resource:
- !Sub "arn:${AWS::Partition}:bedrock:*::foundation-model/*"
- !Sub "arn:${AWS::Partition}:bedrock:*:${AWS::AccountId}:custom-model/*"
- !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:inference-profile/*"
- Effect: Allow
Action:
- "bedrock:GetInferenceProfile"
Resource:
- !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:inference-profile/*"
PolicyName: BedrockPolicy

TestBedrockModelFunction:
Expand All @@ -723,76 +748,38 @@ Resources:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--target', '/tmp', 'boto3'])
sys.path.insert(0,'/tmp')
import boto3

from botocore.config import Config

# Defaults
AWS_REGION = os.environ["AWS_REGION_OVERRIDE"] if "AWS_REGION_OVERRIDE" in os.environ else os.environ["AWS_REGION"]
ENDPOINT_URL = os.environ.get("ENDPOINT_URL", f'https://bedrock-runtime.{AWS_REGION}.amazonaws.com')
DEFAULT_MAX_TOKENS = 128

def get_request_body(modelId, parameters, prompt):
provider = modelId.split(".")[0]
request_body = None
if provider == "anthropic":
if 'claude-3' in modelId:
request_body = {
"max_tokens": DEFAULT_MAX_TOKENS,
"messages": [{"role": "user", "content": prompt}],
"anthropic_version": "bedrock-2023-05-31"
}
else:
request_body = {
"prompt": prompt,
"max_tokens_to_sample": DEFAULT_MAX_TOKENS
}

request_body.update(parameters)
elif provider == "ai21":
request_body = {
"prompt": prompt,
"maxTokens": DEFAULT_MAX_TOKENS
}
request_body.update(parameters)
elif provider == "amazon":
textGenerationConfig = {
"maxTokenCount": DEFAULT_MAX_TOKENS
}
textGenerationConfig.update(parameters)
request_body = {
"inputText": prompt,
"textGenerationConfig": textGenerationConfig
def get_generate_text(response):
return response["output"]["message"]["content"][0]["text"]

def call_llm(prompt, modelId):
client = boto3.client(
service_name='bedrock-runtime',
region_name=AWS_REGION,
endpoint_url=ENDPOINT_URL,
config=Config(retries={'max_attempts': 50, 'mode': 'adaptive'})
)

message = {
'role': 'user',
'content': [{'text': prompt}]
}

response = client.converse(
modelId=modelId,
messages=[message],
inferenceConfig={
'maxTokens': DEFAULT_MAX_TOKENS,
'temperature': 0
}
else:
raise Exception("Unsupported provider: ", provider)
return request_body

def get_generate_text(modelId, response):
provider = modelId.split(".")[0]
generated_text = None
if provider == "anthropic":
if 'claude-3' in modelId:
response_raw = json.loads(response.get("body").read().decode())
generated_text = response_raw.get('content')[0].get('text')

else:
response_body = json.loads(response.get("body").read().decode())
generated_text = response_body.get("completion")
elif provider == "ai21":
response_body = json.loads(response.get("body").read())
generated_text = response_body.get("completions")[0].get("data").get("text")
elif provider == "amazon":
response_body = json.loads(response.get("body").read())
generated_text = response_body.get("results")[0].get("outputText")
else:
raise Exception("Unsupported provider: ", provider)
return generated_text

def call_llm(parameters, prompt):
modelId = parameters.pop("modelId")
body = get_request_body(modelId, parameters, prompt)
print("ModelId", modelId, "- Body: ", body)
client = boto3.client(service_name='bedrock-runtime', region_name=AWS_REGION, endpoint_url=ENDPOINT_URL)
response = client.invoke_model(body=json.dumps(body), modelId=modelId, accept='application/json', contentType='application/json')
generated_text = get_generate_text(modelId, response)
)
generated_text = get_generate_text(response)
return generated_text

def lambda_handler(event, context):
Expand All @@ -808,12 +795,8 @@ Resources:
# Test LLMModel
llmModelId = event['ResourceProperties'].get('LLMModelId', '')
modelId = llmModelId
parameters = {
"modelId": modelId,
"temperature": 0
}
print(f"Testing {modelId}")
call_llm(parameters, prompt)
call_llm(prompt, modelId)
except Exception as e:
status = cfnresponse.FAILED
reason = f"Exception thrown testing ModelId='{modelId}'. Check that Amazon Bedrock is available in your region, and that model is activated in your Amazon Bedrock account - {e}"
Expand Down Expand Up @@ -848,6 +831,7 @@ Resources:
Properties:
TemplateURL: pca-ssm/cfn/ssm.template
Parameters:
StackName: !Ref 'AWS::StackName'
BulkUploadBucketName:
!If
- ShouldCreateBulkUploadBucket
Expand Down Expand Up @@ -911,13 +895,15 @@ Resources:
- 'None'
- 'None'
# WebUri: !GetAtt PCAUI.Outputs.WebUri
DatabaseName: !Ref DatabaseName
DatabaseName: !Ref PCADatabase

PythonUtilsLayer:
DependsOn: SSM
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: pca-server/cfn/lib/python-utilities.template
Parameters:
ParentStackName: !Ref 'AWS::StackName'

BedrockBoto3Layer:
Type: AWS::CloudFormation::Stack
Expand All @@ -944,6 +930,8 @@ Resources:
Properties:
TemplateURL: pca-server/cfn/pca-server.template
Parameters:
DatabaseName: !Ref PCADatabase
ParentStackName: !Ref 'AWS::StackName'
ffmpegDownloadUrl: !Ref ffmpegDownloadUrl
CallSummarization: !Ref CallSummarization
SummarizationBedrockModelId: !Ref SummarizationBedrockModelId
Expand All @@ -966,6 +954,7 @@ Resources:
Properties:
TemplateURL: pca-ui/cfn/pca-ui.template
Parameters:
ParentStackName: !Ref 'AWS::StackName'
AdminUsername: !Ref AdminUsername
AdminEmail: !Ref AdminEmail
AllowedSignUpEmailDomain: !Ref AllowedSignUpEmailDomain
Expand Down Expand Up @@ -1005,7 +994,7 @@ Resources:
Properties:
TemplateURL: build/pca-dashboards.yaml
Parameters:
PcaGlueCatalogDatabaseName: !Ref DatabaseName
PcaGlueCatalogDatabaseName: !Ref PCADatabase
PcaOutputBucket:
!If
- ShouldCreateOutputBucket
Expand All @@ -1023,6 +1012,7 @@ Resources:
Properties:
TemplateURL: pca-samples/copy-samples.template
Parameters:
ParentStackName: !Ref 'AWS::StackName'
DependsOnPCAServer: !Ref PCAServer
DependsOnPCAUI: !If [ShouldEnableGui, !Ref PCAUI, !Ref AWS::NoValue]
DependsOnPCADashboards: !If
Expand Down
Loading

0 comments on commit 9f89e57

Please sign in to comment.