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

Complete OpenAI to AWS Bedrock conversion #64

Merged
merged 11 commits into from
Jan 8, 2025

Conversation

yuzisun
Copy link
Contributor

@yuzisun yuzisun commented Jan 5, 2025

  • Complete OpenAI Chat completion and AWSBedrock Converse type definition
  • Additional conversion for InferenceConfiguration and ToolConfig
  • Error handling and convert to OpenAI error
  • Convert to table testing and add more tests

internal/apischema/awsbedrock/awsbedrock.go Outdated Show resolved Hide resolved
internal/extproc/translator/openai_awsbedrock.go Outdated Show resolved Hide resolved
@mathetake
Copy link
Member

@yuzisun the e2e tests are failing https://github.com/envoyproxy/ai-gateway/actions/runs/12624576475/job/35175024164?pr=64 due to some parsing errors

t.Run("health-checking", func(t *testing.T) {
client := openai.NewClient(option.WithBaseURL("http://localhost:1062/v1/"))
for _, tc := range []struct {
testCaseName,
modelName string
}{
{testCaseName: "openai", modelName: "gpt-4o-mini"}, // This will go to "openai"
{testCaseName: "aws-bedrock", modelName: "us.meta.llama3-2-1b-instruct-v1:0"}, // This will go to "aws-bedrock".
} {
t.Run(tc.modelName, func(t *testing.T) {
require.Eventually(t, func() bool {
chatCompletion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
Messages: openai.F([]openai.ChatCompletionMessageParamUnion{
openai.UserMessage("Say this is a test"),
}),
Model: openai.F(tc.modelName),
})
if err != nil {
t.Logf("error: %v", err)
return false
}
for _, choice := range chatCompletion.Choices {
t.Logf("choice: %s", choice.Message.Content)
}
return true
}, 10*time.Second, 1*time.Second)
})
}
})

@yuzisun
Copy link
Contributor Author

yuzisun commented Jan 6, 2025

@yuzisun the e2e tests are failing https://github.com/envoyproxy/ai-gateway/actions/runs/12624576475/job/35175024164?pr=64 due to some parsing errors

t.Run("health-checking", func(t *testing.T) {
client := openai.NewClient(option.WithBaseURL("http://localhost:1062/v1/"))
for _, tc := range []struct {
testCaseName,
modelName string
}{
{testCaseName: "openai", modelName: "gpt-4o-mini"}, // This will go to "openai"
{testCaseName: "aws-bedrock", modelName: "us.meta.llama3-2-1b-instruct-v1:0"}, // This will go to "aws-bedrock".
} {
t.Run(tc.modelName, func(t *testing.T) {
require.Eventually(t, func() bool {
chatCompletion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
Messages: openai.F([]openai.ChatCompletionMessageParamUnion{
openai.UserMessage("Say this is a test"),
}),
Model: openai.F(tc.modelName),
})
if err != nil {
t.Logf("error: %v", err)
return false
}
for _, choice := range chatCompletion.Choices {
t.Logf("choice: %s", choice.Message.Content)
}
return true
}, 10*time.Second, 1*time.Second)
})
}
})

Ah looks like you are using the new type ChatCompletionNewParams instead of ChatCompletion in the test.

@mathetake
Copy link
Member

mathetake commented Jan 6, 2025

yeah - so we need basically the manual type checking logic to support unions on .contents to be compatible with openai i guess. the ChatCompletionNewParams can actually be accepted by them and that use is the example from go-sdk https://github.com/openai/openai-go?tab=readme-ov-file#usage

@mathetake
Copy link
Member

you can ignore Tests using Secrets / External Processor (pull_request) (fixed in #68) and Tests using Secrets / External Processor (pull_request_target) is what matters. It's still failing but it seems almost there?

@yuzisun
Copy link
Contributor Author

yuzisun commented Jan 7, 2025

you can ignore Tests using Secrets / External Processor (pull_request) (fixed in #68) and Tests using Secrets / External Processor (pull_request_target) is what matters. It's still failing but it seems almost there?

@mathetake The new schema is quite complex which took me a little more time, unfortunately we have to manually craft the types as openai-go did not expose the unmarshall APIs. I need to run the e2e test again, how do I trigger it ?

internal/extproc/processor.go Outdated Show resolved Hide resolved
internal/extproc/processor.go Outdated Show resolved Hide resolved
internal/extproc/translator/openai_awsbedrock.go Outdated Show resolved Hide resolved
Signed-off-by: Takeshi Yoneda <[email protected]>
@mathetake
Copy link
Member

@yuzisun thank you for the excellent job here!!

@mathetake mathetake merged commit cb6b2e0 into envoyproxy:main Jan 8, 2025
8 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.

3 participants