parea-ai
Version:
Client SDK library to connect to Parea AI.
73 lines (72 loc) • 2.68 kB
TypeScript
import { OpenAI } from 'openai';
/**
* Wrapper class for OpenAI API methods with tracing functionality.
*/
export declare class OpenAIWrapper {
private static traceManager;
private static messageConverter;
/**
* Wraps an OpenAI API method with tracing functionality.
* @param method The method to wrap.
* @param thisArg The `this` argument for the method.
* @returns The wrapped method.
*/
static wrapMethod<T extends (...args: any[]) => any>(method: T, thisArg: any): T;
/**
* Wraps the `beta.chat.completions.parse` method with tracing functionality.
* @param method The method to wrap.
* @param thisArg The `this` argument for the method.
* @returns The wrapped method.
*/
static wrapBetaParse<T extends (...args: any[]) => any>(method: T, thisArg: any): T;
/**
* Checks if streaming is enabled in the given arguments.
* @param args The arguments to check.
* @returns True if streaming is enabled, false otherwise.
*/
private static isStreamingEnabled;
/**
* Checks if trace was invoked from `beta.chat.completions.parse` method.
* @param args The arguments to check.
* @returns True if trace was invoked from `beta.chat.completions.parse` method, false otherwise.
*/
private static isBetaCall;
/**
* Finalizes the trace with the given parameters.
* @param trace The trace to finalize.
* @param configuration The LLM configuration.
* @param result The result of the API call.
* @param error Optional error if the API call failed.
*/
private static finalizeTrace;
/**
* Extracts the LLM configuration from the given arguments.
* @param args The arguments to extract the configuration from.
* @returns The extracted LLM configuration.
*/
private static extractConfiguration;
/**
* Calculates the cost of the API call based on the model and usage.
* @param model The model used for the API call.
* @param usage The token usage information.
* @returns The calculated cost.
*/
private static calculateCost;
/**
* Extracts the output from the API result.
* @param result The API result.
* @returns The extracted output as a string.
*/
private static getOutput;
/**
* Extracts the messages from OpenAi args.
* @param inputs The inputs to extract messages from.
* @returns The extracted messages.
*/
private static getMessages;
}
/**
* Patches an OpenAI instance with tracing functionality.
* @param openai The OpenAI instance to patch.
*/
export declare function patchOpenAI(openai: OpenAI): void;