@promptbook/azure-openai
Version:
Promptbook: Run AI apps in plain human language across multiple models and platforms
120 lines (119 loc) • 3.81 kB
TypeScript
import type { Observable } from 'rxjs';
import { PartialDeep } from 'type-fest';
import type { task_id } from '../types/typeAliases';
import type { string_SCREAMING_CASE } from '../utils/normalization/normalizeTo_SCREAMING_CASE';
import type { string_promptbook_version } from '../version';
import type { AbstractTaskResult } from './AbstractTaskResult';
import type { PipelineExecutorResult } from './PipelineExecutorResult';
/**
* Options for creating a new task
*/
type CreateTaskOptions<TTaskResult extends AbstractTaskResult> = {
/**
* The type of task to create
*/
readonly taskType: AbstractTask<TTaskResult>['taskType'];
/**
* Human-readable title of the task - used for displaying in the UI
*/
readonly title: AbstractTask<TTaskResult>['title'];
/**
* Callback that processes the task and updates the ongoing result
* @param ongoingResult The partial result of the task processing
* @returns The final task result
*/
taskProcessCallback(updateOngoingResult: (newOngoingResult: PartialDeep<TTaskResult> & {
/**
* Optional update of the task title
*/
readonly title?: AbstractTask<TTaskResult>['title'];
}) => void): Promise<TTaskResult>;
};
/**
* Helper to create a new task
*
* @private internal helper function
*/
export declare function createTask<TTaskResult extends AbstractTaskResult>(options: CreateTaskOptions<TTaskResult>): AbstractTask<TTaskResult>;
/**
* Represents a task that executes a pipeline
*/
export type ExecutionTask = AbstractTask<PipelineExecutorResult> & {
readonly taskType: 'EXECUTION';
readonly taskId: `exec-${task_id}`;
};
/**
* Represents a task that prepares a pipeline
* @deprecated TODO: [🐚] Currently unused - use
*/
export type PreparationTask = AbstractTask<PipelineExecutorResult> & {
readonly taskType: 'PREPARATION';
readonly taskId: `prep-${task_id}`;
};
/**
* Status of a task
*/
export type task_status = 'RUNNING' | 'FINISHED' | 'ERROR';
/**
* Base interface for all task types
*/
export type AbstractTask<TTaskResult extends AbstractTaskResult> = {
/**
* Type of the task
*/
readonly taskType: string_SCREAMING_CASE;
/**
* Version of the promptbook used to run the task
*/
readonly promptbookVersion: string_promptbook_version;
/**
* Unique identifier for the task
*/
readonly taskId: task_id;
/**
* Human-readable title of the task - used for displaying in the UI
*
* For example name of the book which is being executed
*/
readonly title: string;
/**
* Status of the task
*/
readonly status: task_status;
/**
* Date when the task was created
*/
readonly createdAt: Date;
/**
* Date when the task was last updated
*/
readonly updatedAt: Date;
/**
* Gets a promise that resolves with the task result
*/
asPromise(options?: {
readonly isCrashedOnError?: boolean;
}): Promise<TTaskResult>;
/**
* Gets an observable stream of partial task results
*/
asObservable(): Observable<PartialDeep<TTaskResult>>;
/**
* Gets just the current value which is mutated during the task processing
*/
readonly currentValue: PartialDeep<TTaskResult>;
/**
* List of errors that occurred during the task processing
*/
readonly errors: Array<Error>;
/**
* List of warnings that occurred during the task processing
*/
readonly warnings: Array<Error>;
};
export type Task = ExecutionTask | PreparationTask;
export {};
/**
* TODO: Maybe allow to terminate the task and add getter `isFinished` or `status`
* TODO: [🐚] Split into more files and make `PrepareTask` & `RemoteTask` + split the function
*/