fix
This commit is contained in:
@@ -56,6 +56,10 @@ DEFAULT_SETTINGS: dict[str, dict[str, Any]] = {
|
||||
"ui.logo_url": {"value": "/icon.png", "description": "Logo URL"},
|
||||
"ui.og_image_url": {"value": "", "description": "OpenGraph image URL"},
|
||||
"admin.setup_token": {"value": "", "description": "Admin setup token"},
|
||||
"llm.text_replacements": {
|
||||
"value": [],
|
||||
"description": "List of {from, to} pairs. Each 'from' substring in LLM scene_text output is replaced with 'to' (can be empty string to remove).",
|
||||
},
|
||||
}
|
||||
|
||||
# Keys whose values should never be returned to the client in plaintext.
|
||||
@@ -185,3 +189,24 @@ async def get_admin_setup_token(session: AsyncSession) -> str:
|
||||
token = secrets.token_urlsafe(16)
|
||||
await set_setting(session, "admin.setup_token", token)
|
||||
return token
|
||||
|
||||
|
||||
async def apply_text_replacements(session: AsyncSession, text: str) -> str:
|
||||
"""Apply llm.text_replacements to a text string.
|
||||
|
||||
Each replacement is a dict {from: str, to: str}. The 'from' substring is
|
||||
replaced with 'to' (which can be empty to remove the substring).
|
||||
"""
|
||||
if not text:
|
||||
return text
|
||||
replacements = await get_setting(session, "llm.text_replacements")
|
||||
if not replacements or not isinstance(replacements, list):
|
||||
return text
|
||||
for r in replacements:
|
||||
if not isinstance(r, dict):
|
||||
continue
|
||||
frm = r.get("from")
|
||||
to = r.get("to", "")
|
||||
if frm and isinstance(frm, str):
|
||||
text = text.replace(frm, to)
|
||||
return text
|
||||
|
||||
Reference in New Issue
Block a user