| 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | # All rights reserved. |
| 3 | # |
| 4 | # This source code is licensed under the terms described in the LICENSE file in |
| 5 | # the root directory of this source tree. |
| 6 | |
| 7 | from enum import Enum |
| 8 | from typing import Any, Dict, Optional, Protocol |
| 9 | |
| 10 | from llama_models.llama3.api.datatypes import URL |
| 11 | |
| 12 | from llama_models.schema_utils import json_schema_type, webmethod |
| 13 | |
| 14 | from pydantic import BaseModel |
| 15 | |
| 16 | |
| 17 | @json_schema_type |
| 18 | class TrainEvalDatasetColumnType(Enum): |
| 19 | dialog = "dialog" |
| 20 | text = "text" |
| 21 | media = "media" |
| 22 | number = "number" |
| 23 | json = "json" |
| 24 | |
| 25 | |
| 26 | @json_schema_type |
| 27 | class TrainEvalDataset(BaseModel): |
| 28 | """Dataset to be used for training or evaluating language models.""" |
| 29 | |
| 30 | # TODO(ashwin): figure out if we need to add an enum for a "dataset type" |
| 31 | |
| 32 | columns: Dict[str, TrainEvalDatasetColumnType] |
| 33 | content_url: URL |
| 34 | metadata: Optional[Dict[str, Any]] = None |
| 35 | |
| 36 | |
| 37 | @json_schema_type |
| 38 | class CreateDatasetRequest(BaseModel): |
| 39 | """Request to create a dataset.""" |
| 40 | |
| 41 | uuid: str |
| 42 | dataset: TrainEvalDataset |
| 43 | |
| 44 | |
| 45 | class Datasets(Protocol): |
| 46 | @webmethod(route="/datasets/create") |
| 47 | def create_dataset( |
| 48 | self, |
| 49 | uuid: str, |
| 50 | dataset: TrainEvalDataset, |
| 51 | ) -> None: ... |
| 52 | |
| 53 | @webmethod(route="/datasets/get") |
| 54 | def get_dataset( |
| 55 | self, |
| 56 | dataset_uuid: str, |
| 57 | ) -> TrainEvalDataset: ... |
| 58 | |
| 59 | @webmethod(route="/datasets/delete") |
| 60 | def delete_dataset( |
| 61 | self, |
| 62 | dataset_uuid: str, |
| 63 | ) -> None: ... |