聊天
聊天配置文件
聊天
聊天配置文件
用于定义聊天配置文件列表的装饰器。
如果启用了身份验证,您可以访问用户详情以有条件地创建聊天配置文件列表。
图标是可选的。
参数
来自 UI 的消息。
用法
简单示例
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()
带身份验证
from typing import Optional
import chainlit as cl
@cl.set_chat_profiles
async def chat_profile(current_user: cl.User):
if current_user.metadata["role"] != "ADMIN":
return None
return [
cl.ChatProfile(
name="GPT-3.5",
markdown_description="The underlying LLM model is **GPT-3.5**, a *175B parameter model* trained on 410GB of text data.",
),
cl.ChatProfile(
name="GPT-4",
markdown_description="The underlying LLM model is **GPT-4**, a *1.5T parameter model* trained on 3.5TB of text data.",
icon="https://picsum.photos/250",
),
cl.ChatProfile(
name="GPT-5",
markdown_description="The underlying LLM model is **GPT-5**.",
icon="https://picsum.photos/200",
),
]
@cl.password_auth_callback
def auth_callback(username: str, password: str) -> Optional[cl.User]:
if (username, password) == ("admin", "admin"):
return cl.User(identifier="admin", metadata={"role": "ADMIN"})
else:
return None
@cl.on_chat_start
async def on_chat_start():
user = cl.user_session.get("user")
chat_profile = cl.user_session.get("chat_profile")
await cl.Message(
content=f"starting chat with {user.identifier} using the {chat_profile} chat profile"
).send()