Skip to content

fix groq and cerebras clients #672

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 2 commits into from
Apr 23, 2025
Merged

Conversation

seanmcguire12
Copy link
Member

why

  • both groq and cerebras clients were not returning the response in the correct shape

what changed

  • updated groq and cerebras clients to return an object with the expected shape:
const finalResponse = {
  data: result,
  usage: response.usage,
};

test plan

  • tested with evals locally

Copy link

changeset-bot bot commented Apr 16, 2025

⚠️ No Changeset found

Latest commit: 5ab9a6b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Added consistent response formatting and error handling for Groq and Cerebras LLM clients to ensure proper data shape and usage metrics.

  • Added structured response format { data: result, usage: response.usage } in both clients
  • Improved JSON parsing from tool calls and content with proper error handling
  • Added caching support for both raw and formatted responses
  • Enhanced retry mechanism (up to 5 attempts) for failed JSON parsing
  • Added comprehensive logging for response handling and errors

2 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

if (content) {
try {
// Try to extract JSON from the content
const jsonMatch = content.match(/\{[\s\S]*\}/);
Copy link

Choose a reason for hiding this comment

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

logic: Regex pattern /{[\s\S]*}/ may match nested JSON objects incorrectly, leading to invalid parsing

Comment on lines +279 to +280
const jsonMatch = content.match(/\{[\s\S]*\}/);
if (jsonMatch) {
Copy link

Choose a reason for hiding this comment

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

logic: regex pattern /{[\s\S]*}/ could match nested JSON objects incorrectly or match the first {} it finds instead of the complete JSON object

@seanmcguire12 seanmcguire12 merged commit 9d47027 into main Apr 23, 2025
13 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