mirror of https://github.com/xtekky/gpt4free.git
Merge pull request #1181 from hlohaus/arkose
Use asyncio subprocess in OpenaiChat
This commit is contained in:
commit
85ca16d77f
|
@ -1,7 +1,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import uuid, json, time, os
|
import uuid, json, time, os
|
||||||
import tempfile, subprocess, shutil
|
import tempfile, shutil, asyncio
|
||||||
|
|
||||||
from ..base_provider import AsyncGeneratorProvider
|
from ..base_provider import AsyncGeneratorProvider
|
||||||
from ..helper import get_browser, get_cookies, format_prompt, get_event_loop
|
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.write(source.encode())
|
||||||
tmp.close()
|
tmp.close()
|
||||||
try:
|
try:
|
||||||
p = subprocess.Popen([node, tmp.name], stdout=subprocess.PIPE)
|
p = await asyncio.create_subprocess_exec(
|
||||||
return p.stdout.read().decode()
|
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:
|
finally:
|
||||||
os.unlink(tmp.name)
|
os.unlink(tmp.name)
|
Loading…
Reference in New Issue