diff options
author | H Lohaus <hlohaus@users.noreply.github.com> | 2023-10-29 19:58:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-29 19:58:56 +0100 |
commit | 85ca16d77f4549ae4d3ac494000f299ce39b2253 (patch) | |
tree | 00a85aaeaedd56237cf68c0df2eb1caaf76140a1 /g4f/Provider/needs_auth/OpenaiChat.py | |
parent | Merge pull request #1184 from PrajwalGraj/patch-1 (diff) | |
parent | Use asyncio subprocess in OpenaiChat (diff) | |
download | gpt4free-85ca16d77f4549ae4d3ac494000f299ce39b2253.tar gpt4free-85ca16d77f4549ae4d3ac494000f299ce39b2253.tar.gz gpt4free-85ca16d77f4549ae4d3ac494000f299ce39b2253.tar.bz2 gpt4free-85ca16d77f4549ae4d3ac494000f299ce39b2253.tar.lz gpt4free-85ca16d77f4549ae4d3ac494000f299ce39b2253.tar.xz gpt4free-85ca16d77f4549ae4d3ac494000f299ce39b2253.tar.zst gpt4free-85ca16d77f4549ae4d3ac494000f299ce39b2253.zip |
Diffstat (limited to 'g4f/Provider/needs_auth/OpenaiChat.py')
-rw-r--r-- | g4f/Provider/needs_auth/OpenaiChat.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/g4f/Provider/needs_auth/OpenaiChat.py b/g4f/Provider/needs_auth/OpenaiChat.py index eaccb7f1..fb81face 100644 --- a/g4f/Provider/needs_auth/OpenaiChat.py +++ b/g4f/Provider/needs_auth/OpenaiChat.py @@ -1,7 +1,7 @@ from __future__ import annotations import uuid, json, time, os -import tempfile, subprocess, shutil +import tempfile, shutil, asyncio from ..base_provider import AsyncGeneratorProvider from ..helper import get_browser, get_cookies, format_prompt, get_event_loop @@ -174,7 +174,14 @@ fun.getToken(config).then(token => { tmp.write(source.encode()) tmp.close() try: - p = subprocess.Popen([node, tmp.name], stdout=subprocess.PIPE) - return p.stdout.read().decode() + p = await asyncio.create_subprocess_exec( + node, tmp.name, + stderr=asyncio.subprocess.PIPE, + stdout=asyncio.subprocess.PIPE + ) + stdout, stderr = await p.communicate() + if p.returncode == 0: + return stdout.decode() + raise RuntimeError(f"Exec Error: {stderr.decode()}") finally: os.unlink(tmp.name)
\ No newline at end of file |