JavaScript and TypeScript client library for interacting with Gradio APIs, providing methods to connect to, submit predictions to, and manage connections with Gradio applications.
Overall
score
96%
Build a robust error handling utility for Gradio API interactions that gracefully handles various failure scenarios and provides meaningful error messages.
Create a module that wraps Gradio client operations with comprehensive error handling. The utility should handle common failure scenarios when connecting to and interacting with Gradio applications.
The utility must catch and categorize errors that occur during connection:
When making predictions, the utility should catch and categorize:
All errors should be categorized into specific types (connection, authentication, validation, network, or unknown) and return structured error information that includes:
@generates
/**
* Options for configuring error handling behavior
*/
export interface ErrorHandlerOptions {
maxRetries?: number;
retryDelay?: number;
}
/**
* Result of an error handling operation
*/
export interface ErrorHandlingResult<T> {
success: boolean;
data?: T;
error?: {
type: 'connection' | 'authentication' | 'validation' | 'network' | 'queue' | 'unknown';
message: string;
details?: any;
};
}
/**
* Safely connects to a Gradio application with error handling
*
* @param endpoint - The Gradio endpoint URL or Space name
* @param options - Optional configuration for error handling
* @returns A result object indicating success or failure with error details
*/
export async function safeConnect(
endpoint: string,
options?: ErrorHandlerOptions
): Promise<ErrorHandlingResult<any>>;
/**
* Safely executes a prediction with error handling
*
* @param client - Connected Gradio client instance
* @param endpointName - Name of the prediction endpoint
* @param params - Parameters for the prediction
* @param options - Optional configuration for error handling
* @returns A result object indicating success or failure with error details
*/
export async function safePrediction(
client: any,
endpointName: string,
params: any,
options?: ErrorHandlerOptions
): Promise<ErrorHandlingResult<any>>;Provides the Gradio client API for connecting to and interacting with Gradio applications.
Install with Tessl CLI
npx tessl i tessl/npm-gradio--clientevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10