-
Notifications
You must be signed in to change notification settings - Fork 72
feat(openai): implement llm client interface #276
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
feat(openai): implement llm client interface #276
Conversation
Summary of ChangesHello @kasanatte, 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's Large Language Model (LLM) capabilities into the AI Assistant. It establishes a robust and thread-safe mechanism for configuring and accessing the OpenAI API, which is a critical prerequisite for all future LLM-powered features. The changes focus on setting up the core client and configuration management without introducing any user-facing functionality yet. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds a new package to interface with the OpenAI API. The implementation is straightforward, using global variables and a mutex for configuration management. My review includes two main suggestions to improve the design. First, I recommend decoupling the new openai package from the application-specific options package by passing configuration primitives instead of the whole options struct. Second, for efficiency, I suggest caching the OpenAI client instance instead of creating a new one on every request. These changes will enhance the code's modularity, testability, and performance.
caf8ef9 to
4e832b4
Compare
pkg/openai/config.go
Outdated
| return nil, errors.New("OpenAI not initialized, call InitOpenAIConfig first") | ||
| } | ||
|
|
||
| if globalOpenAIOptions.OpenAIAPIKey == "" { |
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.
rename the key for LLMAPIKey
pkg/openai/config.go
Outdated
| } | ||
|
|
||
| config := openai.DefaultConfig(globalOpenAIOptions.OpenAIAPIKey) | ||
| if globalOpenAIOptions.OpenAIEndpoint != "" { |
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.
ditto
pkg/openai/config.go
Outdated
| ) | ||
|
|
||
| // InitOpenAIConfig initializes OpenAI configuration from Options. | ||
| func InitOpenAIConfig(opts *options.Options) { |
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.
rm the opts *options.Options
4e832b4 to
0e7dd31
Compare
0e7dd31 to
7b34d74
Compare
|
/gemini review |
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.
Code Review
This pull request introduces an interface for connecting to the OpenAI API, providing helper functions to create a configured OpenAI client based on the application's settings. The changes include renaming OpenAI to LLM to support more general LLMs, adding the go-openai library as a dependency, and implementing the core logic for initializing and retrieving the LLM client and model configuration. The code also includes unit and integration tests to ensure the functionality works as expected. I have identified some areas for improvement, primarily focusing on error handling and code clarity.
fc76f61 to
cea14b4
Compare
|
/assign |
|
@kasanatte it seems that there are some conflicts, plz resovle the conflicts first |
9fc865d to
d631d67
Compare
|
|
||
| // Sentinel errors for LLM package. | ||
| // These errors can be used with errors.Is() for error type checking. | ||
| var ( |
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.
good practice 👍
| arguments := request.Params.Arguments | ||
| message, ok := arguments["message"].(string) | ||
| if !ok { | ||
| message, err := request.RequireString("message") |
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.
cool ~ learn from that ~
|
thank, I think this PR is ready to be merged after the issues be resolved @kasanatte |
Signed-off-by: kasanatte <[email protected]>
d631d67 to
d8f7515
Compare
| // Validate verifies that the configuration contains valid values. | ||
| // It checks for required fields and validates the endpoint URL format. | ||
| func (c *Config) Validate() error { | ||
| // Validate API key | ||
| if c.LLMAPIKey == "" { | ||
| return ErrLLMAPIKeyNotConfigured | ||
| } | ||
|
|
||
| // Validate endpoint URL if provided | ||
| if c.LLMEndpoint != "" { | ||
| if _, err := url.Parse(c.LLMEndpoint); err != nil { | ||
| return errors.Join(ErrInvalidEndpoint, err) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } |
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.
it looks better now
|
/retitle feat(openai): implement llm client interface |
|
thanks ~ let's move the PR forward |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: warjiang The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind feature
What this PR does / why we need it:
This PR implements the interface for connecting to the OpenAI API. It provides helper functions to create a configured OpenAI client based on the application's settings. This is a core component for providing the LLM capabilities to the AI Assistant.
Which issue(s) this PR fixes:
Part of #273
Special notes for your reviewer:
It depends on the changes from PR #274
Does this PR introduce a user-facing change?: