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-1/

Gradio API Parameter Validator

A utility that validates parameters before making predictions to a Gradio API endpoint.

Overview

Build a function that validates user-provided parameters against a Gradio API schema before submitting predictions. Use the API introspection capabilities to retrieve endpoint schemas, then validate that all required parameters are present, detect invalid parameters, and support both positional and keyword argument formats. The goal is to catch parameter errors early before making actual API calls.

Capabilities

API Schema Retrieval

Retrieves and parses API schema information from a connected Gradio client.

  • Given a connected client with endpoint "predict", retrieves the API schema showing parameter names and requirements @test
  • Given an endpoint with both required and optional parameters, correctly identifies which parameters are required @test

Required Parameter Validation

Validates that all required parameters are provided before making API calls.

  • Given an endpoint requiring ["text", "model"] and user provides only {"text": "hello"}, validation fails with error indicating "model" is missing @test
  • Given an endpoint requiring ["input"] and user provides {"input": "test"}, validation succeeds @test

Invalid Parameter Detection

Detects when users provide parameters not defined in the endpoint schema.

  • Given an endpoint accepting ["prompt", "temperature"] and user provides {"prompt": "hi", "temperature": 0.7, "top_k": 50}, validation fails indicating "top_k" is invalid @test
  • Given an endpoint with no parameters and user provides any parameters, validation fails @test

Argument Format Support

Supports both positional (array) and keyword (object) parameter formats for flexibility.

  • Given endpoint parameters ["text", "temperature", "max_length"] in that order and user provides ["Hello", 0.8, 100], validation succeeds and correctly maps positional args @test
  • Given endpoint parameters and user provides {"temperature": 0.9, "text": "Hi"} (different order), validation succeeds @test

Implementation

@generates

API

import { Client } from "@gradio/client";

/**
 * Result of parameter validation
 */
interface ValidationResult {
  valid: boolean;
  params?: Record<string, any>;
  error?: string;
}

/**
 * Retrieves API schema information for a specific endpoint
 *
 * @param client - Connected Gradio client instance
 * @param endpoint - Name or index of the endpoint
 * @returns Object containing parameter definitions and requirements
 */
export async function getEndpointSchema(
  client: Client,
  endpoint: string | number
): Promise<any>;

/**
 * Validates user-provided parameters against a Gradio endpoint schema
 *
 * @param client - Connected Gradio client instance
 * @param endpoint - Name or index of the endpoint to validate against
 * @param userParams - Parameters provided by the user (array for positional, object for keyword)
 * @returns Validation result with processed parameters or error message
 */
export async function validateEndpointParams(
  client: Client,
  endpoint: string | number,
  userParams: any[] | Record<string, any>
): Promise<ValidationResult>;

Dependencies { .dependencies }

@gradio/client { .dependency }

JavaScript/TypeScript client library for interacting with Gradio APIs. Provides Client class for connections and view_api() method for API introspection.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-gradio--client

tile.json