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

Add OpenAI as an additional AI provider #2

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lightningRalf
Copy link
Owner

@lightningRalf lightningRalf commented May 17, 2024

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.

  • Configuration and Dependencies: Adds OpenAI SDK as a dependency and updates src/config.ts to include OpenAI specific settings such as API key and endpoint configurations.
  • Constants: Updates src/constants.ts to define OpenAI models and configurations, and introduces a ModelProvider type to represent supported model providers including "claude" and "openai".
  • AI Interaction Logic: Implements runOpenAIInference in src/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.
  • Model Selection: Enhances 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.

Copy link

coderabbitai bot commented May 17, 2024

Walkthrough

Walkthrough

The 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

File Path Change Summary
package.json Added "openai": "^4.47.1" as a new dependency.
src/ai.ts Introduced functions for OpenAI inferences (runOpenAIInference), cost calculations (getOpenAICosts, getOpenAICostsFromText), and modified existing functions to support OpenAI.
src/app.ts Updated imports and runWizard function to include OpenAI models and provider information.
src/config.ts Added config object with settings for OpenAI and Claude APIs.
src/constants.ts Added OPENAI_MODELS array, descriptions for new OpenAI models, and ModelProvider type.

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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@lightningRalf
Copy link
Owner Author

@coderabbitai review

Copy link

coderabbitai bot commented May 17, 2024

Actions Performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lightningRalf lightningRalf marked this pull request as draft May 17, 2024 02:11
@lightningRalf lightningRalf marked this pull request as ready for review May 17, 2024 02:11
@lightningRalf lightningRalf marked this pull request as draft May 17, 2024 02:11
@lightningRalf
Copy link
Owner Author

@coderabbitai review

Copy link

coderabbitai bot commented May 17, 2024

Actions Performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lightningRalf
Copy link
Owner Author

@coderabbitai review

Copy link

coderabbitai bot commented May 17, 2024

Actions Performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 56098f4 and 5a9bb84.
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 of ModelProvider 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 of runOpenAIInference 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 to getModelCosts 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 in runWizard function are well-implemented.

The updates allow users to choose between Claude and OpenAI models effectively, enhancing the application's flexibility and user experience.

Comment on lines +10 to +12
apiKey: process.env.OPENAI_API_KEY || '',
apiEndpoint: process.env.OPENAI_API_ENDPOINT || 'https://api.openai.com',
defaultModel: 'gpt-3.5-turbo',
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant