Spaces:
Running

axeronis commited on
Commit
5bb4c25
·
1 Parent(s): ed7ed5e

fix: simplify demo-chat UI, remove emojis, smart instruction replacement

Browse files
backend/app/api/demo.py CHANGED
@@ -311,17 +311,46 @@ async def confirm_smart_correction(
311
  applied_count += 1
312
  elif "Инструкции" in field or "инструкц" in field.lower():
313
  if "..." in new_value:
314
- # It's truncated, need full value - use from change
315
  full_value = change.get("full_value", new_value.replace("...", ""))
316
  else:
317
  full_value = new_value
318
 
319
- current = ai_settings.get("custom_instructions", "")
320
- if current:
321
- ai_settings["custom_instructions"] = current + "\n\n" + full_value
322
- else:
323
- ai_settings["custom_instructions"] = full_value
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
324
  applied_count += 1
 
325
  elif "Идеальный клиент" in field or "клиент" in field.lower():
326
  full_value = change.get("full_value", new_value.replace("...", ""))
327
  ai_settings["ideal_customer_profile"] = full_value
@@ -621,7 +650,8 @@ async def smart_correct(
621
  for c in applied_changes:
622
  changes_lines.append(f"• {c['field']} ({c['section']}): {c['old']} → {c['new']}")
623
 
624
- message = f"⚠️ Подтвердите изменения:\n" + "\n".join(changes_lines)
 
625
 
626
  logger.info(f"🔧 Smart correction PENDING for tenant {tenant.id}: {len(applied_changes)} changes")
627
 
 
311
  applied_count += 1
312
  elif "Инструкции" in field or "инструкц" in field.lower():
313
  if "..." in new_value:
 
314
  full_value = change.get("full_value", new_value.replace("...", ""))
315
  else:
316
  full_value = new_value
317
 
318
+ current = ai_settings.get("custom_instructions", "") or ""
319
+
320
+ # Smart instruction handling: detect and replace contradictions
321
+ # Common contradicting patterns
322
+ contradictions = [
323
+ (["на вы", "на «вы»", "обращайся на вы"], ["на ты", "на «ты»", "обращайся на ты"]),
324
+ (["мужского рода", "мужской род"], ["женского рода", "женский род"]),
325
+ (["формальн", "официальн"], ["неформальн", "разговорн"]),
326
+ ]
327
+
328
+ # Check if new instruction contradicts any existing ones
329
+ lines = current.split("\n") if current else []
330
+ new_lower = full_value.lower()
331
+
332
+ # Find which pattern group the new instruction belongs to
333
+ for group_a, group_b in contradictions:
334
+ in_a = any(p in new_lower for p in group_a)
335
+ in_b = any(p in new_lower for p in group_b)
336
+
337
+ if in_a or in_b:
338
+ # Remove any existing contradicting instructions
339
+ opposite = group_b if in_a else group_a
340
+ lines = [line for line in lines
341
+ if not any(p in line.lower() for p in opposite + (group_a if in_a else group_b))]
342
+
343
+ # Add new instruction (avoiding duplicates)
344
+ if full_value.strip() not in "\n".join(lines):
345
+ lines.append(full_value.strip())
346
+
347
+ # Limit total instructions to prevent bloat (max 10 lines)
348
+ if len(lines) > 10:
349
+ lines = lines[-10:]
350
+
351
+ ai_settings["custom_instructions"] = "\n".join(filter(None, lines))
352
  applied_count += 1
353
+
354
  elif "Идеальный клиент" in field or "клиент" in field.lower():
355
  full_value = change.get("full_value", new_value.replace("...", ""))
356
  ai_settings["ideal_customer_profile"] = full_value
 
650
  for c in applied_changes:
651
  changes_lines.append(f"• {c['field']} ({c['section']}): {c['old']} → {c['new']}")
652
 
653
+ message = f"Подтвердите изменения:\n" + "\n".join(changes_lines)
654
+
655
 
656
  logger.info(f"🔧 Smart correction PENDING for tenant {tenant.id}: {len(applied_changes)} changes")
657
 
frontend/app/demo-chat/page.tsx CHANGED
@@ -142,7 +142,7 @@ export default function DemoChatPage() {
142
  })
143
 
144
  if (response.data.success) {
145
- toast.success(`✅ ${response.data.message}`)
146
  // Invalidate ALL queries that start with these keys (including ['ai-settings', tenant_id])
147
  queryClient.invalidateQueries({
148
  predicate: (query) => {
@@ -155,7 +155,7 @@ export default function DemoChatPage() {
155
  setMessages(prev => [...prev, {
156
  id: crypto.randomUUID(),
157
  role: 'system',
158
- content: `✅ Правки применены!`,
159
  timestamp: new Date()
160
  }])
161
  } else {
@@ -184,7 +184,7 @@ export default function DemoChatPage() {
184
  setMessages(prev => [...prev, {
185
  id: crypto.randomUUID(),
186
  role: 'user',
187
- content: `🪄 Правка: "${correction}"`,
188
  timestamp: new Date()
189
  }])
190
 
@@ -204,7 +204,7 @@ export default function DemoChatPage() {
204
  setMessages(prev => [...prev, {
205
  id: crypto.randomUUID(),
206
  role: 'system',
207
- content: `📝 Правка учтена: "${correction}"`,
208
  timestamp: new Date()
209
  }])
210
  }
@@ -213,7 +213,7 @@ export default function DemoChatPage() {
213
  setMessages(prev => [...prev, {
214
  id: crypto.randomUUID(),
215
  role: 'system',
216
- content: `📝 Правка применена локально: "${correction}"`,
217
  timestamp: new Date()
218
  }])
219
 
@@ -308,20 +308,20 @@ export default function DemoChatPage() {
308
  }
309
 
310
  return (
311
- <div className="flex flex-col h-full bg-[#050510] relative overflow-hidden">
312
- {/* Aurora Background */}
313
- <div className="absolute inset-0 pointer-events-none overflow-hidden">
314
- <div className="absolute top-1/4 left-1/4 w-96 h-96 bg-violet-600/10 rounded-full blur-3xl animate-pulse" />
315
- <div className="absolute bottom-1/3 right-1/4 w-80 h-80 bg-purple-600/10 rounded-full blur-3xl animate-pulse" style={{ animationDelay: '1s' }} />
316
- <div className="absolute top-2/3 left-1/2 w-64 h-64 bg-indigo-600/10 rounded-full blur-3xl animate-pulse" style={{ animationDelay: '2s' }} />
317
  </div>
318
 
319
  {/* Header */}
320
- <header className="relative z-10 flex-shrink-0 flex items-center justify-between px-4 py-3 border-b border-white/5 bg-[#0a0a15]/60 backdrop-blur-xl safe-area-top">
321
  <div className="flex items-center gap-3">
322
- <Link href="/settings/brain" className="p-2 text-white/40 hover:text-white rounded-lg transition-colors">
 
323
  <ArrowLeft className="w-5 h-5" />
324
  </Link>
 
325
  <div className="w-10 h-10 rounded-xl bg-gradient-to-br from-violet-500 via-purple-600 to-indigo-600 flex items-center justify-center shadow-lg shadow-violet-500/20">
326
  <Bot className="w-5 h-5 text-white" />
327
  </div>
@@ -387,8 +387,7 @@ export default function DemoChatPage() {
387
  onClick={() => setInput('Привет!')}
388
  className="group p-4 bg-white/[0.03] hover:bg-white/[0.06] border border-white/10 hover:border-violet-500/30 rounded-2xl text-sm text-white/80 text-left transition-all duration-200 flex items-center gap-3"
389
  >
390
- <span className="text-xl">💬</span>
391
- <span className="group-hover:text-white transition-colors">"Привет!"</span>
392
  </motion.button>
393
  <motion.button
394
  whileHover={{ scale: 1.02 }}
@@ -396,8 +395,7 @@ export default function DemoChatPage() {
396
  onClick={() => setInput('Сколько стоит?')}
397
  className="group p-4 bg-white/[0.03] hover:bg-white/[0.06] border border-white/10 hover:border-violet-500/30 rounded-2xl text-sm text-white/80 text-left transition-all duration-200 flex items-center gap-3"
398
  >
399
- <span className="text-xl">💰</span>
400
- <span className="group-hover:text-white transition-colors">"Сколько стоит?"</span>
401
  </motion.button>
402
  <motion.button
403
  whileHover={{ scale: 1.02 }}
@@ -405,8 +403,7 @@ export default function DemoChatPage() {
405
  onClick={() => setInput('Хочу записаться')}
406
  className="group p-4 bg-white/[0.03] hover:bg-white/[0.06] border border-white/10 hover:border-violet-500/30 rounded-2xl text-sm text-white/80 text-left transition-all duration-200 flex items-center gap-3"
407
  >
408
- <span className="text-xl">📅</span>
409
- <span className="group-hover:text-white transition-colors">"Хочу записаться"</span>
410
  </motion.button>
411
  </div>
412
  </motion.div>
@@ -630,7 +627,8 @@ export default function DemoChatPage() {
630
  animate={{ opacity: 1, y: 0 }}
631
  className="text-center text-xs text-violet-400/80 mt-2"
632
  >
633
- 🪄 Опишите проблему: "не говори бот", "ты Анна", "общайся на Вы"
 
634
  </motion.p>
635
  )}
636
  </div>
 
142
  })
143
 
144
  if (response.data.success) {
145
+ toast.success(response.data.message)
146
  // Invalidate ALL queries that start with these keys (including ['ai-settings', tenant_id])
147
  queryClient.invalidateQueries({
148
  predicate: (query) => {
 
155
  setMessages(prev => [...prev, {
156
  id: crypto.randomUUID(),
157
  role: 'system',
158
+ content: `Правки применены`,
159
  timestamp: new Date()
160
  }])
161
  } else {
 
184
  setMessages(prev => [...prev, {
185
  id: crypto.randomUUID(),
186
  role: 'user',
187
+ content: `Правка: "${correction}"`,
188
  timestamp: new Date()
189
  }])
190
 
 
204
  setMessages(prev => [...prev, {
205
  id: crypto.randomUUID(),
206
  role: 'system',
207
+ content: `Правка учтена: "${correction}"`,
208
  timestamp: new Date()
209
  }])
210
  }
 
213
  setMessages(prev => [...prev, {
214
  id: crypto.randomUUID(),
215
  role: 'system',
216
+ content: `Правка применена локально: "${correction}"`,
217
  timestamp: new Date()
218
  }])
219
 
 
308
  }
309
 
310
  return (
311
+ <div className="flex flex-col h-full bg-gradient-to-b from-[#0a0a12] to-[#050508] relative">
312
+ {/* Subtle background gradient */}
313
+ <div className="absolute inset-0 pointer-events-none">
314
+ <div className="absolute top-0 left-1/2 -translate-x-1/2 w-[600px] h-[300px] bg-violet-600/5 rounded-full blur-3xl" />
 
 
315
  </div>
316
 
317
  {/* Header */}
318
+ <header className="relative z-10 flex-shrink-0 flex items-center justify-between px-4 py-3 border-b border-white/5 bg-[#0a0a15]/80 backdrop-blur-sm safe-area-top">
319
  <div className="flex items-center gap-3">
320
+ {/* Back arrow - only show on mobile when sidebar is hidden */}
321
+ <Link href="/settings/brain" className="lg:hidden p-2 text-white/40 hover:text-white rounded-lg transition-colors">
322
  <ArrowLeft className="w-5 h-5" />
323
  </Link>
324
+
325
  <div className="w-10 h-10 rounded-xl bg-gradient-to-br from-violet-500 via-purple-600 to-indigo-600 flex items-center justify-center shadow-lg shadow-violet-500/20">
326
  <Bot className="w-5 h-5 text-white" />
327
  </div>
 
387
  onClick={() => setInput('Привет!')}
388
  className="group p-4 bg-white/[0.03] hover:bg-white/[0.06] border border-white/10 hover:border-violet-500/30 rounded-2xl text-sm text-white/80 text-left transition-all duration-200 flex items-center gap-3"
389
  >
390
+ <span className="group-hover:text-white transition-colors">«Привет!»</span>
 
391
  </motion.button>
392
  <motion.button
393
  whileHover={{ scale: 1.02 }}
 
395
  onClick={() => setInput('Сколько стоит?')}
396
  className="group p-4 bg-white/[0.03] hover:bg-white/[0.06] border border-white/10 hover:border-violet-500/30 rounded-2xl text-sm text-white/80 text-left transition-all duration-200 flex items-center gap-3"
397
  >
398
+ <span className="group-hover:text-white transition-colors">«Сколько стоит?»</span>
 
399
  </motion.button>
400
  <motion.button
401
  whileHover={{ scale: 1.02 }}
 
403
  onClick={() => setInput('Хочу записаться')}
404
  className="group p-4 bg-white/[0.03] hover:bg-white/[0.06] border border-white/10 hover:border-violet-500/30 rounded-2xl text-sm text-white/80 text-left transition-all duration-200 flex items-center gap-3"
405
  >
406
+ <span className="group-hover:text-white transition-colors">«Хочу записаться»</span>
 
407
  </motion.button>
408
  </div>
409
  </motion.div>
 
627
  animate={{ opacity: 1, y: 0 }}
628
  className="text-center text-xs text-violet-400/80 mt-2"
629
  >
630
+ Опишите проблему: «не говори бот», «ты Анна», «общайся на Вы»
631
+
632
  </motion.p>
633
  )}
634
  </div>