Compare commits
1 commit
main
...
dev-gameur
| Author | SHA1 | Date | |
|---|---|---|---|
| bbeef58286 |
11 changed files with 78 additions and 34 deletions
28
.gitignore
vendored
Executable file
28
.gitignore
vendored
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
# Fichiers d'environnement (contiennent des tokens/clés sensibles)
|
||||
.env
|
||||
# Fichiers de configuration générés
|
||||
config.json
|
||||
whitelist.json
|
||||
bridges.json
|
||||
config.db
|
||||
malware.json
|
||||
|
||||
# Cache Python
|
||||
__pycache__/
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.pyd
|
||||
|
||||
# Environnements virtuels
|
||||
venv/
|
||||
env/
|
||||
.venv/
|
||||
|
||||
# IDE
|
||||
.vscode/
|
||||
.idea/
|
||||
|
||||
# Logs
|
||||
*.Logs
|
||||
*.log
|
||||
.data
|
||||
Binary file not shown.
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"resume_global": "",
|
||||
"historique_recent": [
|
||||
{
|
||||
"timestamp": "2026-03-21T16:12:34.189353+00:00",
|
||||
"channel_id": 1432453132008554567,
|
||||
"user_message": "<@1108087282692522105> <@1189193599594803272> \nJe suis la pour 18h si vous voulez !",
|
||||
"bot_message": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -113,49 +113,54 @@ class LLMManager:
|
|||
"""Extract JSON action objects from text more robustly."""
|
||||
actions = []
|
||||
|
||||
# Regex plus laxiste pour trouver des blocs JSON potentiels
|
||||
# On cherche des blocs commençant par {"action" ou {'action'
|
||||
matches = re.finditer(r'\{[\s\n]*[\"\']action[\"\'].*?\}', text, re.DOTALL)
|
||||
# 1. Try to extract from markdown blocks if present
|
||||
markdown_blocks = re.findall(r'```(?:json)?\s*(.*?)\s*```', text, re.DOTALL)
|
||||
candidates = markdown_blocks if markdown_blocks else [text]
|
||||
|
||||
for match in matches:
|
||||
json_str = match.group(0)
|
||||
for candidate_text in candidates:
|
||||
# Try to parse the whole text as a list or dict first
|
||||
try:
|
||||
# Tentative de parsing standard
|
||||
parsed = json.loads(json_str)
|
||||
if isinstance(parsed, dict) and 'action' in parsed:
|
||||
actions.append(parsed)
|
||||
except json.JSONDecodeError:
|
||||
# Si erreur, on tente de remplacer les simples quotes par des doubles
|
||||
# (Cas fréquent si le LLM mélange les styles)
|
||||
try:
|
||||
# Remplacement très basique (peut échouer si contenu complexe)
|
||||
json_corrected = json_str.replace("'", '"')
|
||||
parsed = json.loads(json_corrected)
|
||||
if isinstance(parsed, dict) and 'action' in parsed:
|
||||
parsed = json.loads(candidate_text.strip())
|
||||
if isinstance(parsed, list):
|
||||
for item in parsed:
|
||||
if isinstance(item, dict) and 'action' in item:
|
||||
if item not in actions:
|
||||
actions.append(item)
|
||||
if actions: return json.dumps(actions)
|
||||
elif isinstance(parsed, dict) and 'action' in parsed:
|
||||
if parsed not in actions:
|
||||
actions.append(parsed)
|
||||
continue
|
||||
except: pass
|
||||
return json.dumps(actions)
|
||||
except:
|
||||
pass
|
||||
|
||||
# Méthode récursive des accolades si le bloc est tronqué ou complexe
|
||||
start = match.start()
|
||||
# Fallback: scan for { ... } using brace matching
|
||||
start_indexes = [i for i, c in enumerate(candidate_text) if c == '{']
|
||||
for start in start_indexes:
|
||||
brace_count = 0
|
||||
for i in range(start, len(text)):
|
||||
if text[i] == '{': brace_count += 1
|
||||
elif text[i] == '}':
|
||||
for i in range(start, len(candidate_text)):
|
||||
if candidate_text[i] == '{':
|
||||
brace_count += 1
|
||||
elif candidate_text[i] == '}':
|
||||
brace_count -= 1
|
||||
if brace_count == 0:
|
||||
json_str = candidate_text[start:i+1]
|
||||
try:
|
||||
candidate = text[start:i+1]
|
||||
try:
|
||||
parsed = json.loads(candidate)
|
||||
except:
|
||||
parsed = json.loads(candidate.replace("'", '"'))
|
||||
|
||||
parsed = json.loads(json_str)
|
||||
if isinstance(parsed, dict) and 'action' in parsed:
|
||||
actions.append(parsed)
|
||||
break
|
||||
except: pass
|
||||
|
||||
if parsed not in actions: # avoid duplicates
|
||||
actions.append(parsed)
|
||||
except:
|
||||
# Fallback with single quote replace
|
||||
try:
|
||||
parsed = json.loads(json_str.replace("'", '"'))
|
||||
if isinstance(parsed, dict) and 'action' in parsed:
|
||||
if parsed not in actions:
|
||||
actions.append(parsed)
|
||||
except:
|
||||
pass
|
||||
break # Move to next start brace
|
||||
|
||||
if actions:
|
||||
return json.dumps(actions)
|
||||
return None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue