Optimization logic
This commit is contained in:
@@ -47,14 +47,26 @@ class EmbeddingFunc:
|
||||
|
||||
def locate_json_string_body_from_string(content: str) -> Union[str, None]:
|
||||
"""Locate the JSON string body from a string"""
|
||||
maybe_json_str = re.search(r"{.*}", content, re.DOTALL)
|
||||
if maybe_json_str is not None:
|
||||
maybe_json_str = maybe_json_str.group(0)
|
||||
maybe_json_str = maybe_json_str.replace("\\n", "")
|
||||
maybe_json_str = maybe_json_str.replace("\n", "")
|
||||
maybe_json_str = maybe_json_str.replace("'", '"')
|
||||
return maybe_json_str
|
||||
else:
|
||||
try:
|
||||
maybe_json_str = re.search(r"{.*}", content, re.DOTALL)
|
||||
if maybe_json_str is not None:
|
||||
maybe_json_str = maybe_json_str.group(0)
|
||||
maybe_json_str = maybe_json_str.replace("\\n", "")
|
||||
maybe_json_str = maybe_json_str.replace("\n", "")
|
||||
maybe_json_str = maybe_json_str.replace("'", '"')
|
||||
json.loads(maybe_json_str)
|
||||
return maybe_json_str
|
||||
except:
|
||||
# try:
|
||||
# content = (
|
||||
# content.replace(kw_prompt[:-1], "")
|
||||
# .replace("user", "")
|
||||
# .replace("model", "")
|
||||
# .strip()
|
||||
# )
|
||||
# maybe_json_str = "{" + content.split("{")[1].split("}")[0] + "}"
|
||||
# json.loads(maybe_json_str)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user