Tsitsi19 commited on
Commit
9796654
·
verified ·
1 Parent(s): 6589af6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request
2
+ from huggingface_hub import InferenceClient
3
+ import os
4
+ import json
5
+
6
+ app = FastAPI()
7
+
8
+ # Utilisation du moteur Llama-3 (Puissant et sans quotas de merde)
9
+ client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
10
+
11
+ SYSTEM_PROMPT = """Tu es le CERVEAU DU MONSTRE-LAB.
12
+ Ta mission : Interpréter les ordres et générer du code Python pour mes 5 membres :
13
+ 1. SUPABASE (Données)
14
+ 2. RCLONE (Cloud/Fichiers)
15
+ 3. BOT TELEGRAM (Alertes)
16
+ 4. CHANNEL TELEGRAM (Public)
17
+ 5. GITHUB (Exécution)
18
+
19
+ Tu dois répondre UNIQUEMENT au format JSON strict :
20
+ {
21
+ "action": "nom_action",
22
+ "membre": "membre_concerne",
23
+ "fichier": "nom_du_script.py",
24
+ "code": "code_python_complet",
25
+ "statut": "pret"
26
+ }"""
27
+
28
+ @app.post("/ordre")
29
+ async def monstre_process(request: Request):
30
+ data = await request.json()
31
+ message = data.get("message", "")
32
+
33
+ # L'IA génère la réponse
34
+ response_text = ""
35
+ for msg in client.chat_completion(
36
+ messages=[
37
+ {"role": "system", "content": SYSTEM_PROMPT},
38
+ {"role": "user", "content": message},
39
+ ],
40
+ max_tokens=3000,
41
+ temperature=0.1
42
+ ):
43
+ response_text += msg.choices[0].delta.content or ""
44
+
45
+ # Nettoyage pour garantir le JSON
46
+ try:
47
+ start = response_text.find("{")
48
+ end = response_text.rfind("}") + 1
49
+ return json.loads(response_text[start:end])
50
+ except:
51
+ return {"error": "Format JSON corrompu", "brut": response_text}
52
+
53
+ @app.get("/")
54
+ def home():
55
+ return {"message": "Le Cerveau du Monstre est en ligne"}