Create and Manage a Dataset with the Future AGI SDK

Create a dataset, define its columns, add rows, and download it back with fi.datasets.

📝
TL;DR

Build a dataset from scratch with the Future AGI SDK: define columns, add rows, and download it as a CSV. You’ll create the dataset, see it in your Future AGI account, download it as a CSV, and delete it when you’re done.

TimeDifficultyPackage
15 minutesBeginnerfutureagi
Prerequisites
  • A Future AGI account with an API key and secret key (see Get your API keys)
  • Python 3.11 or later

Install

pip install futureagi
export FI_API_KEY="<your_api_key>"
export FI_SECRET_KEY="<your_api_secret>"

Tutorial

Create a dataset

import os
from fi.datasets import Dataset, DatasetConfig
from fi.datasets.types import ModelTypes

config = DatasetConfig(
    id=None,  # set by the server on create
    name="support_ticket_review",
    model_type=ModelTypes.GENERATIVE_LLM,
)

dataset = Dataset(
    dataset_config=config,
    fi_api_key=os.environ["FI_API_KEY"],
    fi_secret_key=os.environ["FI_SECRET_KEY"],
)
dataset = dataset.create()

You should see dataset return with a populated id. That confirms the dataset now exists in your Future AGI account. The client reads FI_API_KEY and FI_SECRET_KEY automatically if they’re already set as environment variables, so passing them explicitly here is optional.

Define the columns

from fi.datasets.types import Column, DataTypeChoices, SourceChoices

columns = [
    Column(
        name="ticket_text",
        data_type=DataTypeChoices.TEXT,
        source=SourceChoices.OTHERS,
        source_id=None,
    ),
    Column(
        name="priority",
        data_type=DataTypeChoices.INTEGER,
        source=SourceChoices.OTHERS,
        source_id=None,
    ),
    Column(
        name="call_recording_url",
        data_type=DataTypeChoices.AUDIO,
        source=SourceChoices.OTHERS,
        source_id=None,
    ),
]

dataset = dataset.add_columns(columns=columns)

You should see dataset reflect three columns: ticket_text, priority, and call_recording_url. Every row you add next must fill these column names exactly.

Add rows

from fi.datasets.types import Row, Cell

rows = [
    Row(
        order=1,
        cells=[
            Cell(column_name="ticket_txt", value="Refund not received after 10 days"),
            Cell(column_name="priority", value=1),
            Cell(column_name="call_recording_url", value="https://example.com/audio1.mp3"),
        ],
    ),
]

dataset = dataset.add_rows(rows=rows)

This raises a validation error: column_name ticket_txt doesn’t match any column defined in the previous step (ticket_text, priority, call_recording_url). Fix the typo and add both rows:

rows = [
    Row(
        order=1,
        cells=[
            Cell(column_name="ticket_text", value="Refund not received after 10 days"),
            Cell(column_name="priority", value=1),
            Cell(column_name="call_recording_url", value="https://example.com/audio1.mp3"),
        ],
    ),
    Row(
        order=2,
        cells=[
            Cell(column_name="ticket_text", value="Password reset link expired"),
            Cell(column_name="priority", value=2),
            Cell(column_name="call_recording_url", value="https://example.com/audio2.mp3"),
        ],
    ),
]

dataset = dataset.add_rows(rows=rows)

You should see dataset now hold 2 rows. Open the dataset in your Future AGI account to see both tickets listed with their priority and audio link.

Download the dataset

file_path = "support_ticket_review.csv"
dataset.download(file_path=file_path)

with open(file_path, "r") as file:
    print(file.read())

You should see the printed CSV with a header row (ticket_text,priority,call_recording_url) followed by the two rows you added.

Clean up

import os

if os.path.exists(file_path):
    os.remove(file_path)

dataset.delete()

You should see no output. The local CSV is removed and the dataset no longer appears in your Future AGI account.

Troubleshooting

SymptomCauseFix
ImportError: cannot import name 'ModelTypes' from 'fi.datasets'ModelTypes isn’t exported from fi.datasets, only Dataset, DatasetConfig, and HuggingfaceDatasetConfig areImport from fi.datasets.types instead: from fi.datasets.types import ModelTypes
ModuleNotFoundError: No module named 'fi.datasets.models'The fi.datasets.models module doesn’t exist in the SDKImport Column, Row, Cell, DataTypeChoices, SourceChoices from fi.datasets.types
401 Unauthorized on dataset.create()FI_API_KEY or FI_SECRET_KEY is unset, expired, or copied with a trailing spaceRe-export both keys from your account’s API keys page and retry
dataset.add_rows() raises a validation error on a cellA row’s column_name doesn’t match a name defined in add_columns()Check for typos and case mismatches between the row’s column_name and the column definitions
dataset.add_columns() fails with a duplicate name errorYou called add_columns() twice with an overlapping column nameAdd each column once, or fetch the existing dataset and check its columns before adding more
dataset.download() writes an empty fileadd_rows() was never called, or ran after download()Confirm rows were added successfully before downloading, and check the row count on dataset
Dataset name already exists error on create()DatasetConfig.name collides with a dataset already in your accountPick a unique name, or delete the existing dataset first with dataset.delete()

See Evaluator SDK Basics to run evals against the rows you just created.

Was this page helpful?

Questions & Discussion