Skip to content

[FEAT] Groq provider #342

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

Merged
merged 4 commits into from
Mar 26, 2025
Merged

[FEAT] Groq provider #342

merged 4 commits into from
Mar 26, 2025

Conversation

Daggx
Copy link
Contributor

@Daggx Daggx commented Mar 25, 2025

Summary by CodeRabbit

  • New Features
    • Introduced a configuration template for API key setup.
    • Expanded available API functionality with a new provider integration supporting text, multimodal, and extended chat interactions.
    • Added structured output formats for AI chat responses, complete with detailed performance and usage metrics.
    • Updated chat settings to incorporate the new provider option.
    • Added new JSON files for error handling and metadata descriptors for chat functionalities.
    • Enhanced the API with new methods for chat interactions.

Copy link

coderabbitai bot commented Mar 25, 2025

Walkthrough

The pull request introduces a new Groq API provider into the system. It adds several new JSON configuration and output files, a new API class (GroqApi) with methods for handling chat interactions, error handling support, and updates to package initialization files to expose the new provider. Additionally, a new entry is added to the settings for provider configuration.

Changes

Files Change Summary
edenai_apis/api_keys/groq_settings_template.json Added JSON template for API key configuration with "api_key": "".
edenai_apis/apis/__init__.py and edenai_apis/apis/groq/__init__.py Added import statements to expose the GroqApi class at the package level.
edenai_apis/apis/groq/errors.py Introduced a new file that imports error handling utilities and defines an empty ERRORS variable.
edenai_apis/apis/groq/groq_api.py Created the GroqApi class implementing multiple interfaces with methods: text__chat and llm__chat.
edenai_apis/apis/groq/info.json
edenai_apis/apis/groq/outputs/llm/chat_output.json
edenai_apis/apis/groq/outputs/text/chat_output.json
Added metadata configuration and two output JSON files for chat responses (LLM and text variants).
edenai_apis/features/text/chat/chat_args.py Updated the chat arguments settings by adding "groq": "llama-3.1-8b-instant".

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant G as GroqApi
    participant L as LLMEngine

    C->>G: Initiate text__chat (or llm__chat)
    G->>L: Call corresponding LLMEngine method with parameters
    L-->>G: Return response or error details
    G-->>C: Send back formatted chat response
Loading

Poem

I'm a rabbit in the byte-filled glade,
Hopping through code in a springtime parade.
New paths emerge, fresh keys in sight,
Groq's magic now gives our chats new light.
With JSON and methods all set to run,
I celebrate these changes—oh what fun!
🐇✨


🪧 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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

@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: 3

🧹 Nitpick comments (3)
edenai_apis/apis/groq/errors.py (1)

5-5: Add Documentation for the ERRORS Dictionary.
The ERRORS variable is correctly typed as ProviderErrorLists and initialized as an empty dictionary. To improve maintainability, consider adding an inline comment or docstring explaining its purpose, such as which error codes or messages might be expected in the future and how they will be utilized by the Groq API.

edenai_apis/apis/groq/__init__.py (1)

1-1: Add __all__ to explicitly define exports

While the import is correct for exposing GroqApi at the package level, consider adding an __all__ list to explicitly define what's exported from this module and fix the static analysis warning.

from .groq_api import GroqApi
+
+__all__ = ["GroqApi"]
🧰 Tools
🪛 Ruff (0.8.2)

1-1: .groq_api.GroqApi imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)

edenai_apis/apis/__init__.py (1)

69-69: Add __all__ to properly handle imports

The import statement correctly adds Groq to the available APIs, but to address the static analysis warning about unused imports, consider adding an __all__ list that includes all the API classes.

# At the beginning of the file after imports
+__all__ = [
+    "AffindaApi", "Ai21labsApi", "AlephAlphaApi", "AmazonApi", "AnthropicApi",
+    # ... other API classes ...
+    "DeepseekApi", "TogetheraiApi", "GroqApi"
+]

This would also help with the "THIS NEEDS TO BE DONE AUTOMATICALLY" comment by making it easier to automate updates to the exports list in the future.

🧰 Tools
🪛 Ruff (0.8.2)

69-69: .groq.GroqApi imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d4bead9 and 6949026.

