Skip to content

Commit

Permalink
do not time.sleep
Browse files Browse the repository at this point in the history
Signed-off-by: San Nguyen <vinhsannguyen91@gmail.com>
  • Loading branch information
sandangel committed Sep 25, 2024
1 parent bdaed2b commit 4151787
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 61 deletions.
47 changes: 13 additions & 34 deletions backend/chainlit/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,40 +221,20 @@ async def init(
parent_id: Optional[str] = None,
created_at: Union[str, None] = None,
):
self = cls(content)
await asyncio.sleep(0.001)
self.language = language
if isinstance(content, dict):
try:
self.content = json.dumps(content, indent=4, ensure_ascii=False)
self.language = "json"
except TypeError:
self.content = str(content)
self.language = "text"
elif isinstance(content, str):
self.content = content
else:
self.content = str(content)
self.language = "text"

if id:
self.id = str(id)

if parent_id:
self.parent_id = str(parent_id)

if created_at:
self.created_at = created_at

self.metadata = metadata
self.tags = tags

self.author = author or config.ui.name
self.type = type
self.actions = actions if actions is not None else []
self.elements = elements if elements is not None else []

super().__post_init__(self)
self = cls(
content,
author,
language,
actions,
elements,
type,
metadata,
tags,
id,
parent_id,
created_at,
)
return self

def __init__(
Expand All @@ -271,7 +251,6 @@ def __init__(
parent_id: Optional[str] = None,
created_at: Union[str, None] = None,
):
time.sleep(0.001)
self.language = language
if isinstance(content, dict):
try:
Expand Down
38 changes: 11 additions & 27 deletions backend/chainlit/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,33 +191,18 @@ async def init(
language: Optional[str] = None,
show_input: Union[bool, str] = "json",
):
self = cls()
trace_event(f"init {self.__class__.__name__} {type}")
await asyncio.sleep(0.001)
self._input = ""
self._output = ""
self.thread_id = context.session.thread_id
self.name = name or ""
self.type = type
self.id = id or str(uuid.uuid4())
self.metadata = metadata or {}
self.tags = tags
self.is_error = False
self.show_input = show_input
self.parent_id = parent_id

self.language = language
self.generation = None
self.elements = elements or []

self.created_at = utc_now()
self.start = None
self.end = None

self.streaming = False
self.persisted = False
self.fail_on_persist_error = False

self = cls(
name,
type,
id,
parent_id,
elements,
metadata,
tags,
language,
show_input,
)
return self

def __init__(
Expand All @@ -233,7 +218,6 @@ def __init__(
show_input: Union[bool, str] = "json",
):
trace_event(f"init {self.__class__.__name__} {type}")
time.sleep(0.001)
self._input = ""
self._output = ""
self.thread_id = context.session.thread_id
Expand Down

0 comments on commit 4151787

Please sign in to comment.