Spaces:
Running on Zero
Running on Zero
Update report_generator.py
Browse files- report_generator.py +27 -14
report_generator.py
CHANGED
|
@@ -10,6 +10,15 @@ except ImportError:
|
|
| 10 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 11 |
groq_client = Groq(api_key=GROQ_API_KEY) if (HAS_GROQ and GROQ_API_KEY) else None
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
def generate_fallback_markdown(diagnostic_data: dict) -> str:
|
| 14 |
summary = diagnostic_data.get("executive_summary", {})
|
| 15 |
results = diagnostic_data.get("results", [])
|
|
@@ -80,17 +89,21 @@ def generate_ai_report(diagnostic_data: dict) -> str:
|
|
| 80 |
f"Failure Diagnostic JSON:\n{json.dumps(filtered_report)}"
|
| 81 |
)
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 11 |
groq_client = Groq(api_key=GROQ_API_KEY) if (HAS_GROQ and GROQ_API_KEY) else None
|
| 12 |
|
| 13 |
+
# Lista de modele cu fallback automat
|
| 14 |
+
GROQ_MODELS = [
|
| 15 |
+
"llama-3.3-70b-versatile",
|
| 16 |
+
"llama-3.1-8b-instant",
|
| 17 |
+
"llama3-8b-8192",
|
| 18 |
+
"gemma2-9b-it",
|
| 19 |
+
"mixtral-8x7b-32768"
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
def generate_fallback_markdown(diagnostic_data: dict) -> str:
|
| 23 |
summary = diagnostic_data.get("executive_summary", {})
|
| 24 |
results = diagnostic_data.get("results", [])
|
|
|
|
| 89 |
f"Failure Diagnostic JSON:\n{json.dumps(filtered_report)}"
|
| 90 |
)
|
| 91 |
|
| 92 |
+
# Incercam pe rand modelele din lista de fallback
|
| 93 |
+
for model_name in GROQ_MODELS:
|
| 94 |
+
try:
|
| 95 |
+
completion = groq_client.chat.completions.create(
|
| 96 |
+
model=model_name,
|
| 97 |
+
messages=[
|
| 98 |
+
{"role": "system", "content": "You are a precise LLMops assistant. Write concise diagnostic reports with git diff prompt patches."},
|
| 99 |
+
{"role": "user", "content": prompt}
|
| 100 |
+
],
|
| 101 |
+
temperature=0.1,
|
| 102 |
+
max_tokens=400
|
| 103 |
+
)
|
| 104 |
+
return completion.choices[0].message.content
|
| 105 |
+
except Exception:
|
| 106 |
+
continue
|
| 107 |
+
|
| 108 |
+
# Daca toate modelele Groq sunt indisponibile, apelam fallback-ul local
|
| 109 |
+
return generate_fallback_markdown(diagnostic_data)
|