Spaces:
Running
Running
Update src/services/ai_modal_engine.py
Browse files
src/services/ai_modal_engine.py
CHANGED
|
@@ -14,7 +14,7 @@ class AiModalEngine:
|
|
| 14 |
|
| 15 |
client = genai.Client(api_key=api_key)
|
| 16 |
|
| 17 |
-
#
|
| 18 |
instruction = f"""
|
| 19 |
PARSONA:
|
| 20 |
You are the QuantVAT AI Trading Journal Auditor, a senior Risk Manager and Trading Psychologist with 50 years trading experience like a Market Wizard.
|
|
@@ -34,12 +34,18 @@ class AiModalEngine:
|
|
| 34 |
{context}
|
| 35 |
"""
|
| 36 |
|
| 37 |
-
# Switched to Flash-Preview for quota safety & token efficiency
|
| 38 |
response = client.models.generate_content(
|
| 39 |
model='gemini-3-flash-preview',
|
| 40 |
contents=f"Analyze this Ledger: {context}",
|
| 41 |
config=types.GenerateContentConfig(system_instruction=instruction)
|
| 42 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
return response.text
|
| 44 |
|
| 45 |
except Exception as e:
|
|
@@ -56,7 +62,7 @@ class AiModalEngine:
|
|
| 56 |
api_key = get_user_keys(uid).get('gemini_key')
|
| 57 |
client = genai.Client(api_key=api_key)
|
| 58 |
|
| 59 |
-
# Use Flash for continuous chat
|
| 60 |
chat = client.chats.create(
|
| 61 |
model='gemini-3-flash-preview',
|
| 62 |
history=history,
|
|
@@ -67,7 +73,7 @@ class AiModalEngine:
|
|
| 67 |
|
| 68 |
response = chat.send_message(prompt)
|
| 69 |
|
| 70 |
-
# Sync back to Firestore
|
| 71 |
history.append({"role": "user", "parts": [{"text": prompt}]})
|
| 72 |
history.append({"role": "model", "parts": [{"text": response.text}]})
|
| 73 |
db.collection('users').document(uid).set({"ai_history": history}, merge=True)
|
|
|
|
| 14 |
|
| 15 |
client = genai.Client(api_key=api_key)
|
| 16 |
|
| 17 |
+
# PARSONA
|
| 18 |
instruction = f"""
|
| 19 |
PARSONA:
|
| 20 |
You are the QuantVAT AI Trading Journal Auditor, a senior Risk Manager and Trading Psychologist with 50 years trading experience like a Market Wizard.
|
|
|
|
| 34 |
{context}
|
| 35 |
"""
|
| 36 |
|
|
|
|
| 37 |
response = client.models.generate_content(
|
| 38 |
model='gemini-3-flash-preview',
|
| 39 |
contents=f"Analyze this Ledger: {context}",
|
| 40 |
config=types.GenerateContentConfig(system_instruction=instruction)
|
| 41 |
)
|
| 42 |
+
|
| 43 |
+
history = [
|
| 44 |
+
{"role": "user", "parts": [{"text": f"Analyze this Ledger: {context}"}]},
|
| 45 |
+
{"role": "model", "parts": [{"text": response.text}]}
|
| 46 |
+
]
|
| 47 |
+
db.collection('users').document(uid).set({"ai_history": history}, merge=True)
|
| 48 |
+
|
| 49 |
return response.text
|
| 50 |
|
| 51 |
except Exception as e:
|
|
|
|
| 62 |
api_key = get_user_keys(uid).get('gemini_key')
|
| 63 |
client = genai.Client(api_key=api_key)
|
| 64 |
|
| 65 |
+
# Use Flash for continuous chat
|
| 66 |
chat = client.chats.create(
|
| 67 |
model='gemini-3-flash-preview',
|
| 68 |
history=history,
|
|
|
|
| 73 |
|
| 74 |
response = chat.send_message(prompt)
|
| 75 |
|
| 76 |
+
# Sync back to Firestore
|
| 77 |
history.append({"role": "user", "parts": [{"text": prompt}]})
|
| 78 |
history.append({"role": "model", "parts": [{"text": response.text}]})
|
| 79 |
db.collection('users').document(uid).set({"ai_history": history}, merge=True)
|