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

fix: limit thread name #1733

Merged
merged 1 commit into from
Jan 17, 2025
Merged
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
16 changes: 11 additions & 5 deletions backend/chainlit/data/chainlit_data_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,13 +530,15 @@ async def update_thread(
if self.show_logger:
logger.info(f"asyncpg: update_thread, thread_id={thread_id}")

thread_name = truncate(
name
if name is not None
else (metadata.get("name") if metadata and "name" in metadata else None)
)

data = {
"id": thread_id,
"name": (
name
if name is not None
else (metadata.get("name") if metadata and "name" in metadata else None)
),
"name": thread_name,
"userId": user_id,
"tags": tags,
"metadata": json.dumps(metadata or {}),
Expand Down Expand Up @@ -606,3 +608,7 @@ async def cleanup(self):
"""Cleanup database connections"""
if self.pool:
await self.pool.close()


def truncate(text: Optional[str], max_length: int = 255) -> Optional[str]:
return None if text is None else text[:max_length]
Loading