MCPcopy Index your code
hub / github.com/CommandCodeAI/BaseAI / callLLM

Function callLLM

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

Source from the content-addressed store, hash-verified

30import type { PipeTool } from 'types/tools';
31
32export async function callLLM({
33 pipe,
34 stream,
35 messages,
36 llmApiKey,
37 variables,
38 paramsTools
39}: {
40 pipe: Pipe;
41 stream: boolean;
42 llmApiKey: string;
43 messages: Message[];
44 variables?: VariablesI;
45 paramsTools: PipeTool[] | undefined;
46}) {
47 try {
48 // Get the model provider from the pipe.
49 const providerString = pipe.model.split(':')[0];
50 const modelProvider = getProvider(providerString);
51
52 const memoryNames = pipe.memory.map(memory => memory.name);
53
54 const similarChunks = await addContextFromMemory({
55 messages,
56 memoryNames
57 });
58
59 // Process the messages to be sent to the model provider.
60 const messagesThread = getRunThread({
61 pipe,
62 messages,
63 similarChunks,
64 variables
65 });
66 messages = messagesThread;
67
68 dlog('Messages for LLM', messages);
69
70 if (modelProvider === OPEN_AI) {
71 dlog('OPEN_AI', '✅');
72 return await callOpenAI({
73 pipe,
74 stream,
75 messages,
76 llmApiKey,
77 paramsTools
78 });
79 }
80
81 if (modelProvider === ANTHROPIC) {
82 dlog('ANTHROPIC', '✅');
83 return await callAnthropic({
84 pipe,
85 stream,
86 messages,
87 llmApiKey,
88 paramsTools
89 });

Callers 2

handleRunFunction · 0.90
handleRunFunction · 0.90

Calls 14

getProviderFunction · 0.90
addContextFromMemoryFunction · 0.90
getRunThreadFunction · 0.90
dlogFunction · 0.90
callOpenAIFunction · 0.90
callAnthropicFunction · 0.90
callTogetherFunction · 0.90
callGroqFunction · 0.90
callGoogleFunction · 0.90
callXAIFunction · 0.90
callCohereFunction · 0.90
callFireworksFunction · 0.90

Tested by

no test coverage detected