File size: 1,852 Bytes
c69aaec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""Shared decision schema and dataset records."""

from pathlib import Path
from typing import Literal, NotRequired, TypedDict

from PIL import Image

type JSONValue = str | int | float | bool | None | list[JSONValue] | dict[str, JSONValue]
type Content = str | dict[str, JSONValue] | list[JSONValue]
type ImageInput = str | Path | Image.Image
type Label = str | int | bool
type Target = Label | float | list[float]


class QuestionBase(TypedDict):
    instructions: NotRequired[Content | None]


class ChoiceQuestion(QuestionBase):
    type: Literal["choice"]
    criteria: dict[str, Content | None]


class NoulQuestion(QuestionBase):
    type: Literal["noul"]
    criteria: NotRequired[dict[Literal["true", "false"], Content | None] | None]


class ScoreQuestion(QuestionBase):
    type: Literal["score"]
    criteria: list[Content]


type Question = ChoiceQuestion | NoulQuestion | ScoreQuestion


class DecisionInput(TypedDict):
    state: Content
    question: Question
    images: NotRequired[list[ImageInput]]


class Example(DecisionInput):
    id: str
    suite: str
    family: str
    label: Label
    target: Target
    source: dict[str, JSONValue]


class ChoiceAnswer(TypedDict):
    type: Literal["choice"]
    choice: str
    probabilities: dict[str, float]
    confidence: float


class NoulAnswer(TypedDict):
    type: Literal["noul"]
    noul: float


class ScoreAnswer(TypedDict):
    type: Literal["score"]
    score: float
    legend: dict[str, Content | None]
    probabilities: dict[str, float]
    confidence: float


type Answer = ChoiceAnswer | NoulAnswer | ScoreAnswer


class Usage(TypedDict, total=False):
    input_tokens: int
    output_tokens: int


class DecisionResponse(TypedDict):
    answers: dict[str, Answer]
    usage: Usage
    model: NotRequired[str]
    id: NotRequired[str]
    provider: NotRequired[str]