Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# --- START OF
|
| 2 |
|
| 3 |
import os
|
| 4 |
import json
|
|
@@ -120,8 +120,16 @@ def perform_web_search_with_gemini(query, client, model_id):
|
|
| 120 |
"""Effectue une recherche web via l'API Google Search intégrée à Gemini."""
|
| 121 |
try:
|
| 122 |
print(f"--- LOG WEBSEARCH: Recherche Google avec Gemini pour: '{query}'")
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
print("--- LOG WEBSEARCH: Résultats de recherche Google obtenus.")
|
| 127 |
|
|
@@ -375,24 +383,22 @@ def chat_api():
|
|
| 375 |
|
| 376 |
print(f" Message {i} (role: {role}): {', '.join(parts_info)}")
|
| 377 |
|
| 378 |
-
# Configuration de
|
| 379 |
-
|
| 380 |
-
system_instruction
|
| 381 |
-
safety_settings
|
| 382 |
-
|
| 383 |
-
|
|
|
|
| 384 |
if use_web_search:
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
|
| 390 |
# Appel à l'API avec le nouveau SDK
|
| 391 |
print(f"--- LOG [/api/chat]: Envoi de la requête à {selected_model_name}...")
|
| 392 |
response = genai_client.models.generate_content(
|
| 393 |
model=selected_model_name,
|
| 394 |
contents=contents,
|
| 395 |
-
|
| 396 |
)
|
| 397 |
|
| 398 |
# --- Traitement de la réponse (avec logs) ---
|
|
|
|
| 1 |
+
# --- START OF FILE app.py ---
|
| 2 |
|
| 3 |
import os
|
| 4 |
import json
|
|
|
|
| 120 |
"""Effectue une recherche web via l'API Google Search intégrée à Gemini."""
|
| 121 |
try:
|
| 122 |
print(f"--- LOG WEBSEARCH: Recherche Google avec Gemini pour: '{query}'")
|
| 123 |
+
|
| 124 |
+
# Utiliser l'outil de recherche Google intégré à Gemini
|
| 125 |
+
# Création de la configuration pour la recherche web
|
| 126 |
+
config = {"tools": [{"google_search": {}}]}
|
| 127 |
+
|
| 128 |
+
response = client.models.generate_content(
|
| 129 |
+
model=model_id,
|
| 130 |
+
contents=[{"role": "user", "parts": [{"text": query}]}],
|
| 131 |
+
generation_config=config
|
| 132 |
+
)
|
| 133 |
|
| 134 |
print("--- LOG WEBSEARCH: Résultats de recherche Google obtenus.")
|
| 135 |
|
|
|
|
| 383 |
|
| 384 |
print(f" Message {i} (role: {role}): {', '.join(parts_info)}")
|
| 385 |
|
| 386 |
+
# Configuration de base
|
| 387 |
+
generation_config = {
|
| 388 |
+
"system_instruction": SYSTEM_INSTRUCTION,
|
| 389 |
+
"safety_settings": SAFETY_SETTINGS
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
# Ajout de la configuration de recherche web si nécessaire
|
| 393 |
if use_web_search:
|
| 394 |
+
generation_config["tools"] = [{"google_search": {}}]
|
|
|
|
|
|
|
|
|
|
| 395 |
|
| 396 |
# Appel à l'API avec le nouveau SDK
|
| 397 |
print(f"--- LOG [/api/chat]: Envoi de la requête à {selected_model_name}...")
|
| 398 |
response = genai_client.models.generate_content(
|
| 399 |
model=selected_model_name,
|
| 400 |
contents=contents,
|
| 401 |
+
generation_config=generation_config
|
| 402 |
)
|
| 403 |
|
| 404 |
# --- Traitement de la réponse (avec logs) ---
|