-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add OpenAI as an additional AI provider #2
base: master
Are you sure you want to change the base?
Conversation
WalkthroughWalkthroughThe updates integrate OpenAI functionality into the existing system, adding dependencies and implementing new functions for OpenAI inferences and cost calculations. Configuration settings for OpenAI and Claude APIs have been included, and model choices are now extended to support OpenAI models. These changes enhance the system's capabilities by incorporating OpenAI's powerful models alongside existing Claude functionalities. Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
@coderabbitai review |
Actions PerformedReview triggered.
|
@coderabbitai review |
Actions PerformedReview triggered.
|
@coderabbitai review |
Actions PerformedReview triggered.
|
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.
Actionable comments posted: 1
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (5)
- package.json (1 hunks)
- src/ai.ts (2 hunks)
- src/app.ts (2 hunks)
- src/config.ts (1 hunks)
- src/constants.ts (1 hunks)
Additional comments not posted (6)
package.json (1)
14-14
: Addition of OpenAI SDK dependency is correct.The specified version
^4.47.1
ensures compatibility and avoids breaking changes from unexpected updates.src/constants.ts (2)
38-51
: Addition of OpenAI models is well-implemented.The use of TypeScript's
as const
ensures that the OpenAI models are treated as immutable, which is a good practice for constant values.
56-56
: Introduction ofModelProvider
type is correct.The use of a union type for
ModelProvider
is appropriate and enhances type safety by explicitly allowing only 'claude' or 'openai' as valid providers.src/ai.ts (2)
212-240
: Implementation ofrunOpenAIInference
function is robust.The function correctly configures the OpenAI API client and handles API responses and errors effectively using async/await patterns.
252-265
: Modification togetModelCosts
to support multiple providers is correct.The function now correctly handles different providers and throws an error for unsupported ones, which is a good practice for fail-fast behavior.
src/app.ts (1)
97-102
: Enhancements to model selection inrunWizard
function are well-implemented.The updates allow users to choose between Claude and OpenAI models effectively, enhancing the application's flexibility and user experience.
apiKey: process.env.OPENAI_API_KEY || '', | ||
apiEndpoint: process.env.OPENAI_API_ENDPOINT || 'https://api.openai.com', | ||
defaultModel: 'gpt-3.5-turbo', |
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.
Ensure secure handling of API keys and endpoints.
The fallback values for apiKey
and apiEndpoint
are empty strings and a default URL, respectively. This could lead to unintended behaviors if environment variables are not set. Consider handling missing configuration more explicitly, possibly by throwing an error if essential environment variables are missing.
Related to #1
This pull request introduces OpenAI as an additional AI provider alongside Claude, enhancing the application's capabilities to support multiple AI providers for generating inferences. The changes include updates to configuration, constants, AI interaction logic, and the application's model selection process.
src/config.ts
to include OpenAI specific settings such as API key and endpoint configurations.src/constants.ts
to define OpenAI models and configurations, and introduces aModelProvider
type to represent supported model providers including "claude" and "openai".runOpenAIInference
insrc/ai.ts
to handle OpenAI API calls and updates cost calculation functions to support OpenAI models. It also modifies existing functions to dynamically select between Claude and OpenAI based on user preference.src/app.ts
to include OpenAI models in the model selection process, allowing users to choose OpenAI models for meta inference and page generation. It also implements logic to calculate costs for OpenAI models and display them to the user.For more details, open the Copilot Workspace session.