1
1
from collections .abc import Iterable
2
+ from functools import cache
2
3
from pathlib import Path
3
- from typing import Annotated , Any , Literal , Optional , Union
4
+ from typing import Annotated , Any , Literal , Optional , TypeVar , Union
4
5
5
6
from datasets import Dataset , DatasetDict , IterableDataset , IterableDatasetDict
6
7
from pydantic import BeforeValidator , Field , NonNegativeInt , PositiveFloat , PositiveInt
13
14
from guidellm .objects .pydantic import StandardBaseModel
14
15
from guidellm .scheduler .strategy import StrategyType
15
16
16
- __ALL__ = ["Scenario" , "GenerativeTextScenario" ]
17
+ __ALL__ = ["Scenario" , "GenerativeTextScenario" , "get_builtin_scenarios" ]
18
+
19
+ SCENARIO_DIR = Path (__file__ ).parent / "scenarios/"
20
+
21
+
22
+ @cache
23
+ def get_builtin_scenarios () -> list [str ]:
24
+ return [p .stem for p in SCENARIO_DIR .glob ("*.json" )]
17
25
18
26
19
27
def parse_float_list (value : Union [str , float , list [float ]]) -> list [float ]:
@@ -32,9 +40,21 @@ def parse_float_list(value: Union[str, float, list[float]]) -> list[float]:
32
40
) from err
33
41
34
42
43
+ T = TypeVar ("T" , bound = "Scenario" )
44
+
45
+
35
46
class Scenario (StandardBaseModel ):
36
47
target : str
37
48
49
+ @classmethod
50
+ def from_builtin (cls : type [T ], name : str , overrides : Optional [dict ] = None ) -> T :
51
+ filename = SCENARIO_DIR / f"{ name } .json"
52
+
53
+ if not filename .is_file ():
54
+ raise ValueError (f"{ name } is not a vaild builtin scenario" )
55
+
56
+ return cls .from_file (filename , overrides )
57
+
38
58
39
59
class GenerativeTextScenario (Scenario ):
40
60
# FIXME: This solves an issue with Pydantic and class types
0 commit comments