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

Function callAnthropic

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

Source from the content-addressed store, hash-verified

9import type { PipeTool } from 'types/tools';
10
11export async function callAnthropic({
12 pipe,
13 messages,
14 llmApiKey,
15 stream,
16 paramsTools
17}: {
18 pipe: Pipe;
19 llmApiKey: string;
20 stream: boolean;
21 messages: Message[];
22 paramsTools: PipeTool[] | undefined;
23}) {
24 try {
25 const modelParams = buildModelParams(pipe, stream, messages);
26 addToolsToParams(modelParams, pipe, paramsTools);
27
28 // Transform params according to provider's format
29 const transformedRequestParams = transformToProviderRequest({
30 provider: ANTHROPIC,
31 params: modelParams,
32 fn: 'chatComplete'
33 });
34 dlog('Anthropic request params', transformedRequestParams);
35
36 const providerOptions = { provider: ANTHROPIC, llmApiKey };
37
38 return await handleProviderRequest({
39 providerOptions,
40 inputParams: modelParams,
41 endpoint: 'chatComplete',
42 transformedRequestParams
43 });
44 } catch (error: any) {
45 handleLlmError({ error, provider: ANTHROPIC });
46 }
47}
48
49function buildModelParams(
50 pipe: Pipe,

Callers 1

callLLMFunction · 0.90

Calls 6

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

Tested by

no test coverage detected