Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow None for timeout in AskSpec to support indefinite waits #925

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 19 additions & 2 deletions backend/chainlit/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
from enum import Enum
from typing import TYPE_CHECKING, Dict, List, Literal, Optional, TypedDict, Union, Generic, TypeVar, Protocol, Any
from typing import (
TYPE_CHECKING,
Any,
Dict,
Generic,
List,
Literal,
Optional,
Protocol,
TypedDict,
TypeVar,
Union,
)

if TYPE_CHECKING:
from chainlit.element import ElementDict
Expand Down Expand Up @@ -37,6 +49,7 @@ class ThreadFilter(BaseModel):
userId: Optional[str] = None
search: Optional[str] = None


@dataclass
class PageInfo:
hasNextPage: bool
Expand All @@ -59,13 +72,16 @@ def from_dict(cls, page_info_dict: Dict) -> "PageInfo":
hasNextPage=hasNextPage, startCursor=startCursor, endCursor=endCursor
)


T = TypeVar("T", covariant=True)


class HasFromDict(Protocol[T]):
@classmethod
def from_dict(cls, obj_dict: Any) -> T:
raise NotImplementedError()


@dataclass
class PaginatedResponse(Generic[T]):
pageInfo: PageInfo
Expand All @@ -90,6 +106,7 @@ def from_dict(

return cls(pageInfo=pageInfo, data=data)


@dataclass
class FileSpec(DataClassJsonMixin):
accept: Union[List[str], Dict[str, List[str]]]
Expand All @@ -106,7 +123,7 @@ class ActionSpec(DataClassJsonMixin):
class AskSpec(DataClassJsonMixin):
"""Specification for asking the user."""

timeout: int
timeout: Optional[int]
type: Literal["text", "file", "action"]


Expand Down