UNPKG

@nomyx/assistant

Version:

A powerful assistant library and cli for your AI projects. works with Vertex AI (Claude and Gemini)

76 lines (75 loc) 3.63 kB
import { ChatMessage, ChatOptions, ProviderResponse } from '../../../types/chat'; import { ProviderCapabilities, EmbeddingProvider } from '../../../types/provider'; import { Tool, GenericToolSchema, StandardizedToolCall } from '../../../types/tool'; import { ILogger } from '../../../types/common'; import { OpenAIProviderConfig } from './types'; import { BaseProvider } from '../BaseProvider'; /** * OpenAIProvider class that extends BaseProvider and implements EmbeddingProvider. * This provider interacts with the OpenAI API for various AI-related tasks. */ export declare class OpenAIProvider extends BaseProvider implements EmbeddingProvider { private config; private cache; /** * Creates an instance of OpenAIProvider. * @param {OpenAIProviderConfig} config - The configuration for the OpenAI provider. * @param {ILogger} logger - The logger instance for logging. */ constructor(config: OpenAIProviderConfig, logger: ILogger); /** * Sends a chat request to the OpenAI API. * @param {ChatMessage[]} messages - The chat messages to send. * @param {ChatOptions} options - The options for the chat request. * @param {Tool[]} [tools] - Optional tools to use in the chat. * @returns {Promise<ProviderResponse>} The response from the API. * @throws {OpenAIProviderError} If there's an error during the API call. */ chat(messages: ChatMessage[], options: ChatOptions, tools?: Tool[]): Promise<ProviderResponse>; /** * Sends a streaming chat request to the OpenAI API. * @param {ChatMessage[]} messages - The chat messages to send. * @param {ChatOptions} options - The options for the chat request. * @param {Tool[]} [tools] - Optional tools to use in the chat. * @returns {AsyncIterableIterator<ProviderResponse>} An async iterator of responses from the API. * @throws {OpenAIProviderError} If there's an error during the API call. */ streamChat(messages: ChatMessage[], options: ChatOptions, tools?: Tool[]): AsyncIterableIterator<ProviderResponse>; /** * Returns the capabilities of the OpenAI provider. * @returns {ProviderCapabilities} The capabilities of the provider. */ getCapabilities(): ProviderCapabilities; /** * Generates an embedding for the given text. * @param {string} text - The text to embed. * @returns {Promise<number[]>} The embedding as an array of numbers. * @throws {OpenAIProviderError} If there's an error during the API call. */ embed(text: string): Promise<number[]>; /** * Generates embeddings for the given texts. * @param {string[]} texts - The texts to embed. * @returns {Promise<number[][]>} The embeddings as an array of number arrays. * @throws {OpenAIProviderError} If there's an error during the API call. */ embedBatch(texts: string[]): Promise<number[][]>; /** * Converts a generic tool schema to the OpenAI-specific format. * @param {GenericToolSchema} schema - The generic tool schema to convert. * @returns {any} The converted schema in OpenAI format. */ convertToolSchema(schema: GenericToolSchema): any; /** * Converts an OpenAI tool call to the standardized format. * @param {any} call - The OpenAI tool call to convert. * @returns {StandardizedToolCall} The converted tool call in standardized format. */ convertToolCall(call: any): StandardizedToolCall; /** * Clears the internal cache of the provider. */ clearCache(): void; } export * from './types'; export { OpenAIProviderError } from './errors';