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 llm_provider Deepseek #55

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

jin10086
Copy link

@jin10086 jin10086 commented Jan 10, 2025

docs: https://api-docs.deepseek.com/

Summary by CodeRabbit

  • New Features

    • Added support for the Deepseek AI provider.
    • Introduced a new Deepseek provider with custom configuration for API interactions.
    • Expanded the list of available AI providers in the application.
  • Chores

    • Updated module initialization to include the new Deepseek provider.
    • Configured environment variable-based API key management for Deepseek.

Copy link
Contributor

coderabbitai bot commented Jan 10, 2025

Walkthrough

The pull request introduces the Deepseek provider to the SimpleMind library, expanding the existing provider ecosystem. A new Deepseek class is added, which inherits from the OpenAI class and is specifically configured for the Deepseek AI service. The provider is integrated into the module's list of providers and public API, allowing users to utilize Deepseek as a language model provider with automatic API key and client configuration.

Changes

File Change Summary
simplemind/providers/__init__.py - Added Deepseek to providers list
- Added Deepseek to __all__ list
simplemind/providers/deepseek.py - Created new Deepseek class extending OpenAI
- Implemented __init__ method with optional API key
- Added client cached property for Deepseek API connection

Sequence Diagram

sequenceDiagram
    participant User
    participant DeepseekProvider
    participant OpenAIClient
    
    User->>DeepseekProvider: Initialize with optional API key
    DeepseekProvider->>DeepseekProvider: Retrieve DEEPSEEK_API_KEY
    DeepseekProvider->>OpenAIClient: Configure client
    OpenAIClient-->>DeepseekProvider: Return configured client
Loading

Poem

🐰 A Rabbit's Ode to Deepseek's Might

In providers' realm, a new star shines bright,
Deepseek joins the dance with algorithmic delight,
With OpenAI's grace and its own special flair,
Another language model beyond compare!
Hop, hop, innovation takes flight! 🚀


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c1f225 and d963bc0.

📒 Files selected for processing (1)
  • simplemind/providers/deepseek.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • simplemind/providers/deepseek.py

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

Copy link
Contributor

@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

🧹 Nitpick comments (2)
simplemind/providers/deepseek.py (2)

16-27: Consider adding endpoint URL validation.

The implementation looks good with proper error handling and caching. However, consider adding validation for the endpoint URL format to catch configuration issues early.

Here's a suggested implementation:

     @cached_property
     def client(self):
         """The raw OpenAI client."""
         if not self.api_key:
             raise ValueError("DEEPSEEK API key is required")
+        if not self.endpoint.startswith(("http://", "https://")):
+            raise ValueError("Invalid endpoint URL format")
         try:
             import openai as oa
         except ImportError as exc:
             raise ImportError(
                 "Please install the `openai` package: `pip install openai`"
             ) from exc
         return oa.OpenAI(api_key=self.api_key, base_url=self.endpoint)

7-27: Add class and method documentation.

Consider adding docstrings to describe:

  • The purpose of the Deepseek provider class
  • The parameters and return values of methods
  • Usage examples

Example:

class Deepseek(OpenAI):
    """Deepseek API provider implementation.
    
    This provider implements the Deepseek API interface using the OpenAI client library.
    It requires a Deepseek API key to be set either through the constructor or
    via the DEEPSEEK_API_KEY environment variable.
    """
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4decaa0 and 0c1f225.

📒 Files selected for processing (2)
  • simplemind/providers/__init__.py (3 hunks)
  • simplemind/providers/deepseek.py (1 hunks)
🔇 Additional comments (3)
simplemind/providers/__init__.py (1)

12-12: LGTM! Clean integration of the Deepseek provider.

The changes follow the established pattern for provider integration, maintaining consistency with other providers in the codebase.

Also applies to: 22-22, 36-36

simplemind/providers/deepseek.py (2)

7-9: Verify the default model name with Deepseek's documentation.

Please ensure that "deepseek-chat" is the correct model identifier as per Deepseek's API documentation.


1-27: Add test coverage for the Deepseek provider.

Please ensure that test coverage is added for:

  • Provider initialization with different API key scenarios
  • Client property behavior
  • Error handling cases

Would you like me to help create a test suite for the Deepseek provider?

simplemind/providers/deepseek.py Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@kennethreitz
Copy link
Owner

we need to update the project's dependencies to reflect this change, as well as the readme

@jin10086
Copy link
Author

Should we create a generic Open Like API interface?

kimi = sm.Session(llm_provider="OpenAILike", llm_model="moonshot-v1-8k", api_key ="",base_url="https://api.moonshot.cn/v1")

@kennethreitz
Copy link
Owner

That's an interesting idea!

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.

2 participants