import { ConversationConfig } from "./ConversationConfig.js"; import { Message } from "./Message.js"; import { ConversationModel } from "../schemas/conversation.schema.js"; import { ConversationRequestOptions } from "./ConversationRequestOptions.js"; import { ConversationHistory } from "./ConversationHistory.js"; import { ConversationCallableFunctions } from "./ConversationCallableFunctions.js"; import { ConversationRequestOptionsModel } from "schemas/conversationRequestOptions.schema.js"; import { ChatCompletionService } from "./ChatCompletionService.js"; import { ConversationGlobalPlugins, ConversationOptions, PluginsFromConversationOptionsWithGlobalPlugins, PromptOptions } from "../utils/types/index.js"; import { ConversationPlugins } from "./ConversationPlugins.js"; /** * A Conversation manages the messages sent to and from the OpenAI API and handles the logic for providing the message history to the API for each prompt. */ export declare class Conversation { /** * Plugins that will be used for all conversations. * * @remarks * Only applies to conversations created after this property is set. Previous conversations will not be affected. * * @example * For TypeScript users, you can achieve type-safe global plugins by overriding the `ConversationGlobalPluginsOverride` interface. * ```ts * const globalPlugins = [somePlugin, someOtherPlugin]; * * declare module "gpt-turbo" { * interface ConversationGlobalPluginsOverride { * globalPlugins: typeof globalPlugins; * } * } * * Conversation.globalPlugins = globalPlugins; * ``` */ static globalPlugins: ConversationGlobalPlugins; /** * A UUID generated by the library for this conversation. Not the same as the conversation ID returned by the OpenAI API. */ id: string; readonly config: ConversationConfig; readonly requestOptions: ConversationRequestOptions; readonly history: ConversationHistory; readonly callableFunctions: ConversationCallableFunctions; readonly plugins: ConversationPlugins>; private readonly chatCompletionService; private readonly pluginService; /** * Creates a new Conversation instance. * * @param options The options for the Conversation instance's configuration, request options, history, and callable functions. */ constructor(options?: TOptions); /** * Creates a new Conversation instance from a JSON object. * * @param json The JSON object of the Conversation instance. * @param plugins The plugins to use for the Conversation instance. * @returns The new Conversation instance. */ static fromJSON(json: ConversationModel, plugins?: ConversationOptions["plugins"]): Conversation; /** * Serializes the `Conversation` to JSON. * * @returns A JSON representation of the `Conversation` instance. */ toJSON(): ConversationModel; /** * This is the **recommended** way to interact with the GPT model. It's a wrapper method around other public methods that handles the logic of adding a user message, sending a request to the OpenAI API, and adding the assistant's response. * * @param prompt The prompt to send to the assistant. * @param options Additional options to pass to the Create Chat Completion API endpoint. This overrides the config passed to the constructor. * @param requestOptions Additional options to pass for the HTTP request. This overrides the config passed to the constructor. * @returns The assistant's response as a [`Message`](./Message.js) instance. */ prompt(prompt: string, options?: PromptOptions, requestOptions?: ConversationRequestOptionsModel): Promise; /** * Removes all messages starting from (but excluding) the `fromMessage` if it's a user message, or its previous user message if `fromMessage` is an assistant message. * Then, the `prompt` method is called using either the specified `newPrompt` or the previous user message's content. * * This is useful if you want to edit a previous user message (by specifying `newPrompt`) or if you want to regenerate the response to a previous user message (by not specifying `newPrompt`). * * @param fromMessageOrId The message to re-prompt from. This can be either a message ID or a [`Message`](./Message.js) instance. * @param newPrompt The new prompt to use for the previous user message. If not provided, the previous user's message content will be reused. * @param options Additional options to pass to the Create Chat Completion API endpoint. This overrides the config passed to the constructor. * @param requestOptions Additional options to pass for the HTTP request. This overrides the config passed to the constructor. * @returns The assistant's response as a [`Message`](./Message.js) instance. * * @example * ```typescript * let assistantRes1 = await conversation.prompt("Hello!"); // Hi * let assistantRes2 = await conversation.prompt("How are you?"); // I'm good, how are you? * * // Regenerate the assistantRes2 response * assistantRes2 = await conversation.reprompt(assistantRes2); // Good! What about you? * * // Edit the initial prompt (and remove all messages after it. In this case, assistantRes2's response) * assistantRes1 = await conversation.reprompt(assistantRes1, "Goodbye!"); // See you later! * ``` */ reprompt(fromMessageOrId: string | Message, newPrompt?: string, options?: PromptOptions, requestOptions?: ConversationRequestOptionsModel): Promise; /** * Sends the result of a user-evaluated function call to the GPT model and gets the assistant's response. * This method should usually be called after receiving a function_call message from the assistant (using `getChatCompletionResponse()` or `prompt()`) and evaluating your own function with the provided arguments from that message. * * @param name The name of the function used to generate the result. This function must be defined in the `functions` config option. * @param result The result of the function call. If the result is anything other than a string, it will be JSON stringified. Since `result` can be anything, the `T` generic is provided for your typing convenience, but is not used internally * @param options Additional options to pass to the Create Chat Completion API endpoint. This overrides the config passed to the constructor. * @param requestOptions Additional options to pass for the HTTP request. This overrides the config passed to the constructor. * @returns The assistant's response as a [`Message`](./Message.js) instance. */ functionPrompt(name: string, result: T, options?: PromptOptions, requestOptions?: ConversationRequestOptionsModel): Promise; /** * Sends a Create Chat Completion request to the OpenAI API using the current messages stored in the conversation's history. * * @remarks * This method is solely provided for client code that wants to trigger a Create Chat Completion request manually. * It is not used internally by the library and does not moderate messages before sending them to the API. * * @param options Additional options to pass to the Create Chat Completion API endpoint. This overrides the config passed to the constructor. * @param requestOptions Additional options to pass for the HTTP request. This overrides the config passed to the constructor. * @returns A new [`Message`](./Message.js) instance with the role of "assistant" and the content set to the response from the OpenAI API. If the `stream` config option was set to `true`, the content will be progressively updated as the response is streamed from the API. Listen to the returned message's `onUpdate` event to get the updated content. */ getChatCompletionResponse(...args: Parameters): Promise; }