UNPKG

chat-about-video

Version:

Chat about a video clip using ChatGPT hosted in OpenAI or Azure, or Gemini provided by Google

107 lines 6.39 kB
import { ConsoleLineLogger } from '@handy-common-utils/misc-utils'; import type { ChatGptApi, ChatGptOptions } from './chat-gpt'; import type { GeminiApi, GeminiOptions } from './gemini'; import { AdditionalCompletionOptions, BuildPromptOutput, ChatApi, ClientOfChatApi, EffectiveExtractVideoFramesOptions, ImagesInput, OptionsOfChatApi, PromptOfChatApi, ResponseOfChatApi, UsageMetadata, VideoInput } from './types'; export type ChatAboutVideoWith<T> = ChatAboutVideo<ClientOfChatApi<T>, OptionsOfChatApi<T>, PromptOfChatApi<T>, ResponseOfChatApi<T>>; export type ChatAboutVideoWithChatGpt = ChatAboutVideoWith<ChatGptApi>; export type ChatAboutVideoWithGemini = ChatAboutVideoWith<GeminiApi>; export type ConversationWith<T> = Conversation<ClientOfChatApi<T>, OptionsOfChatApi<T>, PromptOfChatApi<T>, ResponseOfChatApi<T>>; export type ConversationWithChatGpt = ConversationWith<ChatGptApi>; export type ConversationWithGemini = ConversationWith<GeminiApi>; export type SupportedChatApiOptions = ChatGptOptions | GeminiOptions; export declare class ChatAboutVideo<CLIENT = any, OPTIONS extends AdditionalCompletionOptions = any, PROMPT = any, RESPONSE = any> { protected log: ConsoleLineLogger | undefined; protected options: SupportedChatApiOptions; protected apiPromise: Promise<ChatApi<CLIENT, OPTIONS, PROMPT, RESPONSE>>; constructor(options: SupportedChatApiOptions, log?: ConsoleLineLogger | undefined); /** * Get the underlying API instance. * @returns The underlying API instance. */ getApi(): Promise<ChatApi<CLIENT, OPTIONS, PROMPT, RESPONSE>>; /** * Start a conversation without a video * @param options Overriding options for this conversation * @returns The conversation. */ startConversation(options?: OPTIONS): Promise<Conversation<CLIENT, OPTIONS, PROMPT, RESPONSE>>; /** * Start a conversation about a video. * @param videoFile Path to a video file in local file system. * @param options Overriding options for this conversation * @returns The conversation. */ startConversation(videoFile: string, options?: OPTIONS): Promise<Conversation<CLIENT, OPTIONS, PROMPT, RESPONSE>>; /** * Start a conversation about a video. * @param videos Array of videos or images to be used in the conversation. * For each video, the video file path and the prompt before the video should be provided. * For each group of images, the image file paths and the prompt before the image group should be provided. * @param options Overriding options for this conversation * @returns The conversation. */ startConversation(videos: Array<VideoInput | ImagesInput>, options?: OPTIONS): Promise<Conversation<CLIENT, OPTIONS, PROMPT, RESPONSE>>; } /** * Add up usage. * @param totalUsage Existing usage that will be updated. * @param incrementalUsage New usage to add. If it is undefined, then there will be no change to totalUsage. * @returns nothing, the totalUsage is updated in place. */ export declare function accumulateUsage(totalUsage: UsageMetadata, incrementalUsage: UsageMetadata | undefined): UsageMetadata | undefined; export declare class Conversation<CLIENT = any, OPTIONS extends AdditionalCompletionOptions = any, PROMPT = any, RESPONSE = any> { protected conversationId: string; protected api: ChatApi<CLIENT, OPTIONS, PROMPT, RESPONSE>; protected prompt: PROMPT | undefined; protected options: OPTIONS; protected cleanup?: (() => Promise<any>) | undefined; protected log: ConsoleLineLogger | undefined; protected usage: UsageMetadata | undefined; constructor(conversationId: string, api: ChatApi<CLIENT, OPTIONS, PROMPT, RESPONSE>, prompt: PROMPT | undefined, options: OPTIONS, cleanup?: (() => Promise<any>) | undefined, log?: ConsoleLineLogger | undefined); /** * Get the underlying API instance. * @returns The underlying API instance. */ getApi(): ChatApi<CLIENT, OPTIONS, PROMPT, RESPONSE>; /** * Get usage statistics of the conversation. * Please note that the usage statistics would be undefined before the first `say` call. * It could also be undefined if the underlying API does not support usage statistics. * The usage statistics may not cover those failed requests due to content filtering or other reasons. * Therefore, it could be less than the billable usage. * @returns The usage statistics of the conversation. Or undefined if not available. */ getUsage(): UsageMetadata | undefined; /** * Get the prompt for the current conversation. * The prompt is the accumulated messages in the conversation so far. * @returns The prompt which is the accumulated messages in the conversation so far. */ getPrompt(): PROMPT | undefined; /** * Say something in the conversation, and get the response from AI * @param message The message to say in the conversation. * @param options Options for fine control. * @returns The response/completion */ say(message: string, options?: Partial<OPTIONS>): Promise<string | undefined>; end(): Promise<void>; } /** * Convenient function to generate a temporary conversation ID. * @returns A temporary conversation ID. */ export declare function generateTempConversationId(): string; /** * Build prompt for sending frame images of a video content to AI. * This function is usually used for implementing the `buildVideoPrompt` function of ChatApi by utilising already implemented `buildImagesPrompt` function. * It extracts frame images from the video and builds a prompt containing those images for the conversation. * @param api The API instance. * @param extractVideoFrames The options for extracting video frames. * @param tmpDir The temporary directory to store the extracted frames. * @param videoFile Path to a video file in local file system. * @param conversationId The conversation ID. * @returns The prompt and options for the conversation. */ export declare function buildImagesPromptFromVideo<CLIENT, OPTIONS extends AdditionalCompletionOptions, PROMPT, RESPONSE>(api: ChatApi<CLIENT, OPTIONS, PROMPT, RESPONSE>, extractVideoFrames: EffectiveExtractVideoFramesOptions, tmpDir: string, videoFile: string, conversationId?: string): Promise<BuildPromptOutput<PROMPT, OPTIONS>>; //# sourceMappingURL=chat.d.ts.map