📒 Files selected for processing (9)
  • edenai_apis/api_keys/groq_settings_template.json (1 hunks)
  • edenai_apis/apis/__init__.py (1 hunks)
  • edenai_apis/apis/groq/__init__.py (1 hunks)
  • edenai_apis/apis/groq/errors.py (1 hunks)
  • edenai_apis/apis/groq/groq_api.py (1 hunks)
  • edenai_apis/apis/groq/info.json (1 hunks)
  • edenai_apis/apis/groq/outputs/llm/chat_output.json (1 hunks)
  • edenai_apis/apis/groq/outputs/text/chat_output.json (1 hunks)
  • edenai_apis/features/text/chat/chat_args.py (1 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
edenai_apis/apis/groq/__init__.py (1)
edenai_apis/apis/groq/groq_api.py (1)
  • GroqApi (25-172)
edenai_apis/apis/__init__.py (1)
edenai_apis/apis/groq/groq_api.py (1)
  • GroqApi (25-172)
🪛 Ruff (0.8.2)
edenai_apis/apis/groq/__init__.py

1-1: .groq_api.GroqApi imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)

edenai_apis/apis/__init__.py

69-69: .groq.GroqApi imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)

edenai_apis/apis/groq/groq_api.py

22-22: Redefinition of unused ChatDataClass from line 16

(F811)


28-28: Do not use mutable data structures for argument defaults

Replace with None; initialize within function

(B006)


100-100: Do not use mutable data structures for argument defaults

Replace with None; initialize within function

(B006)

🔇 Additional comments (6)
edenai_apis/apis/groq/errors.py (1)

1-3: Review Import Statement and Type Import.
The import for ProviderErrorLists from edenai_apis.utils.exception is clear and well-formatted. Ensure that the structure defined by ProviderErrorLists aligns with how error mappings are intended to be managed in the Groq API implementation.

edenai_apis/api_keys/groq_settings_template.json (1)

1-3: LGTM! Template file structure is correct

The template file for Groq API settings follows the proper structure with an empty API key placeholder.

edenai_apis/features/text/chat/chat_args.py (1)

31-31: LGTM! Default model properly configured

The default model setting for Groq has been correctly added to the settings dictionary, following the same pattern as other providers.

edenai_apis/apis/groq/info.json (1)

1-17: Looks good!

No issues found with this configuration file. The JSON syntax is valid and each version field is clearly defined for the corresponding chat categories.

edenai_apis/apis/groq/outputs/llm/chat_output.json (1)

1-41: No concerns here!

This JSON response structure is well-formed and clear. Each field (choices, usage, cost, etc.) is suitably descriptive.

edenai_apis/apis/groq/outputs/text/chat_output.json (1)

1-67: Clean and well-structured!

Everything in this JSON layout looks consistent; the presence of both original and standardized responses helps maintain clarity.

class GroqApi(ProviderInterface, TextInterface, LlmInterface):
provider_name = "groq"

def __init__(self, api_keys: Dict = {}) -> None:
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use an immutable default for function parameters.

Using a mutable default ({}) for api_keys can lead to unintended state sharing across instances. Replace it with None and initialize internally.

