Spaces:
Running
Running
axeronis commited on
Commit ·
4a399cd
1
Parent(s): af5f15a
fix: settings/brain now saves to tenant fields and invalidates AI cache for immediate effect
Browse files- backend/app/api/tenants.py +14 -16
backend/app/api/tenants.py
CHANGED
|
@@ -217,25 +217,19 @@ async def update_my_tenant(
|
|
| 217 |
if request.business_type is not None:
|
| 218 |
tenant.business_type = request.business_type
|
| 219 |
|
|
|
|
|
|
|
| 220 |
if request.tone_of_voice is not None:
|
| 221 |
-
|
| 222 |
-
current_settings["tone_of_voice"] = request.tone_of_voice
|
| 223 |
-
tenant.ai_settings = current_settings
|
| 224 |
|
| 225 |
if request.sales_methodology is not None:
|
| 226 |
-
|
| 227 |
-
current_settings["sales_methodology"] = request.sales_methodology
|
| 228 |
-
tenant.ai_settings = current_settings
|
| 229 |
|
| 230 |
if request.custom_instructions is not None:
|
| 231 |
-
|
| 232 |
-
current_settings["custom_instructions"] = request.custom_instructions
|
| 233 |
-
tenant.ai_settings = current_settings
|
| 234 |
|
| 235 |
if request.banned_words is not None:
|
| 236 |
-
|
| 237 |
-
current_settings["banned_words"] = request.banned_words
|
| 238 |
-
tenant.ai_settings = current_settings
|
| 239 |
|
| 240 |
if request.booking_settings is not None:
|
| 241 |
old_settings = tenant.booking_settings or {}
|
|
@@ -321,6 +315,9 @@ async def update_my_tenant(
|
|
| 321 |
await session.commit()
|
| 322 |
await session.refresh(tenant)
|
| 323 |
|
|
|
|
|
|
|
|
|
|
| 324 |
return TenantResponse(
|
| 325 |
id=tenant.id,
|
| 326 |
name=tenant.name,
|
|
@@ -328,10 +325,11 @@ async def update_my_tenant(
|
|
| 328 |
business_type=tenant.business_type,
|
| 329 |
ai_settings=tenant.ai_settings,
|
| 330 |
ai_identity=(tenant.ai_settings or {}).get("ai_identity"),
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
|
|
|
| 335 |
booking_settings=tenant.booking_settings,
|
| 336 |
notification_settings=tenant.notification_settings,
|
| 337 |
tokens_balance=tenant.tokens_balance,
|
|
|
|
| 217 |
if request.business_type is not None:
|
| 218 |
tenant.business_type = request.business_type
|
| 219 |
|
| 220 |
+
# FIXED: Save persona fields to DIRECT tenant fields (not ai_settings JSON)
|
| 221 |
+
# This syncs behavior with PATCH /{tenant_id} endpoint and demo-chat
|
| 222 |
if request.tone_of_voice is not None:
|
| 223 |
+
tenant.tone_of_voice = request.tone_of_voice
|
|
|
|
|
|
|
| 224 |
|
| 225 |
if request.sales_methodology is not None:
|
| 226 |
+
tenant.sales_methodology = request.sales_methodology
|
|
|
|
|
|
|
| 227 |
|
| 228 |
if request.custom_instructions is not None:
|
| 229 |
+
tenant.custom_instructions = request.custom_instructions
|
|
|
|
|
|
|
| 230 |
|
| 231 |
if request.banned_words is not None:
|
| 232 |
+
tenant.banned_words = request.banned_words
|
|
|
|
|
|
|
| 233 |
|
| 234 |
if request.booking_settings is not None:
|
| 235 |
old_settings = tenant.booking_settings or {}
|
|
|
|
| 315 |
await session.commit()
|
| 316 |
await session.refresh(tenant)
|
| 317 |
|
| 318 |
+
# IMPORTANT: Invalidate AI Memory so new settings take effect immediately
|
| 319 |
+
await get_memory_manager().invalidate_memory(session, tenant)
|
| 320 |
+
|
| 321 |
return TenantResponse(
|
| 322 |
id=tenant.id,
|
| 323 |
name=tenant.name,
|
|
|
|
| 325 |
business_type=tenant.business_type,
|
| 326 |
ai_settings=tenant.ai_settings,
|
| 327 |
ai_identity=(tenant.ai_settings or {}).get("ai_identity"),
|
| 328 |
+
# FIXED: Read from tenant fields (source of truth), not ai_settings JSON
|
| 329 |
+
tone_of_voice=tenant.tone_of_voice,
|
| 330 |
+
sales_methodology=tenant.sales_methodology,
|
| 331 |
+
custom_instructions=tenant.custom_instructions,
|
| 332 |
+
banned_words=tenant.banned_words,
|
| 333 |
booking_settings=tenant.booking_settings,
|
| 334 |
notification_settings=tenant.notification_settings,
|
| 335 |
tokens_balance=tenant.tokens_balance,
|