Skip to content

Commit

Permalink
Attempt to satisfy mypy (plus cleaner approach).
Browse files Browse the repository at this point in the history
  • Loading branch information
dokterbob committed Sep 30, 2024
1 parent 0cfa1bf commit c2eaf0c
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions backend/chainlit/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class ElementDict(TypedDict):

@dataclass
class Element:
# Thread id
thread_id: str = Field(default_factory=lambda: context.session.thread_id)
# The type of the element. This will be used to determine how to display the element in the UI.
type: ClassVar[ElementType]
# Name of the element, this will be used to reference the element in the UI.
Expand All @@ -83,15 +85,11 @@ class Element:
language: Optional[str] = None
# Mime type, infered based on content if not provided
mime: Optional[str] = None
# Thread id
thread_id: Optional[str] = None

def __post_init__(self) -> None:
trace_event(f"init {self.__class__.__name__}")
self.persisted = False
self.updatable = False
if not self.thread_id:
self.thread_id = context.session.thread_id

if not self.url and not self.path and not self.content:
raise ValueError("Must provide url, path or content to instantiate element")
Expand Down

0 comments on commit c2eaf0c

Please sign in to comment.