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

translator: handling for OpenAI and AWSBedrock error response #152

Merged
merged 10 commits into from
Jan 23, 2025

Conversation

yuzisun
Copy link
Contributor

@yuzisun yuzisun commented Jan 21, 2025

Add handling for the OpenAI and Bedrock error response. Currently when error response is returned it fails on decoding the ConverseOutput or OpenAIChatCompletionResponse as it is assuming a 200 response.

For AWSBedrock the error response is converted to OpenAIError type when returning to the user. For OpenAI error response we return directly back without translation. In case of connection errors to the AWS Bedrock or OpenAI backend, we translate to OpenAIError type based on the status code and message body.

fixes #133

@yuzisun yuzisun requested a review from a team as a code owner January 21, 2025 03:29
@yuzisun yuzisun changed the title Translator: handling for OpenAI and AWSBedrock error response translator: handling for OpenAI and AWSBedrock error response Jan 21, 2025
@mathetake
Copy link
Member

can you fix the e2e

Comment on lines 389 to 391
if v, ok := headers[statusHeaderName]; ok && v != string(typev3.StatusCode_OK) {
return nil, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this is not necessary or should be panic... if we reach this, that means a bug in extproc code

Copy link
Contributor Author

@yuzisun yuzisun Jan 22, 2025

Choose a reason for hiding this comment

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

Actually for header processing we need this check otherwise it continues processing the event stream header mutation.

Copy link
Member

Choose a reason for hiding this comment

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

unnecessary change?

@mathetake
Copy link
Member

so i made it easy to add the end-to-end transformation testing with testupstream here:

for _, tc := range []struct {

feel free to add more cases to cover this case (maybe some fix might be necessary for the test as well as testupstream)

Signed-off-by: Dan Sun <[email protected]>
@yuzisun yuzisun force-pushed the rename branch 2 times, most recently from 425230d to 7acccb4 Compare January 22, 2025 09:21
Signed-off-by: Dan Sun <[email protected]>
Signed-off-by: Dan Sun <[email protected]>
@mathetake mathetake self-assigned this Jan 22, 2025
@yuzisun yuzisun force-pushed the rename branch 4 times, most recently from 675ee46 to 8b1c09d Compare January 22, 2025 23:46
Comment on lines 390 to 394
if v, err := strconv.Atoi(v); err == nil {
if !isGoodStatusCode(v) {
return nil, nil
}
}
Copy link
Member

Choose a reason for hiding this comment

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

also i am still not sure why if this is a bad status code we can continue and when good we return early. could you put the detailed code comments. This will be hard to understand by anyone without the extensive knowledge. I believe the comments will be helpful for future contributors (including me!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I rewrote the code in a way that it does not require this logic. Before it incorrectly returns a content type check error on error response. I am not a fan of writing too much code comments which means the code is not self-explainable.

Copy link
Member

@mathetake mathetake left a comment

Choose a reason for hiding this comment

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

LGTM modulo i need code comments!

@yuzisun
Copy link
Contributor Author

yuzisun commented Jan 23, 2025

so i made it easy to add the end-to-end transformation testing with testupstream here:

for _, tc := range []struct {

feel free to add more cases to cover this case (maybe some fix might be necessary for the test as well as testupstream)

Added the tests all ready to go

@mathetake
Copy link
Member

Will take a look with an hour!

@mathetake mathetake merged commit 5ac9370 into envoyproxy:main Jan 23, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error handling for aws bedrock and openai response
2 participants