CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-gradio--client

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%

Overview
Eval results
Files

task.mdevals/scenario-6/

Gradio Client Error Handler

Build a robust error handling utility for Gradio API interactions that gracefully handles various failure scenarios and provides meaningful error messages.

Requirements

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.

Connection Error Handling

The utility must catch and categorize errors that occur during connection:

  • Invalid endpoints or unreachable servers
  • Authentication failures when credentials are required
  • Network connectivity issues

Prediction Error Handling

When making predictions, the utility should catch and categorize:

  • Parameter validation errors (wrong parameter names or types)
  • Server errors during processing

Error Categorization

All errors should be categorized into specific types (connection, authentication, validation, network, or unknown) and return structured error information that includes:

  • Error type
  • Human-readable error message
  • Original error details when available

Test Cases

Test Case 1: Invalid Endpoint Connection { .test }

  • Attempting to connect to a non-existent Gradio endpoint should result in a clear error message indicating the connection failed @test

Test Case 2: Authentication Failure { .test }

  • Attempting to connect to a private space without valid credentials should result in an authentication error @test

Test Case 3: Parameter Validation { .test }

  • Attempting to call a prediction endpoint with invalid parameters should result in a validation error that identifies the problematic parameters @test

Implementation

@generates

API

/**
 * 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>>;

Dependencies { .dependencies }

@gradio/client { .dependency }

Provides the Gradio client API for connecting to and interacting with Gradio applications.

Install with Tessl CLI

npx tessl i tessl/npm-gradio--client

tile.json