This page walks through how to create a Testset using the Scorecard SDK.

Example

Create a Testset with Custom Schema

🧙‍♂️ Instructions

  1. Create an account and login to Scorecard. Copy your API key.
  2. Add your Scorecard API Key below.
  3. (If running as notebook) Go to Runtime -> Run all. Enjoy!
1#@title 👉 API Keys
2
3SCORECARD_API_KEY = "" #@param { type: "string" }

Colab Sections

Setup

1#@title Install dependencies
2#@markdown In order to keep the notebook working for all future users, we pin the dependency versions.
3
4!pip install scorecard-ai==0.1.12
5!pip install openai==1.11.1
1#@title Imports
2
3from openai import OpenAI
4from scorecard.client import Scorecard

Create a Testset in Scorecard

1#@title 1. Create a basic Testset with Custom Schema
2#@markdown Here we'll create a basic Testset that gets stored in Scorecard.
3
4from scorecard.types import CustomSchema, CustomVariable
5import json
6
7client = Scorecard(
8 api_key=SCORECARD_API_KEY,
9)
10
11# Create a Testset
12testset = client.testset.create(
13 name="Story Opening Lines",
14 description="Demo of a Testset created via Scorecard Python SDK",
15 using_retrieval=False,
16 custom_schema=CustomSchema(
17 variables=[
18 CustomVariable(
19 name="inputs",
20 description="Custom Parameters for this Testset.",
21 role="input",
22 data_type="json_object",
23 ),
24 ]
25 ),
26)
27
28# Add three Testcases
29client.testcase.create(
30 testset_id=testset.id,
31 user_query="query",
32 custom_inputs={
33 "inputs": json.dumps(
34 {
35 "key": "value",
36 "link": "https://www.google.com",
37 "number": 1,
38 "nested": {"key": "value"},
39 }
40 ),
41 },
42)
43
44print("Visit the Scorecard UI to view your Testset:")
45print(f"https://app.getscorecard.ai/view-dataset/{testset.id}")