app/agent/groqBackend.ts
zzmq.dev@gmail.com/zz / app / agent / groqBackend.ts
@ b65abfa6
Download
Ladder Summary
- file The file implements a Groq‑specific chat backend by wrapping the generic OpenAI‑compatible backend creator. It reads the `GROQ_API_KEY` environment variable (throwing an error if it’s missing) and exports a single function **`createGroqBackend(model: string): ChatBackend`**, which returns a `ChatBackend` configured to call Groq’s `https://api.groq.com/openai/v1/chat/completions` endpoint with the supplied model name. No classes are exported.
// Groq as a remote backend -- OpenAI-compatible chat completions on
// LPU hardware, notable mainly for raw speed (observed far faster
// token generation than either local Ollama or Gemini's free tier) and
// a generous free quota (30 req/min, 1000/day at time of writing).
import { createOpenAiCompatBackend } from "./openaiCompatBackend.js";
import type { ChatBackend } from "./chatBackend.js";
function apiKey(): string {
const key = process.env.GROQ_API_KEY;
if (!key) throw new Error("Groq backend needs an API key: set GROQ_API_KEY in your environment or app/.env. Get a free key at https://console.groq.com/keys -- never paste the key itself into chat.");
return key;
}
export function createGroqBackend(model: string): ChatBackend {
// Resolved eagerly, not passed as a lazy callback -- callers (zz
// work/--assist) call this before resolveCliBackendMode/
// enterFullscreen, specifically so a missing key fails fast as a
// plain CLI error instead of surfacing deep inside a TUI session on
// the first draft attempt (confirmed live: that's exactly what used
// to happen).
const key = apiKey();
return createOpenAiCompatBackend({
name: `groq:${model}`,
url: "https://api.groq.com/openai/v1/chat/completions",
model,
apiKey: () => key,
});
}