forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannotated-function.ts
More file actions
33 lines (29 loc) · 1012 Bytes
/
Copy pathannotated-function.ts
File metadata and controls
33 lines (29 loc) · 1012 Bytes
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
import { AnnotatedFunction, Function } from "../types";
export function annotatedFunctionToChatCompletionFunction(
annotatedFunction: AnnotatedFunction<any[]>,
): Function {
// Create the parameters object based on the argumentAnnotations
let parameters: { [key: string]: any } = {};
for (let arg of annotatedFunction.argumentAnnotations) {
// isolate the args we should forward inline
let { name, required, ...forwardedArgs } = arg;
parameters[arg.name] = forwardedArgs;
}
let requiredParameterNames: string[] = [];
for (let arg of annotatedFunction.argumentAnnotations) {
if (arg.required) {
requiredParameterNames.push(arg.name);
}
}
// Create the ChatCompletionFunctions object
let chatCompletionFunction: Function = {
name: annotatedFunction.name,
description: annotatedFunction.description,
parameters: {
type: "object",
properties: parameters,
required: requiredParameterNames,
},
};
return chatCompletionFunction;
}