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
12 changes: 12 additions & 0 deletions backend/chainlit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@
# Enable third parties caching (e.g., LangChain cache)
cache = false

# Whether to persist user environment variables (API keys) to the database
# Set to true to store user env vars in DB, false to exclude them for security
persist_user_env = false

# Whether to mask user environment variables (API keys) in the UI with password type
# Set to true to show API keys as ***, false to show them as plain text
mask_user_env = false

# Authorized origins
allow_origins = ["*"]

Expand Down Expand Up @@ -398,6 +406,10 @@ class ProjectSettings(BaseModel):
user_session_timeout: int = 1296000 # 15 days
# Enable third parties caching (e.g LangChain cache)
cache: bool = False
# Whether to persist user environment variables (API keys) to the database
persist_user_env: Optional[bool] = False
# Whether to mask user environment variables (API keys) in the UI with password type
mask_user_env: Optional[bool] = False


class ChainlitConfigOverrides(BaseModel):
Expand Down
1 change: 1 addition & 0 deletions backend/chainlit/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ async def project_settings(
"ui": cfg.ui.model_dump(),
"features": cfg.features.model_dump(),
"userEnv": cfg.project.user_env,
"maskUserEnv": cfg.project.mask_user_env,
"dataPersistence": data_layer is not None,
"threadResumable": bool(config.code.on_chat_resume),
"markdown": markdown,
Expand Down
10 changes: 9 additions & 1 deletion backend/chainlit/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,21 @@ async def persist_file(
return {"id": file_id}

def to_persistable(self) -> Dict:
from chainlit.config import config
from chainlit.user_session import user_sessions

user_session = user_sessions.get(self.id) or {} # type: Dict
user_session["chat_settings"] = self.chat_settings
user_session["chat_profile"] = self.chat_profile
user_session["client_type"] = self.client_type
metadata = clean_metadata(user_session)

# Check config setting for whether to persist user environment variables
user_session_copy = user_session.copy()
if not config.project.persist_user_env:
# Remove user environment variables (API keys) before persisting to database
user_session_copy["env"] = {}

metadata = clean_metadata(user_session_copy)
return metadata


Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/Env.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const Env = () => {
<Label htmlFor={key}>{key}</Label>
<Input
id={key}
type={config?.maskUserEnv !== false ? "password" : "text"}
{...register(key)}
className={
touchedFields[key] && errors[key] ? 'border-red-500' : ''
Expand Down
1 change: 1 addition & 0 deletions libs/react-client/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export interface IChainlitConfig {
};
debugUrl?: string;
userEnv: string[];
maskUserEnv?: boolean;
dataPersistence: boolean;
threadResumable: boolean;
chatProfiles: ChatProfile[];
Expand Down
Loading