-
Notifications
You must be signed in to change notification settings - Fork 64
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
Stream conversation logs in sandbox #2073
Conversation
🦋 Changeset detectedLatest commit: 88544ca The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/ai-constructs/API.md
Outdated
@@ -49,6 +51,7 @@ type ConversationHandlerFunctionProps = { | |||
modelId: string; | |||
region?: string; | |||
}>; | |||
outputStorageStrategy?: BackendOutputStorageStrategy<FunctionOutput>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is similar to what data and auth construct do.
amplify-backend/packages/auth-construct/src/types.ts
Lines 472 to 475 in 27202b4
/** | |
* @internal | |
*/ | |
outputStorageStrategy?: BackendOutputStorageStrategy<AuthOutput>; |
new GetFunctionCommand({ | ||
FunctionName: functionName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already do have permissions to call GetFunction
in AmplifyBackendDeployFullAccess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason we went with ListTags
earlier was for performance reasons, since it will be called after each sandbox deployment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was ListTags
significantly faster than GetFunction
?
Some considerations:
- The number of requests to lambda CP doesn't change. We were calling
ListTags
per each function. - We eliminated extra CloudFormation calls to resolve ARNs.
- The alternative would be to call
GetFunctionConfiguration
in addition toListTags
. But, making two requests is not great quota and latency wise. - It seems that default quota for
GetFunction
is much more generous than other CP APIs. See picture below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Synced offline. We'll keep GetFunction
given that alternatives are not better.
outputStorageStrategy?.appendToBackendOutputList(functionOutputKey, { | ||
version: '1', | ||
payload: { | ||
definedFunctions: this.resources.lambda.functionName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this is not a definedFunction
. We should store this under it's own AIConstructOutputKey.
@@ -67,6 +86,7 @@ export class ConversationHandlerFunction | |||
// For custom entry we do bundle SDK as we can't control version customer is coding against. | |||
bundleAwsSDK: !!this.props.entry, | |||
}, | |||
loggingFormat: LoggingFormat.JSON, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be able to actually see the debug logs, don't we need to also expose the ApplicationLogLevel
property so customers can configure it? if I recall cdk sets the default as INFO
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. I called this out in the "Out of scope" section in the PR description.
Co-authored-by: Amplifiyer <[email protected]>
This reverts commit 3e8b590.
This reverts commit 3c2d417.
/** | ||
* Expected key that AI conversation output is stored under | ||
*/ | ||
export const aiConversationOutputKey = 'AWS::Amplify::AI::Conversation'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the naming here follows ai-constructs/<sub_usecase>
I.e. if we add another AI feature not related to conversation we'd have AWS::Amplify::AI::SomethingNew
…logging-improvements
Problem
Conversation handler logs should show up when executing
npx ampx sandbox --stream-function-logs
.Changes
This PR makes the following changes to stream and improve logs in conversation handler.
json
as opposed totext
(which doesn't support application log levels).info
anddebug
logs around incoming event, bedrock invocations, tools invocation, emitting response. Debug logs dump request/response payloads./aws/lambda/<functionName>
. This however won't work for conversation handler (and later if we expose knobs related to logging configuration.<functionName>
to mimic default convention, but the problem is that log group is input to function ctor, therefore it's impossible to use function's properties to create log group (as this happens first). The only alternative I found was to generate function name ourselves, but that wasn't great either - components used by function ctor internally are not available to us, so if we generate name it would look differently than other functions. Hence I figured that it's better to just make sandbox support arbitrary log group.ListTags
call in Sandbox is replaced byGetFunction
which gives both information that we need -tags
andlogGroupName
. TheAmplifyBackendDeployFullAccess
already has necessary permissions to callGetFunction
.backend-ai
toai-construct
. So that data construct can passoutputStrategy
to it in default scenario.Out of scope
outputStrategy
to ai construct. The necessary plumbing on data side will be pursued separately. The idea was validated by a temporary change (reverted here)Validation
Manual check with default
info
level:Manual check with log level set to
debug
via AWS Console:Checklist
run-e2e
label set.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.