AumCoreAI commited on
Commit
1156b22
·
verified ·
1 Parent(s): 57c3ca4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -13
app.py CHANGED
@@ -1,4 +1,4 @@
1
- # app.py - Fixed with proper imports and structure
2
  import os
3
  import uvicorn
4
  import json
@@ -10,7 +10,7 @@ from groq import Groq
10
  app = FastAPI()
11
  client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
12
 
13
- # Configuration
14
  USERNAME = "Sanjay"
15
  MEMORY_FILE = "memory.json"
16
 
@@ -31,16 +31,7 @@ def save_memory(chat_history):
31
  except Exception as e:
32
  print(f"Memory Save Error: {e}")
33
 
34
- SYSTEM_PROMPT = f"""
35
- Role: Senior AI Architect (AumCore AI).
36
- User Identity: {USERNAME}.
37
- Core Rules:
38
- 1. Language: Always 60% English and 40% Hindi (Devanagari).
39
- 2. Code Rule: If {USERNAME} asks for code, provide a robust production-ready Python script with try-except blocks.
40
- 3. Length: Responses must be powerful and direct (Max 4 lines).
41
- 4. Persona: Talk like a Master AI, not a basic chatbot.
42
- """
43
-
44
  HTML_UI = '''
45
  <!DOCTYPE html>
46
  <html lang="en">
@@ -135,10 +126,15 @@ async def reset():
135
 
136
  @app.post("/chat")
137
  async def chat(message: str = Form(...)):
 
 
 
 
 
138
  memory_data = load_memory()
139
  history = memory_data.get("history", [])[-10:]
140
 
141
- api_messages = [{"role": "system", "content": SYSTEM_PROMPT}]
142
  for chat_pair in history:
143
  api_messages.append({"role": "user", "content": chat_pair["u"]})
144
  api_messages.append({"role": "assistant", "content": chat_pair["a"]})
 
1
+ # app.py - FINAL VERSION WITH LANGUAGE DETECTION
2
  import os
3
  import uvicorn
4
  import json
 
10
  app = FastAPI()
11
  client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
12
 
13
+ # Configuration & Persistent Memory Setup
14
  USERNAME = "Sanjay"
15
  MEMORY_FILE = "memory.json"
16
 
 
31
  except Exception as e:
32
  print(f"Memory Save Error: {e}")
33
 
34
+ # UI REMAINS EXACTLY SAME
 
 
 
 
 
 
 
 
 
35
  HTML_UI = '''
36
  <!DOCTYPE html>
37
  <html lang="en">
 
126
 
127
  @app.post("/chat")
128
  async def chat(message: str = Form(...)):
129
+ # ✅ LANGUAGE DETECTION
130
+ from language_detector import detect_input_language, get_system_prompt
131
+ lang_mode = detect_input_language(message)
132
+ system_prompt = get_system_prompt(lang_mode, USERNAME)
133
+
134
  memory_data = load_memory()
135
  history = memory_data.get("history", [])[-10:]
136
 
137
+ api_messages = [{"role": "system", "content": system_prompt}]
138
  for chat_pair in history:
139
  api_messages.append({"role": "user", "content": chat_pair["u"]})
140
  api_messages.append({"role": "assistant", "content": chat_pair["a"]})