Skip to content

feat: implement Groq adapter - #568

Closed
jhosepm352-design wants to merge 1 commit into
profullstack:masterfrom
jhosepm352-design:feat/adapter-ai-groq
Closed

jhosepm352-design wants to merge 1 commit into
profullstack:masterfrom
jhosepm352-design:feat/adapter-ai-groq

Conversation

@jhosepm352-design

Copy link
Copy Markdown
Contributor

Implements the Groq provider using the OpenAI-compatible protocol.

@greptile-apps

greptile-apps Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR refactors the Groq AI adapter — simplifying the setup call, inlining the headers object, and switching to older Llama 3 model identifiers — but introduces several regressions that leave the adapter non-functional. Two undeclared identifiers (Groq_LOWER on the log line and Groq in the error formatter) cause ReferenceError on every generate call and every failed request respectively; the redact() guard against API-key leakage in error bodies was dropped; and the trailing-slash normalization for custom baseUrl values was removed.

  • The generate() function crashes unconditionally before making any network request due to Groq_LOWER being undefined (line 19), and error handling is also broken by the undefined Groq variable (line 42).
  • Removing redact() means the raw GROQ_API_KEY can appear in thrown error messages; the existing test suite asserts redaction and will now fail.
  • Dropping .replace(/\\/+$/, '') on baseUrl produces double-slash URLs for any proxy configuration, and the model list was silently downgraded from current Groq-recommended identifiers to older ones.

Confidence Score: 1/5

Not safe to merge — the adapter is completely non-functional as written and also leaks API keys in error messages.

Every call to generate() crashes with a ReferenceError before a single network request is made, and the error-handling branch crashes independently for the same reason. On top of that, removing the redact() helper exposes the raw GROQ_API_KEY in thrown error messages. The entire existing test suite for this adapter will fail. The change needs significant rework before it can be considered for merging.

packages/ai/groq/src/index.ts — all four issues (two undefined variables, API-key redaction, and trailing-slash normalization) are concentrated in this single file.

Security Review

  • API key leak in error messages (packages/ai/groq/src/index.ts, line 42): The redact() helper that scrubbed GROQ_API_KEY from HTTP error bodies before slicing and throwing was removed. A key that appears in the first 200 characters of an error response will now be included verbatim in the thrown Error message, potentially reaching application logs or monitoring systems.

Important Files Changed

Filename Overview
packages/ai/groq/src/index.ts Two undefined variables (Groq_LOWER, Groq) cause immediate ReferenceErrors; redact() removal leaks API keys in error messages; trailing-slash normalization dropped breaking the baseUrl config path; model list downgraded to older identifiers.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant GroqAdapter
    participant GroqAPI

    Caller->>GroqAdapter: generate(ctx, prompt, opts, config)
    GroqAdapter->>GroqAdapter: ctx.secret('GROQ_API_KEY')
    GroqAdapter->>GroqAdapter: "ctx.log(`${Groq_LOWER}...`) 💥 ReferenceError"
    Note over GroqAdapter: Execution stops here — never reaches fetch

    alt If ReferenceError were fixed
        GroqAdapter->>GroqAPI: POST /v1/chat/completions
        GroqAPI-->>GroqAdapter: non-2xx response
        GroqAdapter->>GroqAdapter: "throw new Error(`${Groq} ...`) 💥 ReferenceError"
        Note over GroqAdapter: Error path also broken
    end

    alt Happy path (both bugs fixed)
        GroqAdapter->>GroqAPI: POST /v1/chat/completions
        GroqAPI-->>GroqAdapter: 200 OK + choices/usage
        GroqAdapter-->>Caller: "{ text, model, inputTokens, outputTokens }"
    end
Loading

Reviews (1): Last reviewed commit: "feat: add Groq adapter" | Re-trigger Greptile

const model = opts.model ?? 'llama-3.3-70b-versatile';
ctx.log(`groq · model=${model} · ${prompt.length} chars in`);
const model = opts.model ?? 'llama3-70b-8192';
ctx.log(`${Groq_LOWER} · model=${model} · ${prompt.length} chars in`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P0 Undefined variable Groq_LOWER causes ReferenceError

Groq_LOWER is never declared anywhere in the file. Every call to generate() will throw a ReferenceError: Groq_LOWER is not defined at the log line before the API request is even made, making the adapter completely non-functional. The previous code used the string literal 'groq' here.

}),
});
if (!res.ok) throw new Error(`Groq ${res.status}: ${redact(await res.text(), apiKey).slice(0, 200)}`);
if (!res.ok) throw new Error(`${Groq} ${res.status}: ${(await res.text()).slice(0, 200)}`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P0 Undefined variable Groq causes ReferenceError in error path

Groq is never declared in the file, so any non-2xx HTTP response will throw ReferenceError: Groq is not defined instead of the intended error message. The original code used the string literal 'Groq' directly in the template, which is what the test at line 100 asserts (expect(message).toContain('Groq 429:')). This also means error handling is entirely broken.

}),
});
if (!res.ok) throw new Error(`Groq ${res.status}: ${redact(await res.text(), apiKey).slice(0, 200)}`);
if (!res.ok) throw new Error(`${Groq} ${res.status}: ${(await res.text()).slice(0, 200)}`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 security API key now leaks in error messages

The redact() helper was removed, so the raw API key can now appear in error bodies that get sliced and thrown. The test at lines 84–104 explicitly verifies redaction — it expects [redacted] to appear and the raw key to be absent. Without redaction, a key that falls within the first 200 characters of the error response body will be exposed in the thrown Error message, which may reach logs or monitoring systems.

'content-type': 'application/json',
};

const res = await fetch(`${config.baseUrl ?? DEFAULT_BASE}/v1/chat/completions`, {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Trailing slash on baseUrl produces a double-slash URL

The previous implementation called .replace(/\/+$/, '') on baseUrl before appending /v1/chat/completions. That guard was removed, so config.baseUrl = 'https://proxy.example.com/' now produces https://proxy.example.com//v1/chat/completions, which many HTTP servers will reject with a 404. The existing test at line 71 directly asserts this normalization and will fail.

Comment on lines +12 to +13
defaultModel: 'llama3-70b-8192',
models: ['llama3-70b-8192', 'llama3-8b-8192'],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Model list downgraded from newer Llama 3.x and Mixtral / DeepSeek-R1 models to older Llama 3 (8k context) identifiers

The removed models — llama-3.3-70b-versatile, llama-3.1-8b-instant, mixtral-8x7b-32768, and deepseek-r1-distill-llama-70b — are all currently listed as active on the Groq console, whereas the replacement identifiers llama3-70b-8192 and llama3-8b-8192 correspond to older base Llama 3 checkpoints. If this is intentional, a comment explaining the rationale would be helpful; otherwise it looks like the newer, more capable model IDs were accidentally reverted.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: git fetch upstream master && git rebase upstream/master.

2 similar comments
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: git fetch upstream master && git rebase upstream/master.

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: git fetch upstream master && git rebase upstream/master.

@ralyodio

ralyodio commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

tests are failing please fix.

@ralyodio ralyodio closed this Jun 4, 2026
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