zz_

app/agent/groqBackend.ts

zzmq.dev@gmail.com/zz / app / agent / groqBackend.ts @ b9c01cc1 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 {
  return createOpenAiCompatBackend({
  name: `groq:${model}`,
  url: "https://api.groq.com/openai/v1/chat/completions",
  model,
  apiKey,
  });
 }