Skip to content

Commit 2fa28fd

Browse files
committed
wrap sd_parse_meta_field in trycatch
1 parent c48999f commit 2fa28fd

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

koboldcpp.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,17 +1814,21 @@ def sd_process_meta_fields(fields, config):
18141814
# json with top-level dict
18151815
def sd_parse_meta_field(prompt, config=False):
18161816
jfields = {}
1817+
kv_dict = {}
18171818
try:
1818-
jfields = json.loads(prompt)
1819-
except json.JSONDecodeError:
1820-
# accept "field":"value",... without {} (also empty strings)
18211819
try:
1822-
jfields = json.loads('{ ' + prompt + ' }')
1820+
jfields = json.loads(prompt)
18231821
except json.JSONDecodeError:
1824-
print("Warning: couldn't parse meta prompt; it should be valid JSON.")
1825-
if not isinstance(jfields, dict):
1826-
jfields = {}
1827-
kv_dict = sd_process_meta_fields(jfields.items(), config)
1822+
# accept "field":"value",... without {} (also empty strings)
1823+
try:
1824+
jfields = json.loads('{ ' + prompt + ' }')
1825+
except json.JSONDecodeError:
1826+
print("Warning: couldn't parse meta prompt; it should be valid JSON.")
1827+
if not isinstance(jfields, dict):
1828+
jfields = {}
1829+
kv_dict = sd_process_meta_fields(jfields.items(), config)
1830+
except Exception:
1831+
pass
18281832
return kv_dict
18291833

18301834

0 commit comments

Comments
 (0)