mirror of https://github.com/xtekky/gpt4free.git
Update helper.py
This commit is contained in:
parent
6e3f350f52
commit
ecc4748882
|
@ -13,4 +13,21 @@ def read_json(text: str) -> dict:
|
||||||
match = re.search(r"```(json|)\n(?P<code>[\S\s]+?)\n```", text)
|
match = re.search(r"```(json|)\n(?P<code>[\S\s]+?)\n```", text)
|
||||||
if match:
|
if match:
|
||||||
return match.group("code")
|
return match.group("code")
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
def find_stop(stop, content: str, chunk: str):
|
||||||
|
first = -1
|
||||||
|
word = None
|
||||||
|
if stop is not None:
|
||||||
|
for word in list(stop):
|
||||||
|
first = content.find(word)
|
||||||
|
if first != -1:
|
||||||
|
content = content[:first]
|
||||||
|
break
|
||||||
|
if stream and first != -1:
|
||||||
|
first = chunk.find(word)
|
||||||
|
if first != -1:
|
||||||
|
chunk = chunk[:first]
|
||||||
|
else:
|
||||||
|
first = 0
|
||||||
|
return first, content, chunk
|
||||||
|
|
Loading…
Reference in New Issue