Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions backend/chainlit/chat_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ def collect_settings(
collect_settings(settings, self.inputs)
return settings

def _inputs_as_dicts(self) -> List[dict[str, Any]]:
return [input_widget.to_dict() for input_widget in self.inputs]

async def refresh(self):
"""Push settings widgets to the UI without updating session chat_settings."""
settings = self.settings()
await context.emitter.emit("chat_settings", self._inputs_as_dicts())
return settings

async def send(self):
settings = self.settings()
context.emitter.set_chat_settings(settings)

inputs_content = [input_widget.to_dict() for input_widget in self.inputs]
await context.emitter.emit("chat_settings", inputs_content)

await context.emitter.emit("chat_settings", self._inputs_as_dicts())
return settings
18 changes: 18 additions & 0 deletions backend/tests/test_chat_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,24 @@ async def test_chat_settings_send(self, mock_chainlit_context):
assert call_args[0][0] == "chat_settings"
assert len(call_args[0][1]) == 2 # Two inputs

async def test_chat_settings_refresh(self, mock_chainlit_context):
"""Test ChatSettings.refresh() emits UI without updating session."""
async with mock_chainlit_context as ctx:
switch = Switch(id="enable", label="Enable", initial=True)
slider = Slider(id="temp", label="Temperature", initial=0.8)

settings = ChatSettings(inputs=[switch, slider])
result = await settings.refresh()

assert result["enable"] is True
assert result["temp"] == 0.8

ctx.emitter.set_chat_settings.assert_not_called()
ctx.emitter.emit.assert_called_once()
call_args = ctx.emitter.emit.call_args
assert call_args[0][0] == "chat_settings"
assert len(call_args[0][1]) == 2

async def test_chat_settings_send_with_tabs(self, mock_chainlit_context):
"""Test ChatSettings.send() with tabs."""
async with mock_chainlit_context as ctx:
Expand Down
Loading
Loading