Skip to content

Commit 4e0baab

Browse files
authored
Release/1.1.300 (#1028)
* Add starters * Debug mode * Rework CoT * Rework Avatars * Remove PP
1 parent 4f7fb2d commit 4e0baab

File tree

175 files changed

+2207
-5668
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+2207
-5668
lines changed

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,33 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
88

99
Nothing unreleased!
1010

11+
## [1.1.300rc0] - 2024-05-27
12+
13+
### Added
14+
15+
- Debug mode when starting with `-d`. Only available if the data layer supports it. This replaces the Prompt Playground.
16+
- `@cl.set_starters` and `cl.Starter` to suggest conversation starters to the user
17+
- `default` theme config in `config.toml`
18+
- If only one OAuth provider is set, automatically redirect the user to it
19+
20+
### Changed
21+
22+
- **[BREAKING]** Avatars have been reworked. `cl.Avatar` has been removed, instead place your avatars by name in `/public/avatars/*`
23+
- **[BREAKING]** The `running`, `took_one` and `took_other` translations have been replaced by `used`.
24+
- **[BREAKING]** `root` attribute of `cl.Step` has been removed. Use `cl.Message` to send root level messages.
25+
- Chain of Thought has been reworked. Only steps of type `tool` will be displayed if `hide_cot` is false
26+
- The `show_readme_as_default` config has been removed
27+
- No longer collapse root level messages
28+
29+
### Fixed
30+
31+
- The Chat Profile description should now disappear when not hovered.
32+
- Error handling of steps has been improved
33+
- No longer stream the first token twice
34+
- Copilot should now work as expected even if the user is closing/reopening it
35+
- Copilot CSS should no longer leak/be impacted by the host website CSS
36+
- Fix various `cl.Context` errors
37+
1138
## [1.1.202] - 2024-05-22
1239

1340
### Added

backend/chainlit/__init__.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from chainlit.context import context
2929
from chainlit.element import (
3030
Audio,
31-
Avatar,
3231
File,
3332
Image,
3433
Pdf,
@@ -52,7 +51,7 @@
5251
from chainlit.step import Step, step
5352
from chainlit.sync import make_async, run_sync
5453
from chainlit.telemetry import trace
55-
from chainlit.types import AudioChunk, ChatProfile, ThreadDict
54+
from chainlit.types import AudioChunk, ChatProfile, Starter, ThreadDict
5655
from chainlit.user import PersistedUser, User
5756
from chainlit.user_session import user_session
5857
from chainlit.utils import make_module_getattr, wrap_user_function
@@ -208,6 +207,22 @@ def set_chat_profiles(
208207
return func
209208

210209

210+
@trace
211+
def set_starters(func: Callable[[Optional["User"]], List["Starter"]]) -> Callable:
212+
"""
213+
Programmatic declaration of the available starter (can depend on the User from the session if authentication is setup).
214+
215+
Args:
216+
func (Callable[[Optional["User"]], List["Starter"]]): The function declaring the starters.
217+
218+
Returns:
219+
Callable[[Optional["User"]], List["Starter"]]: The decorated function.
220+
"""
221+
222+
config.code.set_starters = wrap_user_function(func)
223+
return func
224+
225+
211226
@trace
212227
def on_chat_end(func: Callable) -> Callable:
213228
"""
@@ -348,6 +363,8 @@ def acall(self):
348363
)
349364

350365
__all__ = [
366+
"ChatProfile",
367+
"Starter",
351368
"user_session",
352369
"CopilotFunction",
353370
"AudioChunk",
@@ -359,7 +376,6 @@ def acall(self):
359376
"Plotly",
360377
"Image",
361378
"Text",
362-
"Avatar",
363379
"Pyplot",
364380
"File",
365381
"Task",

backend/chainlit/config.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
from importlib import util
66
from pathlib import Path
7-
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union, Literal
7+
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Literal, Optional, Union
88

99
import tomli
1010
from chainlit.logger import logger
@@ -18,7 +18,7 @@
1818
from chainlit.action import Action
1919
from chainlit.element import ElementBased
2020
from chainlit.message import Message
21-
from chainlit.types import AudioChunk, ChatProfile, ThreadDict
21+
from chainlit.types import AudioChunk, ChatProfile, Starter, ThreadDict
2222
from chainlit.user import User
2323
from fastapi import Request, Response
2424

@@ -61,9 +61,6 @@
6161
# follow_symlink = false
6262
6363
[features]
64-
# Show the prompt playground
65-
prompt_playground = true
66-
6764
# Process and display HTML in messages. This can be a security risk (see https://stackoverflow.com/questions/19603097/why-is-it-dangerous-to-render-user-generated-html-or-javascript)
6865
unsafe_allow_html = false
6966
@@ -95,21 +92,15 @@
9592
sample_rate = 44100
9693
9794
[UI]
98-
# Name of the app and chatbot.
99-
name = "Chatbot"
100-
101-
# Show the readme while the thread is empty.
102-
show_readme_as_default = true
95+
# Name of the assistant.
96+
name = "Assistant"
10397
104-
# Description of the app and chatbot. This is used for HTML tags.
98+
# Description of the assistant. This is used for HTML tags.
10599
# description = ""
106100
107101
# Large size content are by default collapsed for a cleaner ui
108102
default_collapse_content = true
109103
110-
# The default value for the expand messages settings.
111-
default_expand_messages = false
112-
113104
# Hide the chain of thought details from the user in the UI.
114105
hide_cot = false
115106
@@ -136,6 +127,7 @@
136127
# custom_build = "./public/build"
137128
138129
[UI.theme]
130+
default = "dark"
139131
#layout = "wide"
140132
#font_family = "Inter, sans-serif"
141133
# Override default MUI light theme. (Check theme.ts)
@@ -192,11 +184,13 @@ class PaletteOptions(DataClassJsonMixin):
192184
light: Optional[str] = ""
193185
dark: Optional[str] = ""
194186

187+
195188
@dataclass()
196189
class TextOptions(DataClassJsonMixin):
197190
primary: Optional[str] = ""
198191
secondary: Optional[str] = ""
199192

193+
200194
@dataclass()
201195
class Palette(DataClassJsonMixin):
202196
primary: Optional[PaletteOptions] = None
@@ -208,6 +202,7 @@ class Palette(DataClassJsonMixin):
208202
@dataclass()
209203
class Theme(DataClassJsonMixin):
210204
font_family: Optional[str] = None
205+
default: Optional[Literal["light", "dark"]] = "dark"
211206
layout: Optional[Literal["default", "wide"]] = "default"
212207
light: Optional[Palette] = None
213208
dark: Optional[Palette] = None
@@ -234,7 +229,6 @@ class AudioFeature(DataClassJsonMixin):
234229

235230
@dataclass()
236231
class FeaturesSettings(DataClassJsonMixin):
237-
prompt_playground: bool = True
238232
spontaneous_file_upload: Optional[SpontaneousFileUploadFeature] = None
239233
audio: Optional[AudioFeature] = Field(default_factory=AudioFeature)
240234
latex: bool = False
@@ -245,12 +239,10 @@ class FeaturesSettings(DataClassJsonMixin):
245239
@dataclass()
246240
class UISettings(DataClassJsonMixin):
247241
name: str
248-
show_readme_as_default: bool = True
249242
description: str = ""
250243
hide_cot: bool = False
251244
# Large size content are by default collapsed for a cleaner ui
252245
default_collapse_content: bool = True
253-
default_expand_messages: bool = False
254246
github: Optional[str] = None
255247
theme: Optional[Theme] = None
256248
# Optional custom CSS file that allows you to customize the UI
@@ -289,6 +281,7 @@ class CodeSettings:
289281
set_chat_profiles: Optional[Callable[[Optional["User"]], List["ChatProfile"]]] = (
290282
None
291283
)
284+
set_starters: Optional[Callable[[Optional["User"]], List["Starter"]]] = None
292285

293286

294287
@dataclass()

backend/chainlit/data/__init__.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ async def update_thread(
139139
async def delete_user_session(self, id: str) -> bool:
140140
return True
141141

142+
async def build_debug_url(self) -> str:
143+
return ""
144+
142145

143146
_data_layer: Optional[BaseDataLayer] = None
144147

@@ -225,6 +228,14 @@ def step_to_step_dict(self, step: LiteralStep) -> "StepDict":
225228
"waitForAnswer": metadata.get("waitForAnswer", False),
226229
}
227230

231+
async def build_debug_url(self) -> str:
232+
try:
233+
project_id = await self.client.api.get_my_project_id()
234+
return f"{self.client.api.url}/projects/{project_id}/threads?threadId=[thread_id]&currentStepId=[step_id]"
235+
except Exception as e:
236+
logger.error(f"Error building debug url: {e}")
237+
return ""
238+
228239
async def get_user(self, identifier: str) -> Optional[PersistedUser]:
229240
user = await self.client.api.get_user(identifier=identifier)
230241
if not user:
@@ -456,12 +467,12 @@ async def get_thread(self, thread_id: str) -> "Optional[ThreadDict]":
456467
steps = [] # List[StepDict]
457468
if thread.steps:
458469
for step in thread.steps:
459-
if config.ui.hide_cot and step.parent_id:
470+
if config.ui.hide_cot and (
471+
step.parent_id or "message" not in step.type
472+
):
460473
continue
461474
for attachment in step.attachments:
462475
elements.append(self.attachment_to_element_dict(attachment))
463-
if not config.features.prompt_playground and step.generation:
464-
step.generation = None
465476
steps.append(self.step_to_step_dict(step))
466477

467478
return {

backend/chainlit/data/sql_alchemy.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import aiohttp
1010
from chainlit.context import context
1111
from chainlit.data import BaseDataLayer, BaseStorageClient, queue_until_user_message
12-
from chainlit.element import Avatar, ElementDict
12+
from chainlit.element import ElementDict
1313
from chainlit.logger import logger
1414
from chainlit.step import StepDict
1515
from chainlit.types import (
@@ -65,6 +65,9 @@ def __init__(
6565
"SQLAlchemyDataLayer storage client is not initialized and elements will not be persisted!"
6666
)
6767

68+
async def build_debug_url(self) -> str:
69+
return ""
70+
6871
###### SQL Helpers ######
6972
async def execute_sql(
7073
self, query: str, parameters: dict
@@ -373,8 +376,6 @@ async def create_element(self, element: "Element"):
373376
logger.info(f"SQLAlchemy: create_element, element_id = {element.id}")
374377
if not getattr(context.session.user, "id", None):
375378
raise ValueError("No authenticated user in context")
376-
if isinstance(element, Avatar): # Skip creating elements of type avatar
377-
return
378379
if not self.storage_provider:
379380
logger.warn(
380381
f"SQLAlchemy: create_element error. No blob_storage_client is configured!"

backend/chainlit/discord/app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ async def send_step(self, step_dict: StepDict):
104104
is_message = step_type in [
105105
"user_message",
106106
"assistant_message",
107-
"system_message",
108107
]
109108
is_chain_of_thought = bool(step_dict.get("parentId"))
110109
is_empty_output = not step_dict.get("output")

backend/chainlit/element.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
}
2222

2323
ElementType = Literal[
24-
"image", "avatar", "text", "pdf", "tasklist", "audio", "video", "file", "plotly"
24+
"image", "text", "pdf", "tasklist", "audio", "video", "file", "plotly"
2525
]
2626
ElementDisplay = Literal["inline", "side", "page"]
2727
ElementSize = Literal["small", "medium", "large"]
@@ -190,14 +190,6 @@ class Image(Element):
190190
size: ElementSize = "medium"
191191

192192

193-
@dataclass
194-
class Avatar(Element):
195-
type: ClassVar[ElementType] = "avatar"
196-
197-
async def send(self):
198-
await super().send(for_id="")
199-
200-
201193
@dataclass
202194
class Text(Element):
203195
"""Useful to send a text (not a message) to the UI."""

backend/chainlit/langchain/callbacks.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def _start_trace(self, run: Run) -> None:
456456
elif run.run_type == "llm":
457457
step_type = "llm"
458458
elif run.run_type == "retriever":
459-
step_type = "retrieval"
459+
step_type = "tool"
460460
elif run.run_type == "tool":
461461
step_type = "tool"
462462
elif run.run_type == "embedding":
@@ -533,7 +533,9 @@ def _on_run_update(self, run: Run) -> None:
533533
break
534534

535535
current_step.language = "json"
536-
current_step.output = json.dumps(message_completion, indent=4, ensure_ascii=False)
536+
current_step.output = json.dumps(
537+
message_completion, indent=4, ensure_ascii=False
538+
)
537539
else:
538540
completion_start = self.completion_generations[str(run.id)]
539541
completion = generation.get("text", "")

backend/chainlit/llama_index/callbacks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ def on_event_start(
7373

7474
step_type: StepType = "undefined"
7575
if event_type == CBEventType.RETRIEVE:
76-
step_type = "retrieval"
76+
step_type = "tool"
7777
elif event_type == CBEventType.QUERY:
78-
step_type = "retrieval"
78+
step_type = "tool"
7979
elif event_type == CBEventType.LLM:
8080
step_type = "llm"
8181
else:

0 commit comments

Comments
 (0)