-
-
Notifications
You must be signed in to change notification settings - Fork 257
Feat/ai-groq-summarize #837
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| '@tanstack/ai-groq': minor | ||
| --- | ||
|
|
||
| feat: add groqSummarize and createGroqSummarize adapters | ||
|
|
||
| Groq now exposes tree-shakeable summarize factories that wrap `GroqTextAdapter` | ||
| in `ChatStreamSummarizeAdapter`, matching the pattern used by OpenAI, Anthropic, | ||
| Gemini, Ollama, Grok, and OpenRouter. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { ChatStreamSummarizeAdapter } from '@tanstack/ai/adapters' | ||
| import { getGroqApiKeyFromEnv } from '../utils' | ||
| import { GroqTextAdapter } from './text' | ||
| import type { InferTextProviderOptions } from '@tanstack/ai/adapters' | ||
| import type { GROQ_CHAT_MODELS } from '../model-meta' | ||
| import type { GroqClientConfig } from '../utils' | ||
|
|
||
| /** | ||
| * Configuration for Groq summarize adapter | ||
| */ | ||
| export interface GroqSummarizeConfig extends GroqClientConfig {} | ||
|
|
||
| /** Model type for Groq summarization */ | ||
| export type GroqSummarizeModel = (typeof GROQ_CHAT_MODELS)[number] | ||
|
|
||
| /** | ||
| * Creates a Groq summarize adapter with explicit API key. | ||
| * Type resolution happens here at the call site. | ||
| * | ||
| * @param model - The model name (e.g., 'llama-3.3-70b-versatile') | ||
| * @param apiKey - Your Groq API key | ||
| * @param config - Optional additional configuration | ||
| * @returns Configured Groq summarize adapter instance with resolved types | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const adapter = createGroqSummarize('llama-3.3-70b-versatile', "gsk_..."); | ||
| * ``` | ||
| */ | ||
| export function createGroqSummarize<TModel extends GroqSummarizeModel>( | ||
| model: TModel, | ||
| apiKey: string, | ||
| config?: Omit<GroqSummarizeConfig, 'apiKey'>, | ||
| ): ChatStreamSummarizeAdapter< | ||
| TModel, | ||
| InferTextProviderOptions<GroqTextAdapter<TModel>> | ||
| > { | ||
| return new ChatStreamSummarizeAdapter( | ||
| new GroqTextAdapter({ apiKey, ...config }, model), | ||
| model, | ||
| 'groq', | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Creates a Groq summarize adapter with automatic API key detection from environment variables. | ||
| * Type resolution happens here at the call site. | ||
| * | ||
| * Looks for `GROQ_API_KEY` in: | ||
| * - `process.env` (Node.js) | ||
| * - `window.env` (Browser with injected env) | ||
| * | ||
| * @param model - The model name (e.g., 'llama-3.3-70b-versatile') | ||
| * @param config - Optional configuration (excluding apiKey which is auto-detected) | ||
| * @returns Configured Groq summarize adapter instance with resolved types | ||
| * @throws Error if GROQ_API_KEY is not found in environment | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * // Automatically uses GROQ_API_KEY from environment | ||
| * const adapter = groqSummarize('llama-3.3-70b-versatile'); | ||
| * | ||
| * await summarize({ | ||
| * adapter, | ||
| * text: "Long article text..." | ||
| * }); | ||
| * ``` | ||
| */ | ||
| export function groqSummarize<TModel extends GroqSummarizeModel>( | ||
| model: TModel, | ||
| config?: Omit<GroqSummarizeConfig, 'apiKey'>, | ||
| ): ChatStreamSummarizeAdapter< | ||
| TModel, | ||
| InferTextProviderOptions<GroqTextAdapter<TModel>> | ||
| > { | ||
| return createGroqSummarize(model, getGroqApiKeyFromEnv(), config) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import { createOpenaiSummarize } from '@tanstack/ai-openai' | |
| import { createAnthropicSummarize } from '@tanstack/ai-anthropic' | ||
| import { createGeminiSummarize } from '@tanstack/ai-gemini' | ||
| import { createOllamaSummarize } from '@tanstack/ai-ollama' | ||
| import { createGroqSummarize } from '@tanstack/ai-groq' | ||
| import { createGrokSummarize } from '@tanstack/ai-grok' | ||
| import { createOpenRouterSummarize } from '@tanstack/ai-openrouter' | ||
| import type { Provider } from '@/lib/types' | ||
|
|
@@ -46,6 +47,11 @@ function createSummarizeAdapter( | |
| httpOptions: { baseUrl: llmockBase(aimockPort), headers }, | ||
| }), | ||
| ollama: () => createOllamaSummarize('mistral', llmockBase(aimockPort)), | ||
| groq: () => | ||
| createGroqSummarize('llama-3.3-70b-versatile', DUMMY_KEY, { | ||
| baseURL: llmockBase(aimockPort), | ||
| defaultHeaders: headers, | ||
| }), | ||
|
Comment on lines
+50
to
+54
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Inspect how GroqTextAdapter builds its request URL from baseURL/config
fd -t f . packages/ai-groq/src -e ts | xargs rg -nC3 'baseURL|/v1|chat/completions|new URL|fetch\('
# Compare with grok adapter URL construction
fd -t f . packages/ai-grok/src -e ts | xargs rg -nC3 'baseURL|/v1|chat/completions'Repository: TanStack/ai Length of output: 20493 Ensure Groq e2e tests target the The Groq adapter expects endpoints under Update the configuration to append the Groq-specific path: // testing/e2e/src/routes/api.summarize.ts
groq: () =>
createGroqSummarize('llama-3.3-70b-versatile', DUMMY_KEY, {
baseURL: `${llmockBase(aimockPort)}/openai/v1`,
defaultHeaders: headers,
}),🤖 Prompt for AI Agents |
||
| grok: () => | ||
| createGrokSummarize('grok-build-0.1', DUMMY_KEY, { | ||
| baseURL: openaiUrl(aimockPort), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Refresh the Groq entry’s
updatedAt.2026-06-18looks stale for this docs change; please bump it to2026-06-25so the navigation metadata stays accurate.As per coding guidelines,
docs/config.jsonentries must updateupdatedAtwhen making content changes.🛠️ Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Coding guidelines