parea-ai
Version:
Client SDK library to connect to Parea AI.
144 lines (143 loc) • 6.83 kB
TypeScript
import { Completion, CompletionResponse, CreateExperimentRequest, EvaluationResult, ExperimentSchema, ExperimentStatsSchema, ExperimentWithStatsSchema, FeedbackRequest, FinishExperimentRequestSchema, ListExperimentUUIDsFilters, PaginatedTraceLogsResponse, QueryParams, TestCaseCollection, TraceLogFilters, TraceLogTreeSchema, UpdateTestCase, UseDeployedPrompt, UseDeployedPromptResponse } from './types';
import { Experiment } from './experiment/experiment';
import { ExperimentOptions } from './experiment/types';
/**
* Main class for interacting with the Parea API.
*/
export declare class Parea {
project_uuid: string;
private apiKey;
private client;
/**
* Creates a new Parea instance.
* @param apiKey - The API key for authentication.
* @param projectName - The name of the project (default: 'default').
*/
constructor(apiKey?: string, projectName?: string);
/**
* Retrieves and sets the project UUID.
*/
getProjectUUID(): Promise<void>;
/**
* Enables or disables test mode.
* @param enable - Whether to enable test mode.
*/
enableTestMode(enable: boolean): void;
/**
* Sets a mock handler for testing.
* @param mockMessage - The mock message to use.
*/
setMockHandler(mockMessage: string): void;
/**
* Sends a completion request to the API.
* @param data - The completion request data.
* @returns A promise resolving to the completion response.
*/
completion(data: Completion): Promise<CompletionResponse>;
/**
* Retrieves a deployed prompt from the API.
* @param data - The request data for retrieving the prompt.
* @returns A promise resolving to the deployed prompt response.
*/
getPrompt(data: UseDeployedPrompt): Promise<UseDeployedPromptResponse>;
/**
* Records feedback for a completion.
* @param data - The feedback request data.
*/
recordFeedback(data: FeedbackRequest): Promise<void>;
/**
* Creates a new experiment.
* @param data - The experiment creation request data.
* @returns A promise resolving to the created experiment schema.
*/
createExperiment(data: CreateExperimentRequest): Promise<ExperimentSchema>;
/**
* Retrieves statistics for a specific experiment.
* @param experimentUUID - The UUID of the experiment.
* @returns A promise resolving to the experiment statistics.
*/
getExperimentStats(experimentUUID: string): Promise<ExperimentStatsSchema>;
/**
* Marks an experiment as finished and retrieves its statistics.
* @param experimentUUID - The UUID of the experiment.
* @param fin_req - The finish experiment request data.
* @returns A promise resolving to the experiment statistics.
*/
finishExperiment(experimentUUID: string, fin_req: FinishExperimentRequestSchema): Promise<ExperimentStatsSchema>;
/**
* Retrieves a test case collection.
* @param testCollectionIdentifier - The identifier of the test collection.
* @returns A promise resolving to the test case collection or null if not found.
*/
getCollection(testCollectionIdentifier: string | number): Promise<TestCaseCollection | null>;
/**
* Creates a new test case collection.
* @param data - The test case data.
* @param name - Optional name for the collection.
*/
createTestCollection(data: Record<string, any>[], name?: string | undefined): Promise<void>;
/**
* Adds test cases to an existing collection.
* @param data - The test case data to add.
* @param name - Optional name for the test cases.
* @param datasetId - Optional dataset ID to add the test cases to.
*/
addTestCases(data: Record<string, any>[], name?: string | undefined, datasetId?: number | undefined): Promise<void>;
/**
* Updates a specific test case.
* @param testCaseId - The ID of the test case to update.
* @param datasetId - The ID of the dataset containing the test case.
* @param updateRequest - The update request data.
*/
updateTestCase(testCaseId: number | string, datasetId: number | string, updateRequest: UpdateTestCase): Promise<void>;
/**
* Instantiates an experiment on a dataset.
* @param name - The name of the experiment.
* @param data - If your dataset is defined locally it should be an iterable of k/v pairs matching the expected inputs of your function. To reference a dataset you have saved on Parea, use the dataset name as a string or the dataset id as an int.
* @param func - The function to run. This function should accept inputs that match the keys of the data field.
* @param options - Additional options for the experiment.
* @returns An Experiment instance.
*/
experiment<T extends Record<string, any>, R>(name: string, data: string | T[], func: {
(...args: any[]): any | Promise<any>;
}, options?: ExperimentOptions): Experiment<T, R>;
/**
* Lists experiments based on provided filters.
* @param filters - Filters to apply when listing experiments.
* @returns A promise resolving to an array of experiments with stats.
*/
listExperiments(filters?: ListExperimentUUIDsFilters): Promise<ExperimentWithStatsSchema[]>;
/**
* Retrieves logs for a specific experiment.
* @param experimentUUID - The UUID of the experiment.
* @param filter - Optional filters to apply to the logs.
* @returns A promise resolving to an array of trace log trees.
*/
getExperimentLogs(experimentUUID: string, filter?: TraceLogFilters): Promise<TraceLogTreeSchema[]>;
/**
* Get the trace log tree for the given trace ID.
* @param traceId - The trace ID to fetch the log for.
* @returns The trace log tree.
*/
getTraceLog(traceId: string): Promise<TraceLogTreeSchema>;
/**
* Get the evaluation scores from the trace log. If the scores are not present in the trace log, fetch them from the DB.
* @param traceId - The trace ID to get the scores for.
* @param checkContext - If true, will check the context for the scores first before fetching from the DB.
* @returns A list of evaluation results.
*/
getTraceLogScores(traceId: string, checkContext?: boolean): Promise<EvaluationResult[]>;
/**
* Fetches trace logs for a given query.
* @param queryParams - The query parameters for the trace logs.
* @returns A paginated response of trace logs.
*/
getTraceLogs(queryParams?: QueryParams): Promise<PaginatedTraceLogsResponse>;
/**
* Updates the data and trace information for a completion request.
* @param data - The completion request data.
* @returns The updated completion request data.
* @private
*/
private updateDataAndTrace;
}