-    def __init__(self, api_keys: Dict = {}):
+    def __init__(self, api_keys: Optional[Dict] = None):
+        if api_keys is None:
+            api_keys = {}
         self.api_settings = load_provider(
             ...
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def __init__(self, api_keys: Dict = {}) -> None:
def __init__(self, api_keys: Optional[Dict] = None) -> None:
if api_keys is None:
api_keys = {}
self.api_settings = load_provider(
...
🧰 Tools
🪛 Ruff (0.8.2)

28-28: Do not use mutable data structures for argument defaults

Replace with None; initialize within function

(B006)

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
Plan: Lite

📥 Commits

Reviewing files that changed from the base of the PR and between 6949026 and 7ca2b83.

📒 Files selected for processing (1)
  • edenai_apis/apis/groq/groq_api.py (1 hunks)
🔇 Additional comments (3)
edenai_apis/apis/groq/groq_api.py (3)

7-13: Avoid overshadowing imports.

Re-importing ChatDataClass from two different modules can cause confusion and overshadow one of them. Consider aliasing or removing the redundant import if only one is needed.


19-19: Use an immutable default for api_keys.

Defining api_keys: Dict = {} can lead to unintended state sharing across instances. Switch to None and initialize internally.

-    def __init__(self, api_keys: Dict = {}):
+    def __init__(self, api_keys: Optional[Dict] = None):
+        if api_keys is None:
+            api_keys = {}
         self.api_settings = load_provider(
             ...

61-61: Use an immutable default for messages.

Defining messages: List = [] can lead to unintended state sharing. Replace with None and initialize within the function.

-    def llm__chat(
-        self,
-        messages: List = [],
+    def llm__chat(
+        self,
+        messages: Optional[List] = None,
         ...
+        if messages is None:
+            messages = []
         ...

from typing import Dict, List, Literal, Optional, Type, Union

import httpx
from openai import BaseModel
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify if BaseModel is correctly imported from the openai module.

The openai Python library typically doesn't expose BaseModel. If you intended to use Pydantic's BaseModel, please adjust the import statement accordingly.

Please run the following web search to confirm:


🌐 Web query:

Does the openai Python library export a `BaseModel` class?

💡 Result:

The OpenAI Python library does not export a BaseModel class directly. However, the library is often used in conjunction with Pydantic's BaseModel for structured output validation when integrating with OpenAI's API. Here’s a breakdown:

  1. Official OpenAI Library Functionality
    The standard openai Python package (PyPI source [1][5][11]) focuses on API client interactions and does not include a native BaseModel class. For example:

    from openai import OpenAI
    client = OpenAI()
  2. Pydantic Integration
    Structured output validation (e.g., enforcing JSON schemas for responses) typically requires the pydantic.BaseModel class from the separate Pydantic library. This is commonly used with OpenAI via third-party tools like Instructor (documentation [6][10]):

    from pydantic import BaseModel
    import instructor
    from openai import OpenAI
    
    client = instructor.patch(OpenAI())
    
    class User(BaseModel):  # Uses Pydantic's BaseModel
        name: str
        age: int
  3. Community Examples
    Multiple search results show developers combining OpenAI’s library with Pydantic for tasks like parsing API responses, batch processing, and schema validation [3][12][15]. For instance:

    • Defining response models with Pydantic to enforce structure [6][10][15].
    • Using OpenAI’s API with response_model=User (a Pydantic model) via Instructor [6].

Key Takeaway: While the OpenAI library itself doesn’t provide BaseModel, Pydantic’s BaseModel is widely used alongside it for structured data workflows. Install Pydantic separately (pip install pydantic) and import it directly.

Citations:


Fix incorrect BaseModel import in edenai_apis/apis/groq/groq_api.py.

It appears that the OpenAI Python library does not export a BaseModel class. If your intention is to use Pydantic's BaseModel for output validation, please update the import to:

from pydantic import BaseModel
  • Location: edenai_apis/apis/groq/groq_api.py, line 4
  • Issue: Importing BaseModel from openai instead of Pydantic.
  • Suggested Fix: Replace the import with the one shown above to correctly reference Pydantic’s BaseModel.

Copy link
Contributor

@juandavidcruzgomez juandavidcruzgomez left a comment

Choose a reason for hiding this comment

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

There's one comment from the rabbit that I think it's pertinent: https://github.com/edenai/edenai-apis/pull/342/files#r2011774829
The ChatDataClass is being shadowed

@juandavidcruzgomez juandavidcruzgomez self-requested a review March 25, 2025 10:41
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: 0

🧹 Nitpick comments (1)
edenai_apis/apis/groq/info.json (1)

1-20: Overall Structure & Metadata Validity Check
The JSON file correctly defines the metadata and version information for the new Groq API provider in a clear, well-structured format. The _metadata section and the individual provider configurations for text, multimodal, and llm all conform to a consistent pattern.

Points to Consider:

  • Verify the Privacy URL: Ensure that "https://groq.com/privacy-policy" is accurate and reachable.
  • Optional Metadata Enhancements: Consider including additional provider details such as a provider_name or a brief description to enhance clarity and future extensibility (e.g., if similar info files for other providers are expected).
  • Versioning Strategy: All chat configurations are marked as "v1". As the provider evolves, it might be beneficial to include more granular versioning or additional configuration keys if needed.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cfc42fd and 31cbbed.

📒 Files selected for processing (1)
  • edenai_apis/apis/groq/info.json (1 hunks)

@juandavidcruzgomez juandavidcruzgomez merged commit 2b41add into master Mar 26, 2025
3 of 4 checks passed
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