assistan-ts
Version:
A typesafe and code-first library to define and run OpenAI assistants
82 lines • 4.1 kB
TypeScript
import { TSchema } from "@sinclair/typebox";
import { AssistantCreateParams, AssistantFunction, OpenAI } from "./types/openai";
import type { FileLike } from "openai/uploads";
export declare const METADATA_KEY = "__key__";
export declare const definition: <T extends Record<string, FunctionTool>>(definition: AssistantDefinition<T>) => {
/** Find the matching assistant and sync the definition with openai */
link: (openai: OpenAI, options: import("./link").LinkOptions) => Promise<import("./link").LinkedDefinition<T>>;
link__unsafe: (props: {
openai: OpenAI;
assistantId: string;
}) => {
openai: OpenAI;
id: string;
/** A unique key that is added to the assistant metadata in order to resolve the matching assistant */
key: string;
functionTools?: T | undefined;
codeInterpreter?: boolean | undefined;
retrieval?: boolean | undefined;
files?: {
/** Hard coded ids to link to assistant. If a resolve function is also passed, these will be merged in */
file_ids?: string[] | undefined;
/** Function to load files from filesystem, API, etc */
resolve?: (() => Promise<FileLike[]>) | undefined;
/** When the output of these functions matches, the files are considered matches */
keyFns?: {
resolved: (local: FileLike) => string;
remote: (remote: OpenAI.Files.FileObject) => string;
} | undefined;
} | undefined;
name?: string | null | undefined;
metadata?: unknown;
description?: string | null | undefined;
model: string;
instructions?: string | null | undefined;
};
/** A unique key that is added to the assistant metadata in order to resolve the matching assistant */
key: string;
functionTools?: T | undefined;
codeInterpreter?: boolean | undefined;
retrieval?: boolean | undefined;
files?: {
/** Hard coded ids to link to assistant. If a resolve function is also passed, these will be merged in */
file_ids?: string[] | undefined;
/** Function to load files from filesystem, API, etc */
resolve?: (() => Promise<FileLike[]>) | undefined;
/** When the output of these functions matches, the files are considered matches */
keyFns?: {
resolved: (local: FileLike) => string;
remote: (remote: OpenAI.Files.FileObject) => string;
} | undefined;
} | undefined;
name?: string | null | undefined;
metadata?: unknown;
description?: string | null | undefined;
model: string;
instructions?: string | null | undefined;
};
export interface AssistantDefinition<T extends Record<string, FunctionTool>> extends Omit<AssistantCreateParams, "tools" | "file_ids"> {
/** A unique key that is added to the assistant metadata in order to resolve the matching assistant */
key: string;
functionTools?: T;
codeInterpreter?: boolean;
retrieval?: boolean;
files?: {
/** Hard coded ids to link to assistant. If a resolve function is also passed, these will be merged in */
file_ids?: string[];
/** Function to load files from filesystem, API, etc */
resolve?: () => Promise<FileLike[]>;
/** When the output of these functions matches, the files are considered matches */
keyFns?: {
resolved: (local: FileLike) => string;
remote: (remote: OpenAI.Files.FileObject) => string;
};
};
}
export declare const toPayload: (assistant: AssistantDefinition<any>) => AssistantCreateParams;
export declare const toolsToPayload: (def: Pick<AssistantDefinition<any>, "functionTools" | "codeInterpreter" | "retrieval">) => AssistantCreateParams["tools"];
export type FunctionTool = Omit<AssistantFunction["function"], "parameters" | "name"> & {
parameters: TSchema;
};
export declare const functionsToPayload: <T extends Record<string, FunctionTool>>(functionTools: T) => AssistantFunction[];
//# sourceMappingURL=definition.d.ts.map