MCPcopy Create free account
hub / github.com/CommandCodeAI/BaseAI / callGroq

Function callGroq

packages/baseai/src/dev/llms/call-groq.ts:9–42  ·  view source on GitHub ↗
({
	pipe,
	messages,
	llmApiKey,
	stream
}: {
	pipe: Pipe;
	llmApiKey: string;
	stream: boolean;
	messages: Message[];
})

Source from the content-addressed store, hash-verified

7import type { Message, Pipe } from 'types/pipe';
8
9export async function callGroq({
10 pipe,
11 messages,
12 llmApiKey,
13 stream
14}: {
15 pipe: Pipe;
16 llmApiKey: string;
17 stream: boolean;
18 messages: Message[];
19}) {
20 try {
21 const modelParams = buildModelParams(pipe, stream, messages);
22 const groq = new OpenAI({
23 apiKey: llmApiKey,
24 baseURL: 'https://api.groq.com/openai/v1'
25 });
26 applyJsonModeIfEnabled(modelParams, pipe);
27
28 // Transform params according to provider's format
29 const transformedRequestParams = transformToProviderRequest({
30 provider: GROQ,
31 params: modelParams as ModelParams,
32 fn: 'chatComplete'
33 });
34 dlog('Groq request params', transformedRequestParams);
35
36 return await groq.chat.completions.create(
37 transformedRequestParams as any
38 );
39 } catch (error: any) {
40 handleLlmError({ error, provider: GROQ });
41 }
42}
43
44function buildModelParams(
45 pipe: Pipe,

Callers 1

callLLMFunction · 0.90

Calls 5

applyJsonModeIfEnabledFunction · 0.90
dlogFunction · 0.90
handleLlmErrorFunction · 0.90
buildModelParamsFunction · 0.70

Tested by

no test coverage detected