import { AxiosResponse, AxiosRequestConfig } from 'axios'; import { PromptFunctions, PromptMemory, PromptSection, Tokenizer } from "promptrix"; import { PromptCompletionModel, PromptResponse, ChatCompletionFunction, JsonSchema, ChatCompletionTool } from "./types"; import { CreateChatCompletionRequest, CreateChatCompletionResponse, CreateCompletionRequest, CreateCompletionResponse } from "./internals"; /** * Base model options common to both OpenAI and Azure OpenAI services. */ export interface BaseOpenAIModelOptions { /** * Type of completion API to call. */ completion_type: 'text' | 'chat'; /** * Optional. Maximum number of tokens to let the prompt use when rendering. * @remarks * Defaults to `1024`. * * If the rendered prompt exceeds this limit, most `PromptCompletionClient` classes will return * a `response.status == 'too_long'`. */ max_input_tokens?: number; /** * Optional. What sampling temperature to use, between `0` and `2`. * @remarks * Higher values like `0.8` will make the output more random, while lower values like `0.2` will * make it more focused and deterministic. * * It's generally recommended to use this or `top_p` but not both. */ temperature?: number; /** * Optional. An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. * @remarks * A value of `0.1` means only the tokens comprising the top 10% probability mass are considered. * * It's generally recommended to use this or `temperature` but not both. */ top_p?: number; /** * Optional. The maximum number of tokens to generate for a completion. * @remarks * This value plus the `max_input_tokens` value cannot exceed the maximum number of tokens for * the models context window. */ max_tokens?: number; /** * Optional. Up to 4 sequences where the API will stop generating further tokens. * @remarks * The returned text will not contain the stop sequence. */ stop?: Array | string; /** * Optional. Presence penalty value between `-2.0` and `2.0`. * @remarks * Positive values penalize new tokens based on whether they appear in the text so far, * increasing the model's likelihood to talk about new topics. */ presence_penalty?: number; /** * Optional. Frequency penalty value between `-2.0` and `2.0`. * @remarks * Positive values penalize new tokens based on their existing frequency in the text so far, * decreasing the model's likelihood to repeat the same line verbatim. */ frequency_penalty?: number; /** * Optional. Logit bias modifies the likelihood of specified tokens appearing in the completion. */ logit_bias?: object; /** * Optional. Number of candidate completions to generate server side. */ best_of?: number; /** * Optional. Whether to log requests to the console. * @remarks * This is useful for debugging prompts and defaults to `false`. */ logRequests?: boolean; /** * Optional. Retry policy to use when calling the OpenAI API. * @remarks * The default retry policy is `[2000, 5000]` which means that the first retry will be after * 2 seconds and the second retry will be after 5 seconds. */ retryPolicy?: number[]; /** * Optional. Whether to retry if the server closes the connection with ECONNRESET. * @remarks * The default is `true`. */ retryConnectionReset?: boolean; /** * Optional. Request options to use when calling the OpenAI API. */ requestConfig?: AxiosRequestConfig; /** * @deprecated * Optional. A list of functions the model may generate JSON inputs for. */ functions?: ChatCompletionFunction[]; /** * @deprecated * Optional. Controls how the model responds to function calls. * @remarks * `"none"` means the model does not call a function, and responds to the end-user. * `"auto"` means the model can pick between an end-user or calling a function. * Specifying a particular function via `{"name":\ "my_function"}` forces the model to call that function. * `"none"` is the default when no functions are present. * `"auto"` is the default if functions are present. */ function_call?: { name: string; } | 'none' | 'auto'; /** * Optional. An object specifying the format that the model must output. * @remarks * Only available on select models but lets you guarantee that the model will output a JSON object. */ response_format?: { type: 'json_object' | 'json_schema'; json_schema?: JsonSchema; }; /** * Optional. Specifies the seed to the model should use when generating its response. * @remarks * Only available on select models but can be used to improve the models determinism in its responses. */ seed?: number; /** * Optional. A list of tools the model may generate JSON inputs for. */ tools?: ChatCompletionTool[]; /** * Optional. Controls how the model responds to tool calls. * @remarks * Defaults to `auto`. */ tool_choice?: 'auto' | 'none' | 'required' | ChatCompletionTool; /** * Optional. Whether to support calling tools in parallel. * @remarks * Defaults to `true`. */ parallel_tool_calls?: boolean; } /** * Options for configuring an `OpenAIModel` to call an OSS hosted model. */ export interface OSSModelOptions extends BaseOpenAIModelOptions { /** * Model to use for completion. */ ossModel: string; /** * Endpoint to use when calling the OSS API. */ ossEndpoint: string; /** * Optional. API key to use when calling the endpoint. */ apiKey?: string; } /** * Options for configuring an `OpenAIModel` to call an OpenAI hosted model. */ export interface OpenAIModelOptions extends BaseOpenAIModelOptions { /** * API key to use when calling the OpenAI API. * @remarks * A new API key can be created at https://platform.openai.com/account/api-keys. */ apiKey: string; /** * Model to use for completion. * @remarks * For Azure OpenAI this is the name of the deployment to use. */ model: string; /** * Optional. Organization to use when calling the OpenAI API. */ organization?: string; /** * Optional. Endpoint to use when calling the OpenAI API. * @remarks * For Azure OpenAI this is the deployment endpoint. */ endpoint?: string; } /** * Options for configuring an `OpenAIModel` to call an Azure OpenAI hosted model. */ export interface AzureOpenAIModelOptions extends BaseOpenAIModelOptions { /** * API key to use when making requests to Azure OpenAI. */ azureApiKey: string; /** * Deployment endpoint to use. */ azureEndpoint: string; /** * Name of the Azure OpenAI deployment (model) to use. */ azureDeployment: string; /** * Optional. Version of the API being called. Defaults to `2023-05-15`. */ azureApiVersion?: string; } /** * A `PromptCompletionModel` for calling OpenAI and Azure OpenAI hosted models. * @remarks */ export declare class OpenAIModel implements PromptCompletionModel { private readonly _httpClient; private readonly _clientType; private readonly UserAgent; /** * Creates a new `OpenAIClient` instance. * @param options Options for configuring an `OpenAIClient`. */ constructor(options: OSSModelOptions | OpenAIModelOptions | AzureOpenAIModelOptions); /** * Options the client was configured with. */ readonly options: OSSModelOptions | OpenAIModelOptions | AzureOpenAIModelOptions; /** * Creates a new `OpenAIModel` instance with the specified options merged with the current options. * @param options New options to merge with the current options. * @returns Cloned `OpenAIModel` instance. */ clone(options: Partial): OpenAIModel; /** * Completes a prompt using the OpenAI API. * @remarks * The API used, Chat Completion or Text Completion, will be determined by the `this.options.completion_type` property. * @param memory Memory to use when rendering the prompt. * @param functions Functions to use when rendering the prompt. * @param tokenizer Tokenizer to use when rendering the prompt. * @param prompt Prompt to complete. * @returns A `PromptResponse` with the status and message. */ completePrompt(memory: PromptMemory, functions: PromptFunctions, tokenizer: Tokenizer, prompt: PromptSection): Promise; /** * @private */ protected copyOptionsToRequest(target: Partial, src: any, fields: string[]): TRequest; protected patchBreakingChanges(request: CreateChatCompletionRequest): CreateChatCompletionRequest; /** * @private */ protected createCompletion(request: CreateCompletionRequest): Promise>; /** * @private */ protected createChatCompletion(request: CreateChatCompletionRequest): Promise>; /** * @private */ protected post(url: string, body: object, retryCount?: number): Promise>; } //# sourceMappingURL=OpenAIModel.d.ts.map