Conversation
Summary of ChangesHello @levigross, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request lays the groundwork for integrating OpenAI models into the system. It establishes the necessary components to send requests, process responses, and manage streaming interactions with OpenAI's API, ensuring compatibility with existing LLM interfaces. The current implementation focuses on core generation capabilities, with plans to extend support for advanced features like tool calling in future iterations. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces basic support for the OpenAI API by creating an adapter that conforms to the project's model.LLM interface. The implementation is well-structured, separating concerns like request building, response parsing, and stream handling into their own files. However, I've identified a few critical issues, including a couple of compilation errors and incorrect pointer semantics in the model constructor. I also found a potential race condition in stream handling and a gap in error handling for function call tracking. Addressing these points will significantly improve the robustness and correctness of this new integration.
| return m.generate(ctx, params) | ||
| } | ||
|
|
||
| func (m *openAIModel) generate(ctx context.Context, params responses.ResponseNewParams) iter.Seq2[*model.LLMResponse, error] { |
There was a problem hiding this comment.
Could you please support chat completion? it's better for compatible with most providers.
This PR enables basic support for OpenAI models (and endpoints that expose a OpenAI API compatible API interface). I am stressing on *basic* support because we will leave tool calling to the next PR :)
|
@gemini-code-assist please rereview this code |
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive and well-structured adapter for the OpenAI API, implementing the model.LLM interface. The implementation covers request and response conversion, streaming support, and robust error handling for unsupported features. The code is well-tested with good unit and integration test coverage.
My main feedback is a critical issue in NewModel that will prevent compilation due to an attempt to access an unexported field on the openai.Client struct. I've provided suggestions to refactor this to use a pointer to the client, which is a more idiomatic and robust approach for validation in Go. Once this is addressed, the package should be in great shape.
| func NewModel(_ context.Context, modelName string, client openai.Client) (model.LLM, error) { | ||
| // We drop the context because OpenAI doesn't take a context when creating a new Client | ||
| if modelName == "" { | ||
| return nil, ErrModelNameRequired | ||
| } | ||
| if len(client.Options) == 0 { | ||
| return nil, ErrClientRequired | ||
| } | ||
| return &openAIModel{ | ||
| client: &client, | ||
| name: modelName, | ||
| }, nil |
There was a problem hiding this comment.
To fix the compilation issue with client.Options and improve the function's contract, the signature of NewModel should be changed to accept a pointer to an openai.Client. This allows for a nil check to validate the client's presence.
Consequently, the openAIModel struct should store this pointer directly.
| func NewModel(_ context.Context, modelName string, client openai.Client) (model.LLM, error) { | |
| // We drop the context because OpenAI doesn't take a context when creating a new Client | |
| if modelName == "" { | |
| return nil, ErrModelNameRequired | |
| } | |
| if len(client.Options) == 0 { | |
| return nil, ErrClientRequired | |
| } | |
| return &openAIModel{ | |
| client: &client, | |
| name: modelName, | |
| }, nil | |
| func NewModel(_ context.Context, modelName string, client *openai.Client) (model.LLM, error) { | |
| // We drop the context because OpenAI doesn't take a context when creating a new Client | |
| if modelName == "" { | |
| return nil, ErrModelNameRequired | |
| } | |
| if client == nil { | |
| return nil, ErrClientRequired | |
| } | |
| return &openAIModel{ | |
| client: client, | |
| name: modelName, | |
| }, nil | |
| } |
| option.WithBaseURL(server.URL+"/v1"), | ||
| ) | ||
|
|
||
| llm, err := NewModel(t.Context(), openai.ChatModelGPT4oMini, client) |
There was a problem hiding this comment.
| tests := []struct { | ||
| name string | ||
| modelName openai.ChatModel | ||
| client openai.Client | ||
| wantErr error | ||
| }{ | ||
| { | ||
| name: "missing model name", | ||
| modelName: "", | ||
| client: client, | ||
| wantErr: ErrModelNameRequired, | ||
| }, | ||
| { | ||
| name: "missing client", | ||
| modelName: openai.ChatModelGPT4o, | ||
| client: openai.Client{}, | ||
| wantErr: ErrClientRequired, | ||
| }, | ||
| } |
There was a problem hiding this comment.
Following the suggested change in openai.go to use a pointer for the openai.Client, this test table needs to be updated to reflect the new signature of NewModel. The client field in the test struct should be a pointer, and the test cases should be adjusted accordingly. For the "missing client" case, nil should be passed to trigger ErrClientRequired.
| tests := []struct { | |
| name string | |
| modelName openai.ChatModel | |
| client openai.Client | |
| wantErr error | |
| }{ | |
| { | |
| name: "missing model name", | |
| modelName: "", | |
| client: client, | |
| wantErr: ErrModelNameRequired, | |
| }, | |
| { | |
| name: "missing client", | |
| modelName: openai.ChatModelGPT4o, | |
| client: openai.Client{}, | |
| wantErr: ErrClientRequired, | |
| }, | |
| } | |
| tests := []struct { | |
| name string | |
| modelName openai.ChatModel | |
| client *openai.Client | |
| wantErr error | |
| }{ | |
| { | |
| name: "missing model name", | |
| modelName: "", | |
| client: &client, | |
| wantErr: ErrModelNameRequired, | |
| }, | |
| { | |
| name: "missing client", | |
| modelName: openai.ChatModelGPT4o, | |
| client: nil, | |
| wantErr: ErrClientRequired, | |
| }, | |
| } |
|
@dpasiukevich What do I need to do to get this PR reviewed? 😀 |
|
Thank you for contributing this PR to add support for the OpenAI API! This is a highly valuable feature that will greatly improve the flexibility of the project. |
1 similar comment
|
Thank you for contributing this PR to add support for the OpenAI API! This is a highly valuable feature that will greatly improve the flexibility of the project. |
|
hi, any updates on this? |
|
hi, any updates ? |
|
There are currently two PRs under review and one third-party implementation:
Since the review process for both PRs seems to be lagging, could we merge a basic feature set first and improve it incrementally later? I realize that achieving full OpenAI API compatibility is a significant undertaking, and starting with a core version might be more efficient. @byebyebruce |
|
Folks, sry for the lack of reply here. We're a bit not sure on the best mechanism for long-term support of ecosystem models, let's redirect this to adk-go-community repo to unblock for now. |
|
Let me setup the https://github.com/google/adk-go-community and return back here. Let's keep and grow the stuff there with more models, tools, plugins etc. |
|
@dpasiukevich |
|
邮件已收到!我会尽快给您回复。
|
Gentle reminder: Is the adk-go-community repository still coming, or has the decision changed? |
|
Any updates on the way forward? |
|
Same here, any updates on this? |
|
Any updates? guys |
This PR enables basic support for OpenAI models (and endpoints that expose a OpenAI API compatible API interface).
I am stressing on basic support because we will leave tool calling to the next PR :)