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

Function callPerplexity

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

Source from the content-addressed store, hash-verified

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

Callers 1

callLLMFunction · 0.90

Calls 5

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

Tested by

no test coverage detected