Elron commited on
Commit
3c36ff5
1 Parent(s): 0bf7467

Upload api.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. api.py +30 -0
api.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, Dict, List, Union
2
+
3
+ from datasets import DatasetDict
4
+
5
+ from .artifact import fetch_artifact
6
+ from .dataset import get_dataset_artifact
7
+ from .logging_utils import get_logger
8
+ from .metric_utils import _compute
9
+ from .operator import StreamSource
10
+
11
+ logger = get_logger()
12
+
13
+
14
+ def load(source: Union[StreamSource, str]) -> DatasetDict:
15
+ assert isinstance(
16
+ source, (StreamSource, str)
17
+ ), "source must be a StreamSource or a string"
18
+ if isinstance(source, str):
19
+ source, _ = fetch_artifact(source)
20
+ return source().to_dataset()
21
+
22
+
23
+ def load_dataset(dataset_query: str) -> DatasetDict:
24
+ dataset_query = dataset_query.replace("sys_prompt", "instruction")
25
+ dataset_stream = get_dataset_artifact(dataset_query)
26
+ return dataset_stream().to_dataset()
27
+
28
+
29
+ def evaluate(predictions, data) -> List[Dict[str, Any]]:
30
+ return _compute(predictions=predictions, references=data)