Skip to content

Conversation

@kasanatte
Copy link
Contributor

@kasanatte kasanatte commented Sep 26, 2025

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?:

NONE

@karmada-bot karmada-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Sep 26, 2025
@gemini-code-assist
Copy link

Summary of Changes

Hello @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

  • New OpenAI Interface: Introduces a new pkg/openai package dedicated to managing connectivity and configuration for the OpenAI API.
  • Client Configuration and Retrieval: Provides helper functions, InitOpenAIConfig and GetOpenAIClient, to initialize and retrieve a properly configured OpenAI client based on application settings, including API key and endpoint.
  • Thread-Safe Access: Implements sync.RWMutex to ensure thread-safe access and modification of the global OpenAI configuration, preventing race conditions.
  • Model and Configuration Status: Includes functions GetOpenAIModel to retrieve the configured OpenAI model (with a default fallback) and IsOpenAIConfigured to check if the OpenAI integration is properly set up.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 26, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a 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.

return nil, errors.New("OpenAI not initialized, call InitOpenAIConfig first")
}

if globalOpenAIOptions.OpenAIAPIKey == "" {
Copy link
Contributor

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

}

config := openai.DefaultConfig(globalOpenAIOptions.OpenAIAPIKey)
if globalOpenAIOptions.OpenAIEndpoint != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

)

// InitOpenAIConfig initializes OpenAI configuration from Options.
func InitOpenAIConfig(opts *options.Options) {
Copy link
Contributor

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

@kasanatte kasanatte force-pushed the feature/openai-interface branch from 4e832b4 to 0e7dd31 Compare October 21, 2025 12:10
@karmada-bot karmada-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 21, 2025
@kasanatte kasanatte force-pushed the feature/openai-interface branch from 0e7dd31 to 7b34d74 Compare October 21, 2025 12:42
@kasanatte
Copy link
Contributor Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a 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.

@kasanatte kasanatte force-pushed the feature/openai-interface branch 2 times, most recently from fc76f61 to cea14b4 Compare October 22, 2025 04:36
@warjiang
Copy link
Contributor

/assign

@warjiang
Copy link
Contributor

@kasanatte it seems that there are some conflicts, plz resovle the conflicts first

@kasanatte kasanatte force-pushed the feature/openai-interface branch 2 times, most recently from 9fc865d to d631d67 Compare October 23, 2025 03:53

// Sentinel errors for LLM package.
// These errors can be used with errors.Is() for error type checking.
var (
Copy link
Contributor

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")
Copy link
Contributor

@warjiang warjiang Oct 28, 2025

Choose a reason for hiding this comment

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

cool ~ learn from that ~

@warjiang
Copy link
Contributor

thank, I think this PR is ready to be merged after the issues be resolved @kasanatte

@kasanatte kasanatte force-pushed the feature/openai-interface branch from d631d67 to d8f7515 Compare October 29, 2025 13:06
@karmada-bot karmada-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 29, 2025
Comment on lines +36 to +52
// 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
}
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks better now

@warjiang
Copy link
Contributor

/retitle feat(openai): implement llm client interface

@karmada-bot karmada-bot changed the title feat(openai): implement openai interface feat(openai): implement llm client interface Oct 29, 2025
@warjiang
Copy link
Contributor

thanks ~ let's move the PR forward

@warjiang
Copy link
Contributor

/lgtm
/approve

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 29, 2025
@karmada-bot
Copy link
Collaborator

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 29, 2025
@karmada-bot karmada-bot merged commit d87b0a5 into karmada-io:main Oct 29, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants