Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: plumb outputStorageStrategy through conversation transformer to handler #3017

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

atierian
Copy link
Member

@atierian atierian commented Nov 12, 2024

Problem

The default lambda handler deployed for conversation routes via ai-constructs doesn't stream function logs for sandbox deployments when using the --stream-function-logs flag (documentation).

Description of changes

  • Plumb outputStorageStrategy from AmplifyGraphqlApi through the ConversationTransformer to ai-constructs.

This allows ai-constructs to include the conversation handler Lambda function in the root stack outputs for streaming.

Note

#3014 contains an alternative approach that also works, but involves duplicating the types into amplify-graphql-transformer-interfaces.

Relevant Backend PR

CDK / CloudFormation Parameters Changed

N/A

Issue #, if available

N/A

Description of how you validated changes

Manually tested. E2E test not feasible as construct only test; will look into options for automated testing in a follow up.

> npx ampx sandbox --identifier 'logs' --stream-function-logs
[Sandbox] Watching for file changes...
File written: amplify_outputs.json
# Send a message
[AssistantChatDefaultConversationHandler] 1:24:17 PM {"time":"2024-11-12T18:24:17.783Z","type":"platform.initStart","record":{"initializationType":"on-demand","phase":"init","runtimeVersion":"nodejs:18.v49","runtimeVersionArn":"arn:aws:lambda:us-east-1::runtime:13821268cdb8b1fd3647b6b7f047e6989fdfa500ddcef1d207cab3e8aa30c617","functionName":"amplify-aismoketest-logs--AssistantChatDefaultConv-UxEQSg3XTyhZ","functionVersion":"$LATEST"}}
[AssistantChatDefaultConversationHandler] 1:24:18 PM {"time":"2024-11-12T18:24:18.153Z","type":"platform.start","record":{"requestId":"a9007650-3fad-4370-990c-db6646476e8e","version":"$LATEST"}}
[AssistantChatDefaultConversationHandler] 1:24:18 PM {"timestamp":"2024-11-12T18:24:18.154Z","level":"INFO","requestId":"a9007650-3fad-4370-990c-db6646476e8e","message":"Handling conversation turn event, currentMessageId=cd831839-7a3e-42fb-8a45-eb302c33a5ca, conversationId=21c3ec83-c701-4ae9-8b7a-386e36f346b2"}
[AssistantChatDefaultConversationHandler] 1:24:18 PM {"timestamp":"2024-11-12T18:24:18.605Z","level":"INFO","requestId":"a9007650-3fad-4370-990c-db6646476e8e","message":"Sending Bedrock Converse Stream request"}
[AssistantChatDefaultConversationHandler] 1:24:18 PM {"timestamp":"2024-11-12T18:24:18.868Z","level":"INFO","requestId":"a9007650-3fad-4370-990c-db6646476e8e","message":"Received Bedrock Converse Stream response, requestId=a74da7bf-8f48-497d-8977-930d7f1a709b"}
[AssistantChatDefaultConversationHandler] 1:24:24 PM {"timestamp":"2024-11-12T18:24:24.254Z","level":"INFO","requestId":"a9007650-3fad-4370-990c-db6646476e8e","message":"Conversation turn event handled successfully, currentMessageId=cd831839-7a3e-42fb-8a45-eb302c33a5ca, conversationId=21c3ec83-c701-4ae9-8b7a-386e36f346b2"}
[AssistantChatDefaultConversationHandler] 1:24:24 PM {"time":"2024-11-12T18:24:24.257Z","type":"platform.report","record":{"requestId":"a9007650-3fad-4370-990c-db6646476e8e","metrics":{"durationMs":6104.742,"billedDurationMs":6105,"memorySizeMB":512,"maxMemoryUsedMB":124,"initDurationMs":368.411},"status":"success"}}

Checklist

  • PR description included
  • yarn test passes
  • E2E test run linked
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)
  • New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies
  • Any CDK or CloudFormation parameter changes are called out explicitly

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@atierian atierian marked this pull request as ready for review November 12, 2024 19:29
@atierian atierian requested review from a team as code owners November 12, 2024 19:29
sobolk
sobolk previously approved these changes Nov 12, 2024
@@ -35,7 +35,8 @@
"graphql-mapping-template": "5.0.1",
"graphql-transformer-common": "5.1.1",
"immer": "^9.0.12",
"semver": "^7.6.3"
"semver": "^7.6.3",
"@aws-amplify/plugin-types": "^1.0.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please sort dependencies

@@ -324,7 +324,7 @@ function transform(
hasManyTransformer,
hasOneTransformer,
belongsToTransformer,
new ConversationTransformer(modelTransformer, hasManyTransformer, belongsToTransformer, authTransformer, functionMap),
new ConversationTransformer(modelTransformer, hasManyTransformer, belongsToTransformer, authTransformer, undefined, functionMap),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't have to happen on this PR, but it's probably time to create a ConversationTransformerOptions type to support named inputs to the constructor -- the argument list is pretty unwieldy

@atierian atierian merged commit acc8140 into main Nov 13, 2024
7 checks passed
@atierian atierian deleted the ai.conversation-log-stream branch November 13, 2024 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants