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

Function callXAI

packages/baseai/src/dev/llms/call-xai.ts:10–40  ·  view source on GitHub ↗
({
	pipe,
	stream,
	llmApiKey,
	messages,
	paramsTools
}: {
	pipe: Pipe;
	stream: boolean;
	llmApiKey: string;
	messages: Message[];
	paramsTools: PipeTool[] | undefined;
})

Source from the content-addressed store, hash-verified

8import type { PipeTool } from 'types/tools';
9
10export 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
42function buildModelParams(
43 pipe: Pipe,

Callers 1

callLLMFunction · 0.90

Calls 4

addToolsToParamsFunction · 0.90
dlogFunction · 0.90
handleLlmErrorFunction · 0.90
buildModelParamsFunction · 0.70

Tested by

no test coverage detected