ai-functions 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/functions/ai.ts +8 -8
- package/package.json +1 -1
package/functions/ai.ts
CHANGED
|
@@ -18,15 +18,14 @@ export type FunctionCallOptions = Omit<ChatCompletionCreateParamsBase, 'messages
|
|
|
18
18
|
description?: string
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
type AIFunctions<T
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
callOptions?: FunctionCallOptions
|
|
21
|
+
type AIFunctions<T = Record<string,string>> = Record<string, (
|
|
22
|
+
returnSchema: T,
|
|
23
|
+
options?: FunctionCallOptions
|
|
25
24
|
) => (
|
|
26
25
|
args: string | object,
|
|
27
26
|
callOptions?: FunctionCallOptions
|
|
28
|
-
) => Promise<
|
|
29
|
-
|
|
27
|
+
) => Promise<T>
|
|
28
|
+
>
|
|
30
29
|
|
|
31
30
|
export const AI = (config: AIConfig = {}) => {
|
|
32
31
|
const { model = 'gpt-4-1106-preview', system, ...rest } = config
|
|
@@ -44,10 +43,10 @@ export const AI = (config: AIConfig = {}) => {
|
|
|
44
43
|
// })
|
|
45
44
|
|
|
46
45
|
const ai: AIFunctions = new Proxy(
|
|
47
|
-
{},
|
|
46
|
+
{} as Record<string, any>,
|
|
48
47
|
{
|
|
49
48
|
get: (target, functionName: string, receiver) => {
|
|
50
|
-
|
|
49
|
+
target[functionName] = (returnSchema: Record<string,any>, options: FunctionCallOptions) => async (args: string | object, callOptions?: FunctionCallOptions) => {
|
|
51
50
|
console.log(generateSchema(returnSchema))
|
|
52
51
|
const { system, description, model = 'gpt-3.5-turbo', meta = false, ...rest } = { ...options, ...callOptions }
|
|
53
52
|
const prompt: ChatCompletionCreateParamsBase = {
|
|
@@ -104,6 +103,7 @@ export const AI = (config: AIConfig = {}) => {
|
|
|
104
103
|
console.log({ data, content, error, cost, usage: completion.usage })
|
|
105
104
|
return meta ? { prompt, content, data, error, cost, ...completion } : data ?? content
|
|
106
105
|
}
|
|
106
|
+
return target[functionName]
|
|
107
107
|
},
|
|
108
108
|
}
|
|
109
109
|
)
|