-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathprompt-layer.ts
41 lines (39 loc) · 1.16 KB
/
prompt-layer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import type { OpenAI as OpenAIClient } from "openai";
import { AsyncCaller } from "@langchain/core/utils/async_caller";
export const promptLayerTrackRequest = async (
callerFunc: AsyncCaller,
functionName: string,
kwargs:
| OpenAIClient.CompletionCreateParams
| OpenAIClient.Chat.CompletionCreateParams,
plTags: string[] | undefined,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
requestResponse: any,
startTime: number,
endTime: number,
apiKey: string | undefined
) => {
// https://github.com/MagnivOrg/promptlayer-js-helper
const promptLayerResp = await callerFunc.call(
fetch,
"https://api.promptlayer.com/track-request",
{
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
function_name: functionName,
provider: "langchain",
kwargs,
tags: plTags,
request_response: requestResponse,
request_start_time: Math.floor(startTime / 1000),
request_end_time: Math.floor(endTime / 1000),
api_key: apiKey,
}),
}
);
return promptLayerResp.json();
};