datasets api

This commit is contained in:
Xi Yan 2024-10-14 13:16:39 -07:00
parent 18fe966e96
commit f046899a1c
15 changed files with 281 additions and 80 deletions

View file

@ -4,4 +4,4 @@
# This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree.
from .dataset import * # noqa: F401 F403
from .datasets import * # noqa: F401 F403

View file

@ -0,0 +1,92 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree.
import asyncio
import json
import fire
import httpx
from .datasets import * # noqa: F403
class DatasetClient(Datasets):
def __init__(self, base_url: str):
self.base_url = base_url
async def initialize(self) -> None:
pass
async def shutdown(self) -> None:
pass
async def create_dataset(
self,
dataset_def: DatasetDef,
) -> None:
async with httpx.AsyncClient() as client:
response = await client.post(
f"{self.base_url}/datasets/create",
json={
"dataset_def": json.loads(dataset_def.json()),
},
headers={"Content-Type": "application/json"},
timeout=60,
)
response.raise_for_status()
return None
async def get_dataset(
self,
dataset_identifier: str,
) -> DatasetDef:
async with httpx.AsyncClient() as client:
response = await client.post(
f"{self.base_url}/datasets/create",
json={
"dataset_identifier": dataset_identifier,
},
headers={"Content-Type": "application/json"},
timeout=60,
)
response.raise_for_status()
return DatasetDef(**response.json())
async def delete_dataset(
self,
dataset_identifier: str,
) -> DatasetDef:
async with httpx.AsyncClient() as client:
response = await client.post(
f"{self.base_url}/datasets/delete",
json={
"dataset_identifier": dataset_identifier,
},
headers={"Content-Type": "application/json"},
timeout=60,
)
response.raise_for_status()
return None
async def run_main(host: str, port: int):
client = DatasetClient(f"http://{host}:{port}")
# Custom Eval Task
response = await client.create_dataset(
dataset_def=CustomDatasetDef(
identifier="test-dataset",
url="https://openaipublic.blob.core.windows.net/simple-evals/mmlu.csv",
),
)
def main(host: str, port: int):
asyncio.run(run_main(host, port))
if __name__ == "__main__":
fire.Fire(main)

View file

@ -143,19 +143,19 @@ class BaseDataset(ABC, Generic[TDatasetSample]):
class Datasets(Protocol):
@webmethod(route="/datasets/create")
def create_dataset(
async def create_dataset(
self,
dataset: DatasetDef,
dataset_def: DatasetDef,
) -> None: ...
@webmethod(route="/datasets/get")
def get_dataset(
async def get_dataset(
self,
dataset_identifier: str,
) -> DatasetDef: ...
@webmethod(route="/datasets/delete")
def delete_dataset(
async def delete_dataset(
self,
dataset_uuid: str,
dataset_identifier: str,
) -> None: ...

View file

@ -11,7 +11,7 @@ from llama_models.schema_utils import webmethod
from pydantic import BaseModel
from llama_models.llama3.api.datatypes import * # noqa: F403
from llama_stack.apis.dataset import * # noqa: F403
from llama_stack.apis.datasets import * # noqa: F403
class EvaluationJob(BaseModel):