Skip to content

Commit

Permalink
🍭
Browse files Browse the repository at this point in the history
  • Loading branch information
transitive-bullshit committed Jun 17, 2024
1 parent 0bd59f9 commit a102e21
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ export type MaybePromise<T> = T | Promise<T>
export type RelaxedJsonifiable = Jsonifiable | Record<string, Jsonifiable>

export interface AIFunctionSpec {
/** AI Function name. */
name: string

/** Description of what the function does. */
description: string

/** JSON schema spec of the function's input parameters */
parameters: Record<string, unknown>
}

Expand All @@ -36,6 +41,13 @@ export type AIFunctionImpl<Return> = Omit<
'name' | 'toString' | 'arguments' | 'caller' | 'prototype' | 'length'
>

/**
* Flexible type which accepts any AI-function-like object, including:
* - `AIFunctionSet` - Sets of AI functions
* - `AIFunctionsProvider` - Client classes which expose an `AIFunctionSet`
* via the `.functions` property
* - `AIFunction` - Individual functions
*/
export type AIFunctionLike = AIFunctionsProvider | AIFunction | AIFunctionSet

/**
Expand All @@ -45,6 +57,11 @@ export interface AIFunction<
InputSchema extends z.ZodObject<any> = z.ZodObject<any>,
Return = any
> {
/**
* Invokes the underlying AI function `impl` but first validates the input
* against this function's `inputSchema`. This method is callable and is
* meant to be passed the raw LLM JSON string or an OpenAI-compatible Message.
*/
(input: string | Msg): MaybePromise<Return>

/** The Zod schema for the input object. */
Expand All @@ -53,10 +70,12 @@ export interface AIFunction<
/** Parse the function arguments from a message. */
parseInput(input: string | Msg): z.infer<InputSchema>

/** The function spec for the OpenAI API `functions` property. */
/** The JSON schema function spec for the OpenAI API `functions` property. */
spec: AIFunctionSpec

/** The underlying function implementation without any arg parsing or validation. */
/**
* The underlying function implementation without any arg parsing or validation.
*/
// TODO: this `any` shouldn't be necessary, but it is for `createAIFunction` results to be assignable to `AIFunctionLike`
impl: (params: z.infer<InputSchema> | any) => MaybePromise<Return>
}

0 comments on commit a102e21

Please sign in to comment.