API Reference
set_chat_profiles
Decorator to define the list of chat profiles.
If authentication is enabled, you can access the user details to create the list of chat profiles conditionally.
The icon is optional.
Parameters
current_user
AppUser
The message coming from the UI.
Usage
Simple code example
import chainlit as cl
@cl.set_chat_profiles
async def chat_profile():
return [
cl.ChatProfile(
name="GPT-3.5",
markdown_description="The underlying LLM model is **GPT-3.5**.",
icon="https://picsum.photos/200",
),
cl.ChatProfile(
name="GPT-4",
markdown_description="The underlying LLM model is **GPT-4**.",
icon="https://picsum.photos/250",
),
]
@cl.on_chat_start
async def on_chat_start():
chat_profile = cl.user_session.get("chat_profile")
await cl.Message(
content=f"starting chat using the {chat_profile} chat profile"
).send()
Code example with authentication
from typing import Optional
import chainlit as cl
@cl.set_chat_profiles
async def chat_profile(current_user: cl.AppUser):
if "admin_user" not in current_user.tags:
# Default to 3.5 when not admin
return [
cl.ChatProfile(
name="GPT-3.5",
markdown_description="The underlying LLM model is **GPT-3.5**.",
icon="https://picsum.photos/200",
)
]
return [
cl.ChatProfile(
name="GPT-3.5",
markdown_description="The underlying LLM model is **GPT-3.5**.",
icon="https://picsum.photos/200",
),
cl.ChatProfile(
name="GPT-4",
markdown_description="The underlying LLM model is **GPT-4**.",
icon="https://picsum.photos/250",
),
]
@cl.password_auth_callback
def auth_callback(username: str, password: str) -> Optional[cl.AppUser]:
if (username, password) == ("admin", "admin"):
return cl.AppUser(
username="admin", role="ADMIN", provider="credentials", tags=["admin_user"]
)
elif (username, password) == ("test", "test"):
return cl.AppUser(
username="test", role="USER", provider="credentials", tags=["regular_user"]
)
else:
return None
@cl.on_chat_start
async def on_chat_start():
app_user = cl.user_session.get("user")
chat_profile = cl.user_session.get("chat_profile")
await cl.Message(
content=f"starting chat with {app_user.username} using the {chat_profile} chat profile"
).send()
Was this page helpful?