Spaces:
Runtime error
Runtime error
Dmitry Kirsanov commited on
Commit ·
8579920
1
Parent(s): d1983b7
missed file
Browse files- llm_parsing.py +33 -0
llm_parsing.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
def parse_lists(ret, what):
|
| 4 |
+
|
| 5 |
+
lines = ret.splitlines()
|
| 6 |
+
inlist = False
|
| 7 |
+
retlist = []
|
| 8 |
+
|
| 9 |
+
for line in lines:
|
| 10 |
+
line = line.strip()
|
| 11 |
+
if line == "":
|
| 12 |
+
inlist = False
|
| 13 |
+
elif line[-1] == ":":
|
| 14 |
+
if line[:-1].upper() == what.upper():
|
| 15 |
+
inlist = True
|
| 16 |
+
else:
|
| 17 |
+
inlist = False
|
| 18 |
+
elif inlist:
|
| 19 |
+
if line.startswith("- "):
|
| 20 |
+
item = line[2:].strip()
|
| 21 |
+
else:
|
| 22 |
+
item = line
|
| 23 |
+
retlist.append(item)
|
| 24 |
+
|
| 25 |
+
print(f"===Parsed list {what}: {retlist}")
|
| 26 |
+
return retlist
|
| 27 |
+
|
| 28 |
+
def extract_document_from_response(ret):
|
| 29 |
+
r = re.sub(r'^<derivative-document>(.*)</derivative-document>$', r'\1', ret, flags=re.DOTALL)
|
| 30 |
+
r = re.sub(r'^<revised-document>(.*)</revised-document>$', r'\1', r, flags=re.DOTALL)
|
| 31 |
+
r = re.sub(r'^<document>(.*)</document>$', r'\1', r, flags=re.DOTALL)
|
| 32 |
+
return r
|
| 33 |
+
|