feat(config): add support for groq AI provider, including config validation and engine implementation (#381)

This commit is contained in:
BILLY Maxime
2024-09-07 14:03:25 +02:00
committed by GitHub
parent a91aa3b4de
commit 2d7e3842d6
4 changed files with 40 additions and 8 deletions
+15 -2
View File
@@ -76,6 +76,16 @@ export const MODEL_LIST = {
'gemini-1.0-pro', 'gemini-1.0-pro',
'gemini-pro-vision', 'gemini-pro-vision',
'text-embedding-004' 'text-embedding-004'
],
groq: [
'llama3-70b-8192', // Meta Llama 3 70B (default one, no daily token limit and 14 400 reqs/day)
'llama3-8b-8192', // Meta Llama 3 8B
'llama-guard-3-8b', // Llama Guard 3 8B
'llama-3.1-8b-instant', // Llama 3.1 8B (Preview)
'llama-3.1-70b-versatile', // Llama 3.1 70B (Preview)
'gemma-7b-it', // Gemma 7B
'gemma2-9b-it' // Gemma 2 9B
] ]
}; };
@@ -87,6 +97,8 @@ const getDefaultModel = (provider: string | undefined): string => {
return MODEL_LIST.anthropic[0]; return MODEL_LIST.anthropic[0];
case 'gemini': case 'gemini':
return MODEL_LIST.gemini[0]; return MODEL_LIST.gemini[0];
case 'groq':
return MODEL_LIST.groq[0];
default: default:
return MODEL_LIST.openai[0]; return MODEL_LIST.openai[0];
} }
@@ -241,7 +253,7 @@ export const configValidators = {
validateConfig( validateConfig(
CONFIG_KEYS.OCO_AI_PROVIDER, CONFIG_KEYS.OCO_AI_PROVIDER,
['openai', 'anthropic', 'gemini', 'azure', 'test', 'flowise'].includes( ['openai', 'anthropic', 'gemini', 'azure', 'test', 'flowise', 'groq'].includes(
value value
) || value.startsWith('ollama'), ) || value.startsWith('ollama'),
`${value} is not supported yet, use 'ollama', 'anthropic', 'azure', 'gemini', 'flowise' or 'openai' (default)` `${value} is not supported yet, use 'ollama', 'anthropic', 'azure', 'gemini', 'flowise' or 'openai' (default)`
@@ -288,7 +300,8 @@ export enum OCO_AI_PROVIDER_ENUM {
GEMINI = 'gemini', GEMINI = 'gemini',
AZURE = 'azure', AZURE = 'azure',
TEST = 'test', TEST = 'test',
FLOWISE = 'flowise' FLOWISE = 'flowise',
GROQ = 'groq',
} }
export type ConfigType = { export type ConfigType = {
+10
View File
@@ -0,0 +1,10 @@
import { OpenAiConfig, OpenAiEngine } from './openAi';
interface GroqConfig extends OpenAiConfig {}
export class GroqEngine extends OpenAiEngine {
constructor(config: GroqConfig) {
config.baseURL = 'https://api.groq.com/openai/v1';
super(config);
}
}
+6 -1
View File
@@ -4,7 +4,7 @@ import { GenerateCommitMessageErrorEnum } from '../generateCommitMessageFromGitD
import { tokenCount } from '../utils/tokenCount'; import { tokenCount } from '../utils/tokenCount';
import { AiEngine, AiEngineConfig } from './Engine'; import { AiEngine, AiEngineConfig } from './Engine';
interface OpenAiConfig extends AiEngineConfig {} export interface OpenAiConfig extends AiEngineConfig {}
export class OpenAiEngine implements AiEngine { export class OpenAiEngine implements AiEngine {
config: OpenAiConfig; config: OpenAiConfig;
@@ -12,7 +12,12 @@ export class OpenAiEngine implements AiEngine {
constructor(config: OpenAiConfig) { constructor(config: OpenAiConfig) {
this.config = config; this.config = config;
if (!config.baseURL) {
this.client = new OpenAI({ apiKey: config.apiKey }); this.client = new OpenAI({ apiKey: config.apiKey });
} else {
this.client = new OpenAI({ apiKey: config.apiKey, baseURL: config.baseURL });
}
} }
public generateCommitMessage = async ( public generateCommitMessage = async (
+4
View File
@@ -7,6 +7,7 @@ import { GeminiEngine } from '../engine/gemini';
import { OllamaEngine } from '../engine/ollama'; import { OllamaEngine } from '../engine/ollama';
import { OpenAiEngine } from '../engine/openAi'; import { OpenAiEngine } from '../engine/openAi';
import { TestAi, TestMockType } from '../engine/testAi'; import { TestAi, TestMockType } from '../engine/testAi';
import { GroqEngine } from '../engine/groq';
export function getEngine(): AiEngine { export function getEngine(): AiEngine {
const config = getConfig(); const config = getConfig();
@@ -39,6 +40,9 @@ export function getEngine(): AiEngine {
case OCO_AI_PROVIDER_ENUM.FLOWISE: case OCO_AI_PROVIDER_ENUM.FLOWISE:
return new FlowiseEngine(DEFAULT_CONFIG); return new FlowiseEngine(DEFAULT_CONFIG);
case OCO_AI_PROVIDER_ENUM.GROQ:
return new GroqEngine(DEFAULT_CONFIG);
default: default:
return new OpenAiEngine(DEFAULT_CONFIG); return new OpenAiEngine(DEFAULT_CONFIG);
} }