-
Notifications
You must be signed in to change notification settings - Fork 725
/
types.py
167 lines (115 loc) · 3.3 KB
/
types.py
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
from enum import Enum
from typing import TYPE_CHECKING, Dict, List, Literal, Optional, TypedDict, Union
if TYPE_CHECKING:
from chainlit.element import ElementDict
from chainlit.user import UserDict
from chainlit.step import StepDict
from dataclasses_json import DataClassJsonMixin
from literalai import ChatGeneration, CompletionGeneration
from pydantic import BaseModel
from pydantic.dataclasses import dataclass
InputWidgetType = Literal[
"switch", "slider", "select", "textinput", "tags", "numberinput"
]
class ThreadDict(TypedDict):
id: str
createdAt: str
name: Optional[str]
user: Optional["UserDict"]
tags: Optional[List[str]]
metadata: Optional[Dict]
steps: List["StepDict"]
elements: Optional[List["ElementDict"]]
class Pagination(BaseModel):
first: int
cursor: Optional[str] = None
class ThreadFilter(BaseModel):
feedback: Optional[Literal[0, 1]] = None
userId: Optional[str] = None
search: Optional[str] = None
@dataclass
class FileSpec(DataClassJsonMixin):
accept: Union[List[str], Dict[str, List[str]]]
max_files: int
max_size_mb: int
@dataclass
class ActionSpec(DataClassJsonMixin):
keys: List[str]
@dataclass
class AskSpec(DataClassJsonMixin):
"""Specification for asking the user."""
timeout: int
type: Literal["text", "file", "action"]
@dataclass
class AskFileSpec(FileSpec, AskSpec, DataClassJsonMixin):
"""Specification for asking the user a file."""
@dataclass
class AskActionSpec(ActionSpec, AskSpec, DataClassJsonMixin):
"""Specification for asking the user an action"""
class FileReference(TypedDict):
id: str
class FileDict(TypedDict):
id: str
name: str
path: str
size: int
type: str
class UIMessagePayload(TypedDict):
message: "StepDict"
fileReferences: Optional[List[FileReference]]
@dataclass
class AskFileResponse:
id: str
name: str
path: str
size: int
type: str
class AskActionResponse(TypedDict):
name: str
value: str
label: str
description: str
forId: str
id: str
collapsed: bool
class GenerationRequest(BaseModel):
chatGeneration: Optional[ChatGeneration] = None
completionGeneration: Optional[CompletionGeneration] = None
userEnv: Dict[str, str]
@property
def generation(self):
if self.chatGeneration:
return self.chatGeneration
return self.completionGeneration
def is_chat(self):
return self.chatGeneration is not None
class DeleteThreadRequest(BaseModel):
threadId: str
class DeleteFeedbackRequest(BaseModel):
feedbackId: str
class GetThreadsRequest(BaseModel):
pagination: Pagination
filter: ThreadFilter
class Theme(str, Enum):
light = "light"
dark = "dark"
@dataclass
class ChatProfile(DataClassJsonMixin):
"""Specification for a chat profile that can be chosen by the user at the thread start."""
name: str
markdown_description: str
icon: Optional[str] = None
FeedbackStrategy = Literal["BINARY"]
class FeedbackDict(TypedDict):
forId: str
id: Optional[str]
value: Literal[0, 1]
comment: Optional[str]
@dataclass
class Feedback:
forId: str
value: Literal[0, 1]
id: Optional[str] = None
comment: Optional[str] = None
class UpdateFeedbackRequest(BaseModel):
feedback: Feedback