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

Function callCohere

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

Source from the content-addressed store, hash-verified

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