返回提交历史
Modified
g4f/Provider/needs_auth/OpenaiChat.py
+25
-21
XFEstudio/gpt4free
Add exec_js helper def
dfefd22a
代码差异
1 个文件
+25
-21
@@ -145,11 +145,6 @@ class OpenaiChat(AsyncGeneratorProvider):
145
145
return f"g4f.provider.{cls.__name__} supports: ({param})"
146
146
147
147
async def get_arkose_token(proxy: str = None) -> str:
148
node = shutil.which("node")
149
if not node:
150
if debug.logging:
151
print('OpenaiChat: "node" not found')
152
return
153
148
dir = os.path.dirname(os.path.dirname(__file__))
154
149
include = f'{dir}/npm/node_modules/funcaptcha'
155
150
config = {
@@ -175,23 +170,32 @@ fun.getToken(config).then(token => {
175
170
tmp.write(source.encode())
176
171
tmp.close()
177
172
try:
178
if sys.platform == 'win32':
179
p = subprocess.Popen(
180
[node, tmp.name],
181
stdout=subprocess.PIPE,
182
stderr=subprocess.PIPE
183
)
184
if p.returncode == 0:
185
return p.stdout.read().decode()
186
raise RuntimeError(f"Exec Error: {p.stderr.read().decode()}")
187
p = await asyncio.create_subprocess_exec(
188
node, tmp.name,
189
stderr=asyncio.subprocess.PIPE,
190
stdout=asyncio.subprocess.PIPE
173
return await exec_js(tmp.name)
174
finally:
175
os.unlink(tmp.name)
176
177
async def exec_js(file: str) -> str:
178
node = shutil.which("node")
179
if not node:
180
if debug.logging:
181
print('OpenaiChat: "node" not found')
182
return
183
if sys.platform == 'win32':
184
p = subprocess.Popen(
185
[node, file],
186
stdout=subprocess.PIPE,
187
stderr=subprocess.PIPE
191
188
)
192
stdout, stderr = await p.communicate()
189
stdout, stderr = p.communicate()
193
190
if p.returncode == 0:
194
191
return stdout.decode()
195
192
raise RuntimeError(f"Exec Error: {stderr.decode()}")
196
finally:
197
os.unlink(tmp.name)
193
p = await asyncio.create_subprocess_exec(
194
node, file,
195
stderr=asyncio.subprocess.PIPE,
196
stdout=asyncio.subprocess.PIPE
197
)
198
stdout, stderr = await p.communicate()
199
if p.returncode == 0:
200
return stdout.decode()
201
raise RuntimeError(f"Exec Error: {stderr.decode()}")