Skip to content

Commit

Permalink
~ |
Browse files Browse the repository at this point in the history
trying to improve compability with python versions < 3.8
  • Loading branch information
xtekky committed Nov 19, 2023
1 parent a7e1419 commit d4c8f3e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
7 changes: 3 additions & 4 deletions g4f/Provider/AItianhu.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ async def create_async_generator(

if "detail" not in line:
raise RuntimeError(f"Response: {line}")
if content := line["detail"]["choices"][0]["delta"].get(
"content"
):

content = line["detail"]["choices"][0]["delta"].get("content")
if content:
yield content


@classmethod
@property
def params(cls):
Expand Down
5 changes: 2 additions & 3 deletions g4f/Provider/GptForLove.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ async def create_async_generator(
except:
raise RuntimeError(f"Broken line: {line}")
if "detail" in line:
if content := line["detail"]["choices"][0]["delta"].get(
"content"
):
content = line["detail"]["choices"][0]["delta"].get("content")
if content:
yield content
elif "10分钟内提问超过了5次" in line:
raise RuntimeError("Rate limit reached")
Expand Down
4 changes: 3 additions & 1 deletion g4f/Provider/GptGo.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ async def create_async_generator(
line = json.loads(line[len(start):-1])
if line["choices"][0]["finish_reason"] == "stop":
break
if content := line["choices"][0]["delta"].get("content"):

content = line["choices"][0]["delta"].get("content"):
if content:
yield content


Expand Down
5 changes: 2 additions & 3 deletions g4f/Provider/Ylokh.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ async def create_async_generator(
if line.startswith("data: [DONE]"):
break
line = json.loads(line[6:])
if content := line["choices"][0]["delta"].get(
"content"
):
content = line["choices"][0]["delta"].get("content")
if content:
yield content
else:
chat = await response.json()
Expand Down
4 changes: 3 additions & 1 deletion g4f/Provider/deprecated/Ails.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ async def create_async_generator(
if line.startswith(start) and line != "data: [DONE]":
line = line[len(start):-1]
line = json.loads(line)
if token := line["choices"][0]["delta"].get("content"):
token = line["choices"][0]["delta"].get("content")

if token:
if "ai.ls" in token or "ai.ci" in token:
raise Exception(f"Response Error: {token}")
yield token
Expand Down

0 comments on commit d4c8f3e

Please sign in to comment.