Skip to content

Add Groq model support to LLMClient (#1977) #2165

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 20 commits into from
Jul 3, 2025

Conversation

kunjanshah0811
Copy link
Contributor

@kunjanshah0811 kunjanshah0811 commented May 12, 2025

@davidberenstein1957 @henchaves @alexcombessie

Description

This PR adds support for using Groq as an additional LLM client in Giskard, without replacing the default LiteLLM client. It enables developers to integrate Groq models like llama3-8b-8192 by configuring and initializing GroqClient explicitly.

Related Issue

Closes Set any groq model as default LLMClient for giskard #1977

Type of Change

  • 📚 Examples / docs / tutorials / dependencies update
  • 🔧 Bug fix (non-breaking change which fixes an issue)
  • 🥂 Improvement (non-breaking change which improves an existing feature)
  • 🚀 New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 🔐 Security fix

Checklist

  • I've read the CODE_OF_CONDUCT.md document.
  • I've read the CONTRIBUTING.md guide.
  • I've updated the pdm.lock running pdm update-lock (only applicable when pyproject.toml has been
    modified)
  • I've written the docstring in Google format for all the methods and classes that I used.
  • I've written tests for all new methods and classes that I created.

Usage Example

import os
from dotenv import load_dotenv
from groq import Groq
from giskard.llm.client import ChatMessage
from giskard.llm.client.groq_client import GroqClient

load_dotenv()  # Loads GROQ_API_KEY from .env

# Create Groq client using the API key
client = Groq(api_key=os.environ["GROQ_API_KEY"])
groq_client = GroqClient(client=client)

def test_groq_json_mode():
    messages = [
        ChatMessage(role="system", content="You are a helpful assistant that performs sentiment analysis. "
                    "Return a short summary of the sentiment (Positive, Neutral, or Negative) "
                    "and briefly explain why."),
        ChatMessage(role="user", content="Here's a customer review: 'The product works fine, but the customer service was terrible and slow.'")
    ]
    response = groq_client.complete(messages)
    print("Response:\n", response.content)

if __name__ == "__main__":
    test_groq_json_mode()

Copy link
Member

@davidberenstein1957 davidberenstein1957 left a comment

Choose a reason for hiding this comment

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

Looks good already. Some minor remarks :)

… redundant seed assignment

- Added _supports_json_format(model: str) to check for JSON support based on model name.
- Now user can specify JSON format via the 'format' parameter instead of hardcoding.
- Removed duplicate assignment of extra_params['seed'] = seed in GroqClient.complete()."
Copy link
Member

@davidberenstein1957 davidberenstein1957 left a comment

Choose a reason for hiding this comment

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

Hi, I left some more comments.

Copy link
Contributor Author

@kunjanshah0811 kunjanshah0811 left a comment

Choose a reason for hiding this comment

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

Fixed previous issues and added one comment that needs your attention in groq_client.py
Here https://github.com/Giskard-AI/giskard/pull/2165/files/10a4b68e3841dedb23605c1f5d3f333621942d0f#r2120776154

@davidberenstein1957
Copy link
Member

LFTM, one final thing is to mention it in our docs: https://docs.giskard.ai/en/stable/open_source/setting_up/index.html.

@kunjanshah0811
Copy link
Contributor Author

LFTM, one final thing is to mention it in our docs: https://docs.giskard.ai/en/stable/open_source/setting_up/index.html.

I will update it by today and let you know. :)

Copy link
Contributor Author

@kunjanshah0811 kunjanshah0811 left a comment

Choose a reason for hiding this comment

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

I have added Groq Client in Documentation.

@davidberenstein1957
Copy link
Member

@kunjanshah0811 now, we need to make sure all tests pass.

@kunjanshah0811
Copy link
Contributor Author

@kunjanshah0811 now, we need to make sure all tests pass.

Solved the Linting Error.

@davidberenstein1957
Copy link
Member

@kunjanshah0811 there are some remaining errors. Before pushing, could you make sure they pass locally?

@kunjanshah0811
Copy link
Contributor Author

kunjanshah0811 commented Jun 11, 2025

@kunjanshah0811 there are some remaining errors. Before pushing, could you make sure they pass locally?

I ran both pdm run test and pdm run test-fast locally, and all tests passed without any breaking changes. Please see the attached screenshot for confirmation. Please check and confirm; I think this time the PR is ready to merge into the main branch. ✅

Let me know if anything else is needed from my end. @davidberenstein1957 😀

Note: Some tests require HuggingFace authentication. So, it is done locally via huggingface-cli login.

image

