-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_parser.py
More file actions
32 lines (25 loc) · 925 Bytes
/
Copy pathtest_parser.py
File metadata and controls
32 lines (25 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import json
import re
def yaniti_ayristir(ham_metin: str):
metin = ham_metin.strip()
metin = re.sub(r"^```[a-zA-Z]*\n", "", metin)
metin = re.sub(r"\n```$", "", metin)
metin = metin.strip()
try:
data = json.loads(metin)
if data.get("type") in ["error", "refusal"]:
return data.get("content", ""), ""
return data.get("explain", ""), data.get("content", "")
except Exception:
pass
aciklama = ""
komut = ""
metin = re.sub(r"```[a-zA-Z]*\n", " ", ham_metin)
metin = metin.replace("```", "")
if not re.search(r"(AÇIKLAMA|DESCRIPTION|KOMUT|COMMAND)\s*:", metin, re.IGNORECASE):
# THIS IS THE FALLBACK I AM CURIOUS ABOUT
return "", ""
# ...rest
return "X", "Y"
print("1:", yaniti_ayristir("Hello! How can I help you?"))
print("2:", yaniti_ayristir('{"type": "command", "content": "hello"}'))