返回提交历史
Modified
g4f/Provider/needs_auth/OpenaiChat.py
+10
-3
XFEstudio/gpt4free
Use asyncio subprocess in OpenaiChat
cc301a3d
代码差异
1 个文件
+10
-3
@@ -1,7 +1,7 @@
1
1
from __future__ import annotations
2
2
3
3
import uuid, json, time, os
4
import tempfile, subprocess, shutil
4
import tempfile, shutil, asyncio
5
5
6
6
from ..base_provider import AsyncGeneratorProvider
7
7
from ..helper import get_browser, get_cookies, format_prompt, get_event_loop
@@ -174,7 +174,14 @@ fun.getToken(config).then(token => {
174
174
tmp.write(source.encode())
175
175
tmp.close()
176
176
try:
177
p = subprocess.Popen([node, tmp.name], stdout=subprocess.PIPE)
178
return p.stdout.read().decode()
177
p = await asyncio.create_subprocess_exec(
178
node, tmp.name,
179
stderr=asyncio.subprocess.PIPE,
180
stdout=asyncio.subprocess.PIPE
181
)
182
stdout, stderr = await p.communicate()
183
if p.returncode == 0:
184
return stdout.decode()
185
raise RuntimeError(f"Exec Error: {stderr.decode()}")
179
186
finally:
180
187
os.unlink(tmp.name)