mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-09-12 08:29:30 -04:00
Merge pull request #1207 from hlohaus/win
Fix NotImplementedError on WIn
This commit is contained in:
commit
363daeaab2
@ -2,6 +2,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import uuid, json, time, os
|
import uuid, json, time, os
|
||||||
import tempfile, shutil, asyncio
|
import tempfile, shutil, asyncio
|
||||||
|
import sys, subprocess
|
||||||
|
|
||||||
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
|
||||||
@ -144,11 +145,6 @@ class OpenaiChat(AsyncGeneratorProvider):
|
|||||||
return f"g4f.provider.{cls.__name__} supports: ({param})"
|
return f"g4f.provider.{cls.__name__} supports: ({param})"
|
||||||
|
|
||||||
async def get_arkose_token(proxy: str = None) -> str:
|
async def get_arkose_token(proxy: str = None) -> str:
|
||||||
node = shutil.which("node")
|
|
||||||
if not node:
|
|
||||||
if debug.logging:
|
|
||||||
print('OpenaiChat: "node" not found')
|
|
||||||
return
|
|
||||||
dir = os.path.dirname(os.path.dirname(__file__))
|
dir = os.path.dirname(os.path.dirname(__file__))
|
||||||
include = f'{dir}/npm/node_modules/funcaptcha'
|
include = f'{dir}/npm/node_modules/funcaptcha'
|
||||||
config = {
|
config = {
|
||||||
@ -174,14 +170,32 @@ fun.getToken(config).then(token => {
|
|||||||
tmp.write(source.encode())
|
tmp.write(source.encode())
|
||||||
tmp.close()
|
tmp.close()
|
||||||
try:
|
try:
|
||||||
p = await asyncio.create_subprocess_exec(
|
return await exec_js(tmp.name)
|
||||||
node, tmp.name,
|
finally:
|
||||||
stderr=asyncio.subprocess.PIPE,
|
os.unlink(tmp.name)
|
||||||
stdout=asyncio.subprocess.PIPE
|
|
||||||
|
async def exec_js(file: str) -> str:
|
||||||
|
node = shutil.which("node")
|
||||||
|
if not node:
|
||||||
|
if debug.logging:
|
||||||
|
print('OpenaiChat: "node" not found')
|
||||||
|
return
|
||||||
|
if sys.platform == 'win32':
|
||||||
|
p = subprocess.Popen(
|
||||||
|
[node, file],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE
|
||||||
)
|
)
|
||||||
stdout, stderr = await p.communicate()
|
stdout, stderr = p.communicate()
|
||||||
if p.returncode == 0:
|
if p.returncode == 0:
|
||||||
return stdout.decode()
|
return stdout.decode()
|
||||||
raise RuntimeError(f"Exec Error: {stderr.decode()}")
|
raise RuntimeError(f"Exec Error: {stderr.decode()}")
|
||||||
finally:
|
p = await asyncio.create_subprocess_exec(
|
||||||
os.unlink(tmp.name)
|
node, file,
|
||||||
|
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()}")
|
Loading…
Reference in New Issue
Block a user