@davidberenstein1957
Copy link
Member

Awesome @kunjanshah0811 . Thanks a lot for the help.

@kunjanshah0811
Copy link
Contributor Author

kunjanshah0811 commented Jun 20, 2025

Awesome @kunjanshah0811 . Thanks a lot for the help.

Fixed with minor errors. @davidberenstein1957 thanks a lot for the review. :)

@davidberenstein1957 davidberenstein1957 added safe for build Lockfile Temporary label to update pdm.lock labels Jun 20, 2025
Copy link
Member

@davidberenstein1957 davidberenstein1957 left a comment

Choose a reason for hiding this comment

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

Some minor tweaks for the dependencies and we are good to go. A lot of thanks for the help.

pyproject.toml Outdated
@@ -59,7 +61,13 @@ dev = [
"mistralai>=1",
"boto3>=1.34.88",
"scikit-learn==1.4.2",
"bert-score>=0.3.13",

Choose a reason for hiding this comment

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

why did you duplicate these dependencies here? Is there a specific reason? I'm not sure if we rely on them directly and they might be included in the other libraries, like langchain already?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why did you duplicate these dependencies here? Is there a specific reason? I'm not sure if we rely on them directly and they might be included in the other libraries, like langchain already?

I added those dependencies because I ran into import errors during local testing, and adding them directly resolved the issues at the time. But you're right,other libraries like langchain might already pull in some of them and I may have added them redundantly without double-checking after that. I’m happy to remove any that aren’t needed directly.

@davidberenstein1957 davidberenstein1957 added safe for build Lockfile Temporary label to update pdm.lock and removed safe for build Lockfile Temporary label to update pdm.lock labels Jun 23, 2025
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should set groq as default LLM client.
Could we revert the modifications here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we should set groq as default LLM client. Could we revert the modifications here?

Thank you for the feedback. Before I make any changes, I want to ensure I understand your request correctly:

  1. I'll remove Groq from being automatically selected as a default LLM client by modifying the get_default_llm_api() function in __init__.py

  2. I'll keep the following in place so Groq can still be used when explicitly selected:

    • The Groq client implementation (groq_client.py)
    • The Groq dependency in pyproject.toml
    • The test case for the Groq client
    • "groq" as a valid option in the API list (users can still explicitly set GSK_LLM_API="groq")

Is this understanding correct? If you'd prefer I completely remove all Groq-related changes, please let me know.

Copy link
Member

Choose a reason for hiding this comment

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

Hey @kunjanshah0811, yes exactly!
Just reverting llm/client/__init__.py should be fine, you can keep the groq_client.py as it is.

Copy link
Contributor Author

@kunjanshah0811 kunjanshah0811 Jul 1, 2025

Choose a reason for hiding this comment

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

Hey @kunjanshah0811, yes exactly! Just reverting llm/client/__init__.py should be fine, you can keep the groq_client.py as it is.

@henchaves I have made suggested changes with the recent commit. Please have a look and let me know. Thanks a lot 🚀.

Comment on lines 21 to 22
# Note: Groq does not currently support embedding models
# Use another provider for embeddings if needed
Copy link
Member

Choose a reason for hiding this comment

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

Perfect! Thanks.
Could you just mention to access https://docs.litellm.ai/docs/embedding/supported_embedding to see the full list of supported providers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perfect! Thanks. Could you just mention to access https://docs.litellm.ai/docs/embedding/supported_embedding to see the full list of supported providers?

  1. I'll add the documentation reference you suggested in docs/open_source/setting_up/index.md linking to LiteLLM's supported embedding providers

Copy link
Member

Choose a reason for hiding this comment

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

yes, thanks!

@henchaves henchaves removed the Lockfile Temporary label to update pdm.lock label Jul 2, 2025
@henchaves henchaves self-assigned this Jul 2, 2025
@henchaves
Copy link
Member

Thanks a lot @kunjanshah0811! The PR is ready to be merged 🙂

@kunjanshah0811
Copy link
Contributor Author

Thanks a lot @kunjanshah0811! The PR is ready to be merged 🙂

Thank you so much @davidberenstein1957 and @henchaves for your constant support! 🙏✨
I learnt a lot from you both during my First Open-source Contribution and really appreciate your time and help. 🚀💡
I’m excited to keep learning and contributing to Giskard! 😄🦾
Thanks again for everything! 🚀🤩

@henchaves henchaves enabled auto-merge July 2, 2025 21:02
@henchaves henchaves merged commit 6ed690f into Giskard-AI:main Jul 3, 2025
30 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Set any groq model as default LLMClient for giskard
3 participants