Test runners - Create with local data
This feature is currently only available in our TypeScript SDK. We have not implemented this functionality in Python yet.
The createTestRunners()
function allows you to create test runners using local test data, rather than using test case data defined in datasets. This is useful when you want to run evaluations on custom, locally-defined test cases.
Use cases
- Running evaluations on custom test data not stored in Gentrace datasets
- Quick prototyping and testing of AI models with local inputs
- Integrating external test case sources into your Gentrace workflow
Example
typescript
import {createTestRunners ,LocalTestData ,Pipeline ,submitTestRunners } from "@gentrace/core";import {initPlugin } from "@gentrace/openai";// Initialize Gentrace and OpenAI pluginconstplugin = awaitinitPlugin ({apiKey :process .env .OPENAI_KEY });constpipeline = newPipeline ({slug : "your-pipeline-slug",plugins : {openai :plugin }});// Define local test dataconstlocalData :LocalTestData [] = [{name : "Test Case 1",inputs : {prompt : "Convert this sentence to JSON: John is 10 years old." },},// Add more test cases as needed];// Create test runners using local dataconsttestRunners =createTestRunners (pipeline ,localData );// Process test casesfor (const [runner ,testCase ] oftestRunners ) {// Use runner.openai to make API callsconstcompletion = awaitrunner .openai .chat .completions .create ({model : "gpt-3.5-turbo",messages : [{role : "user",content :testCase .inputs .prompt }],});// Optionally, add local evaluationsrunner .addEval ({name : "example-eval",value : 0.8,// Add more evaluation details as needed});}// Submit test runnersconstresult = awaitsubmitTestRunners (pipeline ,testRunners );console .log ("Test result ID:",result .resultId );
Arguments
pipeline: Pipeline
The pipeline instance to associate with the test runners.
localData: LocalTestData[]
An array of local test data objects. Each object should have the following structure:
typescript
interface LocalTestData {name: string;inputs: Record<string, any>;}
Return value
Returns an array of PipelineRunLocalDataTuple
objects, which are tuples containing a PipelineRun
instance and the corresponding LocalTestData
data.
Integration with submitTestRunners()
After creating test runners with createTestRunners()
, you can use submitTestRunners()
to submit the results to Gentrace. This allows you to run evaluations and store the results in Gentrace.
typescript
const result = await submitTestRunners(pipeline, testRunners);console.log("Test result ID:", result.resultId);