chainlit 1.1.0rc1__py3-none-any.whl → 1.1.101__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of chainlit might be problematic. Click here for more details.

chainlit/config.py CHANGED
@@ -4,7 +4,7 @@ import site
4
4
  import sys
5
5
  from importlib import util
6
6
  from pathlib import Path
7
- from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
7
+ from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union, Literal
8
8
 
9
9
  import tomli
10
10
  from chainlit.logger import logger
@@ -132,9 +132,10 @@ hide_cot = false
132
132
  # Be careful: If this is a relative path, it should not start with a slash.
133
133
  # custom_build = "./public/build"
134
134
 
135
- # Override default MUI light theme. (Check theme.ts)
136
135
  [UI.theme]
136
+ #layout = "wide"
137
137
  #font_family = "Inter, sans-serif"
138
+ # Override default MUI light theme. (Check theme.ts)
138
139
  [UI.theme.light]
139
140
  #background = "#FAFAFA"
140
141
  #paper = "#FFFFFF"
@@ -194,6 +195,7 @@ class Palette(DataClassJsonMixin):
194
195
  @dataclass()
195
196
  class Theme(DataClassJsonMixin):
196
197
  font_family: Optional[str] = None
198
+ layout: Optional[Literal["default", "wide"]] = "default"
197
199
  light: Optional[Palette] = None
198
200
  dark: Optional[Palette] = None
199
201
 
chainlit/context.py CHANGED
@@ -1,15 +1,15 @@
1
1
  import asyncio
2
2
  import uuid
3
3
  from contextvars import ContextVar
4
- from typing import TYPE_CHECKING, Dict, Optional, Union, List
4
+ from typing import TYPE_CHECKING, Dict, List, Optional, Union
5
5
 
6
- from chainlit.session import HTTPSession, WebsocketSession
6
+ from chainlit.session import ClientType, HTTPSession, WebsocketSession
7
7
  from lazify import LazyProxy
8
8
 
9
9
  if TYPE_CHECKING:
10
10
  from chainlit.emitter import BaseChainlitEmitter
11
- from chainlit.user import PersistedUser, User
12
11
  from chainlit.step import Step
12
+ from chainlit.user import PersistedUser, User
13
13
 
14
14
 
15
15
  class ChainlitContextException(Exception):
@@ -28,13 +28,20 @@ class ChainlitContext:
28
28
  if self.active_steps:
29
29
  return self.active_steps[-1]
30
30
 
31
- def __init__(self, session: Union["HTTPSession", "WebsocketSession"]):
31
+ def __init__(
32
+ self,
33
+ session: Union["HTTPSession", "WebsocketSession"],
34
+ emitter: Optional["BaseChainlitEmitter"] = None,
35
+ ):
32
36
  from chainlit.emitter import BaseChainlitEmitter, ChainlitEmitter
33
37
 
34
38
  self.loop = asyncio.get_running_loop()
35
39
  self.session = session
36
40
  self.active_steps = []
37
- if isinstance(self.session, HTTPSession):
41
+
42
+ if emitter:
43
+ self.emitter = emitter
44
+ elif isinstance(self.session, HTTPSession):
38
45
  self.emitter = BaseChainlitEmitter(self.session)
39
46
  elif isinstance(self.session, WebsocketSession):
40
47
  self.emitter = ChainlitEmitter(self.session)
@@ -56,15 +63,20 @@ def init_ws_context(session_or_sid: Union[WebsocketSession, str]) -> ChainlitCon
56
63
 
57
64
 
58
65
  def init_http_context(
66
+ thread_id: Optional[str] = None,
59
67
  user: Optional[Union["User", "PersistedUser"]] = None,
60
68
  auth_token: Optional[str] = None,
61
69
  user_env: Optional[Dict[str, str]] = None,
70
+ client_type: ClientType = "webapp",
62
71
  ) -> ChainlitContext:
72
+ session_id = str(uuid.uuid4())
73
+ thread_id = thread_id or str(uuid.uuid4())
63
74
  session = HTTPSession(
64
- id=str(uuid.uuid4()),
75
+ id=session_id,
76
+ thread_id=thread_id,
65
77
  token=auth_token,
66
78
  user=user,
67
- client_type="app",
79
+ client_type=client_type,
68
80
  user_env=user_env,
69
81
  )
70
82
  context = ChainlitContext(session)