Skip to content

Commit

Permalink
Mypy doesn't seem to play well with dataclasses-json class decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
ramnes committed Jul 25, 2023
1 parent 84b3c5b commit eaf039b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 24 deletions.
5 changes: 2 additions & 3 deletions src/chainlit/action.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from typing import Optional

from dataclasses_json import dataclass_json
from dataclasses_json import DataClassJsonMixin
from pydantic.dataclasses import dataclass

from chainlit.context import get_emitter
from chainlit.telemetry import trace_event


@dataclass_json
@dataclass
class Action:
class Action(DataClassJsonMixin):
# Name of the action, this should be used in the action_callback
name: str
# The value associated with the action. This is useful to differentiate between multiple actions with the same name.
Expand Down
5 changes: 2 additions & 3 deletions src/chainlit/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Union,
)

from dataclasses_json import dataclass_json
from dataclasses_json import DataClassJsonMixin
from pydantic.dataclasses import dataclass

from chainlit.types import (
Expand Down Expand Up @@ -77,9 +77,8 @@ class PageInfo:
T = TypeVar("T")


@dataclass_json
@dataclass
class PaginatedResponse(Generic[T]):
class PaginatedResponse(DataClassJsonMixin, Generic[T]):
pageInfo: PageInfo
data: List[T]

Expand Down
17 changes: 6 additions & 11 deletions src/chainlit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Literal, Optional, Union

import tomli
from dataclasses_json import dataclass_json
from dataclasses_json import DataClassJsonMixin
from pydantic.dataclasses import dataclass

from chainlit.logger import logger
Expand Down Expand Up @@ -109,32 +109,28 @@ class RunSettings:
ci: bool = False


@dataclass_json
@dataclass()
class PaletteOptions:
class PaletteOptions(DataClassJsonMixin):
main: Optional[str] = ""
light: Optional[str] = ""
dark: Optional[str] = ""


@dataclass_json
@dataclass()
class Palette:
class Palette(DataClassJsonMixin):
primary: PaletteOptions = None
background: Optional[str] = ""
paper: Optional[str] = ""


@dataclass_json
@dataclass()
class Theme:
class Theme(DataClassJsonMixin):
light: Palette = None
dark: Palette = None


@dataclass_json
@dataclass()
class UISettings:
class UISettings(DataClassJsonMixin):
name: str
description: str = ""
hide_cot: bool = False
Expand Down Expand Up @@ -171,9 +167,8 @@ def validate(self):
return True


@dataclass_json
@dataclass()
class ProjectSettings:
class ProjectSettings(DataClassJsonMixin):
# Enables Cloud features if provided
id: Optional[str] = None
# Whether the app is available to anonymous users or only to team members.
Expand Down
11 changes: 4 additions & 7 deletions src/chainlit/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Dict, List, Literal, Optional, TypedDict, Union

from dataclasses_json import dataclass_json
from dataclasses_json import DataClassJsonMixin
from pydantic import BaseModel
from pydantic.dataclasses import dataclass

Expand All @@ -11,18 +11,16 @@
ElementSize = Literal["small", "medium", "large"]


@dataclass_json
@dataclass
class AskSpec:
class AskSpec(DataClassJsonMixin):
"""Specification for asking the user."""

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


@dataclass_json
@dataclass
class AskFileSpec(AskSpec):
class AskFileSpec(AskSpec, DataClassJsonMixin):
"""Specification for asking the user for a file."""

accept: Union[List[str], Dict[str, List[str]]]
Expand All @@ -44,9 +42,8 @@ class AskFileResponse:
content: bytes


@dataclass_json
@dataclass
class LLMSettings:
class LLMSettings(DataClassJsonMixin):
model_name: str = "text-davinci-003"
stop: Optional[List[str]] = None
temperature: float = 0
Expand Down

0 comments on commit eaf039b

Please sign in to comment.