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

Function callOpenAI

packages/baseai/src/dev/llms/call-openai.ts:12–39  ·  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

10import type { PipeTool } from 'types/tools';
11
12export async function callOpenAI({
13 pipe,
14 stream,
15 llmApiKey,
16 messages,
17 paramsTools
18}: {
19 pipe: Pipe;
20 stream: boolean;
21 llmApiKey: string;
22 messages: Message[];
23 paramsTools: PipeTool[] | undefined;
24}) {
25 try {
26 validateInput(pipe, messages);
27 const openai = new OpenAI({ apiKey: llmApiKey });
28 await moderateContent(openai, messages, pipe.moderate);
29
30 const modelParams = buildModelParams(pipe, stream, messages);
31 addToolsToParams(modelParams, pipe, paramsTools);
32 applyJsonModeIfEnabled(modelParams, pipe);
33
34 dlog('modelParams', modelParams);
35 return await openai.chat.completions.create(modelParams as any);
36 } catch (error: any) {
37 handleLlmError({ error, provider: OPEN_AI });
38 }
39}
40
41function validateInput(pipe: Pipe, messages: Message[]) {
42 if (!pipe || !pipe.model || !messages || messages.length === 0) {

Callers 1

callLLMFunction · 0.90

Calls 7

addToolsToParamsFunction · 0.90
applyJsonModeIfEnabledFunction · 0.90
dlogFunction · 0.90
handleLlmErrorFunction · 0.90
validateInputFunction · 0.85
moderateContentFunction · 0.85
buildModelParamsFunction · 0.70

Tested by

no test coverage detected