It is highly recommended to run evals with either the Python or TypeScript SDKs. The SDKs have many optimizations and features that enhance the performance and reliability of your evals. However, if you are unable to use the SDKs, either because you are using a different language or because you are running in a restricted environment, you can use the REST API directly.This guide will show you how to run evals using the REST API, using the requests library in Python as an example. However, the same principles apply to any language.
Here, we are using the python SDK for convenience. You can also use the API directly use the UI, see this guide for more information.
Accept POST requests
Accept JSON input with the example inputs
Return JSON output with the results
Here’s an example using FastAPI:
Copy
Ask AI
from fastapi import FastAPIfrom pydantic import BaseModelfrom typing import Dict, Anyapp = FastAPI()class EvaluationInput(BaseModel): inputs: Dict[str, Any]class EvaluationOutput(BaseModel): outputs: Dict[str, Any]@app.post("/evaluate", response_model=EvaluationOutput)async def evaluate(inputs: EvaluationInput): # Your evaluation logic here # This is just an example result = {"output": f"Processed: {inputs.inputs}"} return EvaluationOutput(outputs=result)
Next, we’ll demonstrate how to run a pairwise experiment. In a pairwise experiment, you compare two examples against each other. For more information, check out this guide.