joj
Browse files- app.py +18 -9
- instructions/system_instruction.md +1 -0
app.py
CHANGED
|
@@ -13,9 +13,21 @@ app = Flask(__name__)
|
|
| 13 |
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB max file size
|
| 14 |
load_dotenv()
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
# Configuration du client Gemini
|
| 17 |
API_KEY = os.getenv("GOOGLE_API_KEY")
|
| 18 |
-
SYSTEM_INSTRUCTION =
|
| 19 |
|
| 20 |
client = genai.Client(api_key=API_KEY)
|
| 21 |
|
|
@@ -154,12 +166,10 @@ def chat():
|
|
| 154 |
for chunk in response_stream:
|
| 155 |
for part in chunk.candidates[0].content.parts:
|
| 156 |
if part.text:
|
|
|
|
|
|
|
| 157 |
if part.thought and thinking_enabled:
|
| 158 |
thoughts += part.text
|
| 159 |
-
yield f"data: {json.dumps({'type': 'thought', 'content': part.text})}\n\n"
|
| 160 |
-
else:
|
| 161 |
-
full_response += part.text
|
| 162 |
-
yield f"data: {json.dumps({'type': 'text', 'content': part.text})}\n\n"
|
| 163 |
|
| 164 |
# Ajouter la réponse de l'assistant à l'historique
|
| 165 |
if full_response:
|
|
@@ -263,11 +273,10 @@ def chat_with_file():
|
|
| 263 |
for chunk in response_stream:
|
| 264 |
for part in chunk.candidates[0].content.parts:
|
| 265 |
if part.text:
|
|
|
|
|
|
|
| 266 |
if part.thought and thinking_enabled:
|
| 267 |
-
|
| 268 |
-
else:
|
| 269 |
-
full_response += part.text
|
| 270 |
-
yield f"data: {json.dumps({'type': 'text', 'content': part.text})}\n\n"
|
| 271 |
|
| 272 |
# Ajouter la réponse de l'assistant à l'historique
|
| 273 |
if full_response:
|
|
|
|
| 13 |
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB max file size
|
| 14 |
load_dotenv()
|
| 15 |
|
| 16 |
+
def load_system_instruction():
|
| 17 |
+
"""Charge les instructions système depuis le fichier Markdown"""
|
| 18 |
+
try:
|
| 19 |
+
with open('instructions/system_instruction.md', 'r', encoding='utf-8') as f:
|
| 20 |
+
return f.read().strip()
|
| 21 |
+
except FileNotFoundError:
|
| 22 |
+
print("Erreur: Fichier d'instructions système non trouvé.")
|
| 23 |
+
return "Tu es un assistant intelligent et amical nommé Mariam. Tu assistes les utilisateurs au mieux de tes capacités. Tu as été créé par Aenir."
|
| 24 |
+
except Exception as e:
|
| 25 |
+
print(f"Erreur lors du chargement des instructions système: {e}")
|
| 26 |
+
return "Tu es un assistant intelligent et amical nommé Mariam. Tu assistes les utilisateurs au mieux de tes capacités. Tu as été créé par Aenir."
|
| 27 |
+
|
| 28 |
# Configuration du client Gemini
|
| 29 |
API_KEY = os.getenv("GOOGLE_API_KEY")
|
| 30 |
+
SYSTEM_INSTRUCTION = load_system_instruction()
|
| 31 |
|
| 32 |
client = genai.Client(api_key=API_KEY)
|
| 33 |
|
|
|
|
| 166 |
for chunk in response_stream:
|
| 167 |
for part in chunk.candidates[0].content.parts:
|
| 168 |
if part.text:
|
| 169 |
+
full_response += part.text
|
| 170 |
+
yield f"data: {json.dumps({'type': 'text', 'content': part.text})}\n\n"
|
| 171 |
if part.thought and thinking_enabled:
|
| 172 |
thoughts += part.text
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
# Ajouter la réponse de l'assistant à l'historique
|
| 175 |
if full_response:
|
|
|
|
| 273 |
for chunk in response_stream:
|
| 274 |
for part in chunk.candidates[0].content.parts:
|
| 275 |
if part.text:
|
| 276 |
+
full_response += part.text
|
| 277 |
+
yield f"data: {json.dumps({'type': 'text', 'content': part.text})}\n\n"
|
| 278 |
if part.thought and thinking_enabled:
|
| 279 |
+
thoughts += part.text
|
|
|
|
|
|
|
|
|
|
| 280 |
|
| 281 |
# Ajouter la réponse de l'assistant à l'historique
|
| 282 |
if full_response:
|
instructions/system_instruction.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Tu es un assistant intelligent et amical nommé Mariam. Tu assistes les utilisateurs au mieux de tes capacités. Tu as été créé par Aenir.
|