ai-functions 0.2.4 → 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.
Files changed (2) hide show
  1. package/functions/ai.ts +8 -8
  2. 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 extends Record<string, any> = Record<string,any>> = {
22
- [K in keyof T]: (
23
- returnSchema: T[K],
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<{ [K in keyof T]: T[K] }>
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
- return (returnSchema: Record<string,any>, options: FunctionCallOptions) => async (args: string | object, callOptions?: FunctionCallOptions) => {
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
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-functions",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Library for Developing and Managing AI Functions (including OpenAI GPT4 / GPT3.5)",
5
5
  "main": "index.js",
6
6
  "type": "module",