({
pipe,
stream,
llmApiKey,
messages,
paramsTools
}: {
pipe: Pipe;
stream: boolean;
llmApiKey: string;
messages: Message[];
paramsTools: PipeTool[] | undefined;
})
| 8 | import type { PipeTool } from 'types/tools'; |
| 9 | |
| 10 | export async function callXAI({ |
| 11 | pipe, |
| 12 | stream, |
| 13 | llmApiKey, |
| 14 | messages, |
| 15 | paramsTools |
| 16 | }: { |
| 17 | pipe: Pipe; |
| 18 | stream: boolean; |
| 19 | llmApiKey: string; |
| 20 | messages: Message[]; |
| 21 | paramsTools: PipeTool[] | undefined; |
| 22 | }) { |
| 23 | try { |
| 24 | const modelParams = buildModelParams(pipe, stream, messages); |
| 25 | |
| 26 | // LLM. |
| 27 | const groq = new OpenAI({ |
| 28 | apiKey: llmApiKey, |
| 29 | baseURL: 'https://api.x.ai/v1' |
| 30 | }); |
| 31 | |
| 32 | // Add tools (functions) to modelParams |
| 33 | addToolsToParams(modelParams, pipe, paramsTools); |
| 34 | dlog('modelParams', modelParams); |
| 35 | |
| 36 | return await groq.chat.completions.create(modelParams as any); |
| 37 | } catch (error: any) { |
| 38 | handleLlmError({ error, provider: X_AI }); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | function buildModelParams( |
| 43 | pipe: Pipe, |
no test coverage detected