From 1072583f03bcaca4f5495b04a504824766da4a6a Mon Sep 17 00:00:00 2001 From: Narendranath Gogineni Date: Wed, 11 Dec 2024 09:00:52 +0530 Subject: [PATCH 1/3] fix: groq finish reason mapping --- src/providers/groq/chatComplete.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/providers/groq/chatComplete.ts b/src/providers/groq/chatComplete.ts index aa824f44e..8478bd769 100644 --- a/src/providers/groq/chatComplete.ts +++ b/src/providers/groq/chatComplete.ts @@ -153,7 +153,7 @@ export const GroqChatCompleteStreamChunkTransform: ( index: parsedChunk.choices[0].index || 0, delta: {}, logprobs: null, - finish_reason: parsedChunk.choices[0].index, + finish_reason: parsedChunk.choices[0].finish_reason, }, ], usage: { From 1584ee4366a4f2334a57a512d1884c537689b2a2 Mon Sep 17 00:00:00 2001 From: Narendranath Gogineni Date: Wed, 11 Dec 2024 11:18:44 +0530 Subject: [PATCH 2/3] update transformers for groq --- src/providers/groq/chatComplete.ts | 2 ++ src/providers/groq/index.ts | 17 +++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/providers/groq/chatComplete.ts b/src/providers/groq/chatComplete.ts index 8478bd769..15a8278dd 100644 --- a/src/providers/groq/chatComplete.ts +++ b/src/providers/groq/chatComplete.ts @@ -72,6 +72,7 @@ export interface GroqStreamChunk { choices: { delta: { content?: string; + tool_calls?: object[]; }; index: number; finish_reason: string | null; @@ -175,6 +176,7 @@ export const GroqChatCompleteStreamChunkTransform: ( delta: { role: 'assistant', content: parsedChunk.choices[0].delta.content, + tool_calls: parsedChunk.choices[0].delta?.tool_calls, }, logprobs: null, finish_reason: parsedChunk.choices[0].finish_reason || null, diff --git a/src/providers/groq/index.ts b/src/providers/groq/index.ts index 2ed4bd436..867dd80a1 100644 --- a/src/providers/groq/index.ts +++ b/src/providers/groq/index.ts @@ -1,16 +1,21 @@ import { ProviderConfigs } from '../types'; import GroqAPIConfig from './api'; +import { GroqChatCompleteStreamChunkTransform } from './chatComplete'; import { - GroqChatCompleteConfig, - GroqChatCompleteResponseTransform, - GroqChatCompleteStreamChunkTransform, -} from './chatComplete'; + chatCompleteParams, + completeParams, + embedParams, + responseTransformers, +} from '../open-ai-base'; +import { GROQ } from '../../globals'; const GroqConfig: ProviderConfigs = { - chatComplete: GroqChatCompleteConfig, + chatComplete: chatCompleteParams(['logprobs', 'logits_bias', 'top_logprobs']), api: GroqAPIConfig, responseTransforms: { - chatComplete: GroqChatCompleteResponseTransform, + ...responseTransformers(GROQ, { + chatComplete: true, + }), 'stream-chatComplete': GroqChatCompleteStreamChunkTransform, }, }; From b12e66d6b1764d7e7abed6f3207015ecba2a1b5b Mon Sep 17 00:00:00 2001 From: Narendranath Gogineni Date: Wed, 11 Dec 2024 12:09:47 +0530 Subject: [PATCH 3/3] remove unused imports --- src/providers/groq/chatComplete.ts | 57 +----------------------------- src/providers/groq/index.ts | 7 +--- 2 files changed, 2 insertions(+), 62 deletions(-) diff --git a/src/providers/groq/chatComplete.ts b/src/providers/groq/chatComplete.ts index 15a8278dd..9c39940b1 100644 --- a/src/providers/groq/chatComplete.ts +++ b/src/providers/groq/chatComplete.ts @@ -1,65 +1,10 @@ import { GROQ } from '../../globals'; -import { - ChatCompletionResponse, - ErrorResponse, - ProviderConfig, -} from '../types'; +import { ChatCompletionResponse, ErrorResponse } from '../types'; import { generateErrorResponse, generateInvalidProviderResponseError, } from '../utils'; -export const GroqChatCompleteConfig: ProviderConfig = { - model: { - param: 'model', - required: true, - default: 'mixtral-8x7b-32768', - }, - messages: { - param: 'messages', - default: '', - }, - max_tokens: { - param: 'max_tokens', - default: 100, - min: 0, - }, - max_completion_tokens: { - param: 'max_tokens', - default: 100, - min: 0, - }, - temperature: { - param: 'temperature', - default: 1, - min: 0, - max: 2, - }, - top_p: { - param: 'top_p', - default: 1, - min: 0, - max: 1, - }, - stream: { - param: 'stream', - default: false, - }, - stop: { - param: 'stop', - }, - n: { - param: 'n', - default: 1, - max: 1, - min: 1, - }, - tools: { - param: 'tools', - required: false, - }, -}; - export interface GroqChatCompleteResponse extends ChatCompletionResponse {} export interface GroqErrorResponse extends ErrorResponse {} diff --git a/src/providers/groq/index.ts b/src/providers/groq/index.ts index 867dd80a1..27c7907d1 100644 --- a/src/providers/groq/index.ts +++ b/src/providers/groq/index.ts @@ -1,12 +1,7 @@ import { ProviderConfigs } from '../types'; import GroqAPIConfig from './api'; import { GroqChatCompleteStreamChunkTransform } from './chatComplete'; -import { - chatCompleteParams, - completeParams, - embedParams, - responseTransformers, -} from '../open-ai-base'; +import { chatCompleteParams, responseTransformers } from '../open-ai-base'; import { GROQ } from '../../globals'; const GroqConfig: ProviderConfigs = {