@promptbook/google
Version:
Promptbook: Run AI apps in plain human language across multiple models and platforms
92 lines (91 loc) • 3.87 kB
TypeScript
import OpenAI from 'openai';
import type { AvailableModel } from '../../execution/AvailableModel';
import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
import type { ChatPromptResult } from '../../execution/PromptResult';
import type { CompletionPromptResult } from '../../execution/PromptResult';
import type { EmbeddingPromptResult } from '../../execution/PromptResult';
import type { Usage } from '../../execution/Usage';
import type { Prompt } from '../../types/Prompt';
import type { string_markdown } from '../../types/typeAliases';
import type { string_markdown_text } from '../../types/typeAliases';
import type { string_model_name } from '../../types/typeAliases';
import type { string_title } from '../../types/typeAliases';
import { computeOpenAiUsage } from './computeOpenAiUsage';
import type { OpenAiCompatibleExecutionToolsNonProxiedOptions } from './OpenAiCompatibleExecutionToolsOptions';
/**
* Execution Tools for calling OpenAI API or other OpenAI compatible provider
*
* @public exported from `@promptbook/openai`
*/
export declare abstract class OpenAiCompatibleExecutionTools implements LlmExecutionTools {
protected readonly options: OpenAiCompatibleExecutionToolsNonProxiedOptions;
/**
* OpenAI API client.
*/
private client;
/**
* Rate limiter instance
*/
private limiter;
/**
* Creates OpenAI compatible Execution Tools.
*
* @param options which are relevant are directly passed to the OpenAI compatible client
*/
constructor(options: OpenAiCompatibleExecutionToolsNonProxiedOptions);
abstract get title(): string_title & string_markdown_text;
abstract get description(): string_markdown;
getClient(): Promise<OpenAI>;
/**
* Check the `options` passed to `constructor`
*/
checkConfiguration(): Promise<void>;
/**
* List all available OpenAI compatible models that can be used
*/
listModels(): Promise<ReadonlyArray<AvailableModel>>;
/**
* Calls OpenAI compatible API to use a chat model.
*/
callChatModel(prompt: Pick<Prompt, 'content' | 'parameters' | 'modelRequirements' | 'format'>): Promise<ChatPromptResult>;
/**
* Calls OpenAI API to use a complete model.
*/
callCompletionModel(prompt: Pick<Prompt, 'content' | 'parameters' | 'modelRequirements'>): Promise<CompletionPromptResult>;
/**
* Calls OpenAI compatible API to use a embedding model
*/
callEmbeddingModel(prompt: Pick<Prompt, 'content' | 'parameters' | 'modelRequirements'>): Promise<EmbeddingPromptResult>;
/**
* Get the model that should be used as default
*/
protected getDefaultModel(defaultModelName: string_model_name): AvailableModel;
/**
* List all available models (non dynamically)
*
* Note: Purpose of this is to provide more information about models than standard listing from API
*/
protected abstract get HARDCODED_MODELS(): ReadonlyArray<AvailableModel>;
/**
* Computes the usage of the OpenAI API based on the response from OpenAI Compatible API
*/
protected abstract computeUsage(...args: Parameters<typeof computeOpenAiUsage>): Usage;
/**
* Default model for chat variant.
*/
protected abstract getDefaultChatModel(): AvailableModel;
/**
* Default model for completion variant.
*/
protected abstract getDefaultCompletionModel(): AvailableModel;
/**
* Default model for completion variant.
*/
protected abstract getDefaultEmbeddingModel(): AvailableModel;
}
/**
* TODO: [🛄] Some way how to re-wrap the errors from `OpenAiCompatibleExecutionTools`
* TODO: [🛄] Maybe make custom `OpenAiCompatibleError`
* TODO: [🧠][🈁] Maybe use `isDeterministic` from options
* TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
*/