feat: Add GROQ API key support and integrate GROQ provider (#930)
* feat: Add GROQ API key support and integrate GROQ provider * feat: Add support for Groq provider - Added a new changeset documenting the addition of Groq provider support. -Ran npm run format * feat: Add support for Groq provider - Added a new changeset documenting the addition of Groq provider support. -Ran npm run format
This commit is contained in:
41
src/ai-providers/groq.js
Normal file
41
src/ai-providers/groq.js
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* src/ai-providers/groq.js
|
||||
*
|
||||
* Implementation for interacting with Groq models
|
||||
* using the Vercel AI SDK.
|
||||
*/
|
||||
|
||||
import { createGroq } from '@ai-sdk/groq';
|
||||
import { BaseAIProvider } from './base-provider.js';
|
||||
|
||||
export class GroqProvider extends BaseAIProvider {
|
||||
constructor() {
|
||||
super();
|
||||
this.name = 'Groq';
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a Groq client instance.
|
||||
* @param {object} params - Parameters for client initialization
|
||||
* @param {string} params.apiKey - Groq API key
|
||||
* @param {string} [params.baseURL] - Optional custom API endpoint
|
||||
* @returns {Function} Groq client function
|
||||
* @throws {Error} If API key is missing or initialization fails
|
||||
*/
|
||||
getClient(params) {
|
||||
try {
|
||||
const { apiKey, baseURL } = params;
|
||||
|
||||
if (!apiKey) {
|
||||
throw new Error('Groq API key is required.');
|
||||
}
|
||||
|
||||
return createGroq({
|
||||
apiKey,
|
||||
...(baseURL && { baseURL })
|
||||
});
|
||||
} catch (error) {
|
||||
this.handleError('client initialization', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ export { PerplexityAIProvider } from './perplexity.js';
|
||||
export { GoogleAIProvider } from './google.js';
|
||||
export { OpenAIProvider } from './openai.js';
|
||||
export { XAIProvider } from './xai.js';
|
||||
export { GroqProvider } from './groq.js';
|
||||
export { OpenRouterAIProvider } from './openrouter.js';
|
||||
export { OllamaAIProvider } from './ollama.js';
|
||||
export { BedrockAIProvider } from './bedrock.js';
|
||||
|
||||
Reference in New Issue
Block a user