UNPKG

assistan-ts

Version:

A typesafe and code-first library to define and run OpenAI assistants

46 lines 1.93 kB
import { FunctionTool } from "./definition"; import { LinkedDefinition } from "./link"; import { RunOptions, ToolsRequiredResponse } from "./run"; import { ToolBox, ToolOptions, ToolsDefsToToolbox } from "./toolbox"; import { Run, RunCreateParams, OpenAI } from "./types/openai"; export type Assistant<T extends Record<string, FunctionTool>> = { /** A definition that has been "linked" to OpenAI */ definition: LinkedDefinition<T>; /** The toolbox that was created from the definition + tool functions */ toolbox: ToolBox<T>; /** Run related functions */ run: { /** Create a new run */ create: (params: { threadId: string; body?: Omit<RunCreateParams, "assistant_id">; options?: OpenAI.RequestOptions; }) => Promise<SetupRunResponse>; /** Load an existing run */ load: (run: Run) => SetupRunResponse; }; }; type SetupRunResponse = { run: OpenAI.Beta.Threads.Runs.Run; toolsRequired: (opts?: RunOptions & { timeout?: number; }) => Promise<ToolsRequiredResponse>; complete: (opts?: RunOptions & { timeout?: number; }) => Promise<OpenAI.Beta.Threads.Runs.Run>; }; type Props<T extends Record<string, FunctionTool>> = { /** A definition that has been "linked" to OpenAI */ definition: LinkedDefinition<T>; /** Functions matching the tool definitions */ tools: ToolsDefsToToolbox<T>; /** Options to pass to the toolbox */ toolOptions?: Partial<ToolOptions>; /** Override the toolbox before creating a run * @param base The toolbox that was created from the definition */ toolBoxOverride?: (base: ToolBox<T>) => ToolBox<any>; }; export declare const assistant: <T extends Record<string, FunctionTool>>({ definition, tools, toolOptions, toolBoxOverride: overrideToolbox, }: Props<T>) => Assistant<T>; export {}; //# sourceMappingURL=assistant.d.ts.map