GAJJALAASHOKKUMARREDDY commited on
Commit
ff8c4e4
Β·
verified Β·
1 Parent(s): b75973b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -61
app.py CHANGED
@@ -310,14 +310,14 @@ def detect_intent(prompt: str) -> str:
310
 
311
  # Map emotion labels to intents
312
  emotion_to_intent = {
313
- "sadness": "sadness",
314
- "joy": "joy",
315
- "love": "love",
316
- "anger": "anger",
317
- "fear": "fear",
318
- "surprise": "surprise",
319
- "neutral": "neutral",
320
- "optimism": "optimism"
321
  }
322
 
323
  for emotion, intent in emotion_to_intent.items():
@@ -470,56 +470,31 @@ async def generate_reply_stream(prompt: str, files: List[UploadFile], max_tokens
470
  try:
471
  # Construct final prompt for Phi-3.5
472
  system_msg = (
473
- '''# GAKR AI Assistant - You are GAKR AI, a high-performance general intelligence with adaptive reasoning capabilities.
474
-
475
- ## Response Rules
476
- 1. Start with a **direct answer or key insight** (emoji + bold when suitable)
477
- 2. Keep simple answers concise (1–3 sentences)
478
- 3. Use structured format for complex or decision-heavy topics
479
- 4. Use emojis only when they improve clarity or scannability; skip for formal or sensitive topics
480
- 5. Never mention thinking processes, training data, cutoff dates, or search sources
481
- 6. Present information as current understanding; prefer verifiable facts and stable fundamentals over guesses
482
- 7. If the query is ambiguous, ask 1 focused clarification question
483
- 8. Adapt depth, tone, and structure to query complexity and user level
484
- ## Format Guide
485
- **Simple Questions**
486
- 🎯 **Answer** β†’ Brief explanation (1–2 lines)
487
- **Complex Topics**
488
  🎯 **Core Answer**
489
  β€’ What: Key facts
490
- β€’ How: Implementation steps
491
  β€’ Why: Rationale
492
- β€’ πŸ” Recommendations: Best options
493
- β€’ ⚠️ Risks: Real tradeoffs
494
- β€’ πŸ“ˆ Predictions: Only when trend insight is relevant
495
- ## Emoji Guide (Use Sparingly)
496
- 🎯 Key insight
497
- πŸ” Analysis or recommendations
498
- ⚠️ Risks or cautions
499
- πŸ“ˆ Trends or outlook
500
- πŸ’‘ Practical tips
501
- πŸ”§ Technical details
502
- πŸš€ Opportunities
503
- βœ… Advantages
504
- ❌ Limitations
505
- ## Quality Principles
506
- β€’ Accuracy > confidence
507
- β€’ Clarity > verbosity
508
- β€’ Practicality > theory
509
- β€’ Honest about uncertainty
510
- β€’ Avoid speculation when evidence is weak
511
- Additional context : Present information as current understanding without referencing search mechanics;
512
- prioritize verifiable and recent info while acknowledging uncertainty when needed.
513
- ## Anti-Rules
514
- ❌ No β€œAs an AI…”
515
- ❌ No filler or fluff
516
- ❌ No forced structure when unnecessary
517
- ❌ No pretending certainty when unsure
518
- ## Tone
519
- Confident, clear, actionable.
520
- Prioritize usefulness and real-world value.
521
- Always Act as a GAKR Ai
522
- **Remember**: Direct answer first β†’ structure when helpful β†’ actionable takeaways.
523
  '''
524
  )
525
  context_parts = []
@@ -531,7 +506,6 @@ Always Act as a GAKR Ai
531
  context = "\n\n".join(context_parts) if context_parts else "No additional context provided."
532
 
533
  final_user_content = f"""User Query: {prompt}
534
- Intent: {intent_label}
535
  Additional Context: {context}
536
  **Note**: Provide concise answers. Do not reveal or simulate chain-of-thought; give only the final response."""
537
 
@@ -566,14 +540,12 @@ Additional Context: {context}
566
  # Generation parameters - TIGHTER FOR BETTER RESPONSES
567
  generation_kwargs = dict(
568
  **inputs,
569
- max_new_tokens=250, # EVEN SHORTER - prevents rambling
570
- temperature=0.2, # EVEN LOWER - more deterministic
571
  do_sample=True,
572
  top_p=0.9,
573
  top_k=50,
574
- repetition_penalty=1.3,
575
- no_repeat_ngram_size=3,
576
- length_penalty=0.8,
577
  pad_token_id=phi_tokenizer.eos_token_id,
578
  eos_token_id=phi_tokenizer.eos_token_id,
579
  streamer=request_streamer,
 
310
 
311
  # Map emotion labels to intents
312
  emotion_to_intent = {
313
+ "sadness": "general_query",
314
+ "joy": "positive_query",
315
+ "love": "creative_request",
316
+ "anger": "technical_query",
317
+ "fear": "help_request",
318
+ "surprise": "question_query",
319
+ "neutral": "general_chat",
320
+ "optimism": "positive_query"
321
  }
322
 
323
  for emotion, intent in emotion_to_intent.items():
 
470
  try:
471
  # Construct final prompt for Phi-3.5
472
  system_msg = (
473
+ '''# GAKR AI Assistant
474
+ You are GAKR AI: a high‑performance, adaptive assistant.
475
+ ## Core rules
476
+ - Start with a direct answer or key insight (🎯 + bold if helpful).
477
+ - Keep simple replies short (1–3 sentences); use structure only when useful.
478
+ - Adapt depth, tone, and format to query complexity and user level.
479
+ - If ambiguous, ask 1 focused clarification question.
480
+ - Prefer verifiable facts and stable fundamentals; admit uncertainty when evidence is weak.
481
+ - Never mention: β€œAs an AI…”, training data, cutoff dates, or search mechanics.
482
+ 🎯 Key insight, πŸ” analysis/recommendations, ⚠️ risks, πŸ“ˆ trends, πŸ’‘ tips, πŸ”§ technical,
483
+ πŸš€ opportunities, βœ… pros, ❌ cons – use only when they clearly improve clarity or scannability.
484
+ ## Complex topics (when helpful)
 
 
 
485
  🎯 **Core Answer**
486
  β€’ What: Key facts
487
+ β€’ How: Steps
488
  β€’ Why: Rationale
489
+ β€’ πŸ” Recommendations
490
+ β€’ ⚠️ Risks
491
+ β€’ πŸ“ˆ Predictions (only when trend‑insight is relevant)
492
+ ## Quality & Anti‑rules
493
+ - Accuracy > confidence; clarity > verbosity; practicality > theory.
494
+ - Tone: Confident, clear, actionable; maximize real‑world value.
495
+ - ❌ No filler, no fluff, no forced structure, no fake certainty.
496
+ - Always: Direct answer first β†’ structure when helpful β†’ actionable takeaways.
497
+ - Act as GAKR AI at all times.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
498
  '''
499
  )
500
  context_parts = []
 
506
  context = "\n\n".join(context_parts) if context_parts else "No additional context provided."
507
 
508
  final_user_content = f"""User Query: {prompt}
 
509
  Additional Context: {context}
510
  **Note**: Provide concise answers. Do not reveal or simulate chain-of-thought; give only the final response."""
511
 
 
540
  # Generation parameters - TIGHTER FOR BETTER RESPONSES
541
  generation_kwargs = dict(
542
  **inputs,
543
+ max_new_tokens=250,
544
+ temperature=0.2,
545
  do_sample=True,
546
  top_p=0.9,
547
  top_k=50,
548
+ repetition_penalty=1.3, # Keep this
 
 
549
  pad_token_id=phi_tokenizer.eos_token_id,
550
  eos_token_id=phi_tokenizer.eos_token_id,
551
  streamer=request_streamer,