"gradio_webserver.py" did not exist on "d359cda5fae1c9a6fe54ba12b940572edfbf87ac"
instance.py 1 KB
Newer Older
1
from dataclasses import dataclass, field
2
from typing import Literal, Tuple
3

lintangsutawika's avatar
lintangsutawika committed
4

5
6
@dataclass
class Instance:
7
8
9
10
11
12
    request_type: Literal[
        "loglikelihood",
        "loglikelihood_rolling",
        "generate_until",
        "multiple_choice",
    ]
haileyschoelkopf's avatar
haileyschoelkopf committed
13
14
15
16
17
18
    doc: dict
    arguments: tuple
    idx: int
    metadata: Tuple[str, int, int] = field(
        default_factory=lambda: (None, None, None)
    )  # TODO: better typehints here
19
20
21
    resps: list = field(default_factory=list)
    filtered_resps: dict = field(default_factory=dict)

22
    # initialized after init
23
24
25
26
    task_name: str = None
    doc_id: str = None
    repeats: str = None

Ethan Smith's avatar
Ethan Smith committed
27
    def __post_init__(self) -> None:
haileyschoelkopf's avatar
haileyschoelkopf committed
28
        # unpack metadata field
29
        self.task_name, self.doc_id, self.repeats = self.metadata
lintangsutawika's avatar
lintangsutawika committed
30

31
32
33
34
35
    @property
    def args(self):
        """
        Returns (string,) where `string` is the string to calculate loglikelihood over
        """
lintangsutawika's avatar
lintangsutawika committed
36
37
38
        return (
            self.arguments if isinstance(self.arguments, tuple) else (self.arguments,)
        )