Overview

Run an experiment to test and evaluate model performance on the configured dataset.

Method Signature

# Synchronous
client.experiments.run_experiment(
    experiment_id: str,
    config: Optional[Dict[str, Any]] = None
) -> Dict[str, Any]

# Asynchronous
await client.experiments.run_experiment(
    experiment_id: str,
    config: Optional[Dict[str, Any]] = None
) -> Dict[str, Any]

Parameters

experiment_id
string
required
The unique identifier of the experiment to run
config
Dict[str, Any]
Optional configuration parameters for the experiment run

Returns

Returns a dictionary containing the experiment run results and status.

Example

from keywordsai import KeywordsAI

client = KeywordsAI(api_key="your-api-key")

# Run experiment with default configuration
result = client.experiments.run_experiment(
    experiment_id="exp_123"
)

print(f"Experiment status: {result['status']}")
print(f"Run ID: {result['run_id']}")

# Run experiment with custom configuration
config = {
    "model": "gpt-4",
    "temperature": 0.7,
    "max_tokens": 150
}

result = client.experiments.run_experiment(
    experiment_id="exp_123",
    config=config
)

Error Handling

try:
    result = client.experiments.run_experiment(
        experiment_id="exp_123"
    )
except Exception as e:
    print(f"Error running experiment: {e}")