@promptbook/google
Version:
Promptbook: Turn your company's scattered knowledge into AI ready books
136 lines (135 loc) • 4.83 kB
TypeScript
import type { ClientOptions } from 'openai';
import OpenAI from 'openai';
import { TODO_any } from '../../_packages/types.index';
import type { string_title } from '../../types/typeAliases';
import type { OpenAiCompatibleExecutionToolsOptions } from './OpenAiCompatibleExecutionToolsOptions';
import { OpenAiExecutionTools } from './OpenAiExecutionTools';
/**
* Metadata for uploaded knowledge source files used for vector store diagnostics.
*/
type KnowledgeSourceUploadMetadata = {
readonly fileId: string;
readonly filename: string;
readonly sizeBytes?: number;
};
/**
* Shared options for OpenAI vector store handling.
*
* @public exported from `@promptbook/openai`
*/
export type OpenAiVectorStoreHandlerOptions = OpenAiCompatibleExecutionToolsOptions & ClientOptions & {
/**
* Per-knowledge-source download timeout in milliseconds when preparing vector stores.
*
* @default 30000
*/
readonly knowledgeSourceDownloadTimeoutMs?: number;
/**
* Max concurrency for uploading knowledge source files to the vector store.
*
* @default 5
*/
readonly knowledgeSourceUploadMaxConcurrency?: number;
/**
* Poll interval in milliseconds when waiting for vector store file batch processing.
*
* @default 5000
*/
readonly knowledgeSourceUploadPollIntervalMs?: number;
/**
* Overall timeout in milliseconds for vector store file batch processing.
*
* @default 900000
*/
readonly knowledgeSourceUploadTimeoutMs?: number;
/**
* Whether we should continue even if vector store ingestion stalls.
*
* @default true
*/
readonly shouldContinueOnVectorStoreStall?: boolean;
};
/**
* Base class for OpenAI execution tools that need hosted vector stores.
*
* @public exported from `@promptbook/openai`
*/
export declare abstract class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
/**
* Returns the per-knowledge-source download timeout in milliseconds.
*/
protected getKnowledgeSourceDownloadTimeoutMs(): number;
/**
* Returns the max concurrency for knowledge source uploads.
*/
protected getKnowledgeSourceUploadMaxConcurrency(): number;
/**
* Returns the polling interval in milliseconds for vector store uploads.
*/
protected getKnowledgeSourceUploadPollIntervalMs(): number;
/**
* Returns the overall upload timeout in milliseconds for vector store uploads.
*/
protected getKnowledgeSourceUploadTimeoutMs(): number;
/**
* Returns true if we should continue even if vector store ingestion stalls.
*/
protected shouldContinueOnVectorStoreStall(): boolean;
/**
* Returns vector-store-specific options with extended settings.
*/
protected get vectorStoreOptions(): OpenAiVectorStoreHandlerOptions;
/**
* Returns the OpenAI vector stores API surface, supporting stable and beta SDKs.
*/
protected getVectorStoresApi(client: OpenAI): TODO_any;
/**
* Downloads a knowledge source URL into a File for vector store upload.
*/
protected downloadKnowledgeSourceFile(options: {
readonly source: string;
readonly timeoutMs: number;
readonly logLabel: string;
}): Promise<{
readonly file: File;
readonly sizeBytes: number;
readonly filename: string;
readonly elapsedMs: number;
} | null>;
/**
* Logs vector store file batch diagnostics to help trace ingestion stalls or failures.
*/
protected logVectorStoreFileBatchDiagnostics(options: {
readonly client: OpenAI;
readonly vectorStoreId: string;
readonly batchId: string;
readonly uploadedFiles: ReadonlyArray<KnowledgeSourceUploadMetadata>;
readonly logLabel: string;
readonly reason: 'stalled' | 'timeout' | 'failed';
}): Promise<void>;
/**
* Uploads knowledge source files to the vector store and polls until processing completes.
*/
protected uploadKnowledgeSourceFilesToVectorStore(options: {
readonly client: OpenAI;
readonly vectorStoreId: string;
readonly files: ReadonlyArray<File>;
readonly totalBytes: number;
readonly logLabel: string;
}): Promise<TODO_any | null>;
/**
* Creates a vector store and uploads knowledge sources, returning its ID.
*/
protected createVectorStoreWithKnowledgeSources(options: {
readonly client: OpenAI;
readonly name: string_title;
readonly knowledgeSources: ReadonlyArray<string>;
readonly logLabel: string;
}): Promise<{
readonly vectorStoreId: string;
readonly uploadedFileCount: number;
readonly skippedCount: number;
readonly totalBytes: number;
}>;
}
export {};