functions.do
Version:
A framework and platform for easily creating, managing, evaluating, and iterating on AI functions & object generation
40 lines • 1.4 kB
TypeScript
export type ModelName = string;
export interface AIConfig {
model?: ModelName;
system?: string;
temperature?: number;
seed?: number;
schema?: Record<string, any>;
}
export type AIFunction<TInput = any, TOutput = any> = {
(input: TInput, config?: AIConfig): Promise<TOutput>;
};
export type SchemaValue = string | string[] | {
[key: string]: SchemaValue;
} | SchemaValue[];
export type FunctionDefinition = Record<string, SchemaValue>;
type SchemaToOutput<T extends FunctionDefinition> = {
[K in keyof T]: T[K] extends Array<infer U> ? U extends Record<string, any> ? Array<{
[P in keyof U]: SchemaToOutput<{
value: U[P];
}>['value'];
}> : string[] : T[K] extends Record<string, any> ? {
[P in keyof T[K]]: SchemaToOutput<{
value: T[K][P];
}>['value'];
} : string;
};
export type FunctionCallback<TArgs = any> = (context: {
ai: AI_Instance;
args: TArgs;
}) => any | Promise<any>;
export type AI = {
<T extends Record<string, FunctionDefinition | FunctionCallback>>(functions: T, config?: AIConfig): {
[K in keyof T]: T[K] extends FunctionDefinition ? AIFunction<any, SchemaToOutput<T[K]>> : T[K] extends FunctionCallback<infer TArgs> ? FunctionCallback<TArgs> : never;
};
};
export type AI_Instance = {
[K: string]: AIFunction;
};
export {};
//# sourceMappingURL=types.d.ts.map