summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/openai
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-04-22 01:35:07 +0200
committerGitHub <noreply@github.com>2024-04-22 01:35:07 +0200
commit4b4d1f08b5c75c8c8932b5edfbb0d020f8e029a7 (patch)
tree6ed0cfc6cd53a3ab32565d6199a929ac1ea6ad80 /g4f/Provider/openai
parentMerge pull request #1869 from hlohaus/carst (diff)
parentAdd vision models to readme (diff)
downloadgpt4free-4b4d1f08b5c75c8c8932b5edfbb0d020f8e029a7.tar
gpt4free-4b4d1f08b5c75c8c8932b5edfbb0d020f8e029a7.tar.gz
gpt4free-4b4d1f08b5c75c8c8932b5edfbb0d020f8e029a7.tar.bz2
gpt4free-4b4d1f08b5c75c8c8932b5edfbb0d020f8e029a7.tar.lz
gpt4free-4b4d1f08b5c75c8c8932b5edfbb0d020f8e029a7.tar.xz
gpt4free-4b4d1f08b5c75c8c8932b5edfbb0d020f8e029a7.tar.zst
gpt4free-4b4d1f08b5c75c8c8932b5edfbb0d020f8e029a7.zip
Diffstat (limited to 'g4f/Provider/openai')
-rw-r--r--g4f/Provider/openai/crypt.py2
-rw-r--r--g4f/Provider/openai/har_file.py20
2 files changed, 15 insertions, 7 deletions
diff --git a/g4f/Provider/openai/crypt.py b/g4f/Provider/openai/crypt.py
index e7f35190..43156f3d 100644
--- a/g4f/Provider/openai/crypt.py
+++ b/g4f/Provider/openai/crypt.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
import json
import base64
import hashlib
diff --git a/g4f/Provider/openai/har_file.py b/g4f/Provider/openai/har_file.py
index 52cd8260..da25b637 100644
--- a/g4f/Provider/openai/har_file.py
+++ b/g4f/Provider/openai/har_file.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
import base64
import json
import os
@@ -59,17 +61,21 @@ def readHAR():
except KeyError:
continue
cookies = {c['name']: c['value'] for c in v['request']['cookies']}
+ headers = get_headers(v)
if not accessToken:
raise NoValidHarFileError("No accessToken found in .har files")
if not chatArks:
- return None, accessToken, cookies
- return chatArks.pop(), accessToken, cookies
+ return None, accessToken, cookies, headers
+ return chatArks.pop(), accessToken, cookies, headers
+
+def get_headers(entry) -> dict:
+ return {h['name'].lower(): h['value'] for h in entry['request']['headers'] if h['name'].lower() not in ['content-length', 'cookie'] and not h['name'].startswith(':')}
def parseHAREntry(entry) -> arkReq:
tmpArk = arkReq(
arkURL=entry['request']['url'],
arkBx="",
- arkHeader={h['name'].lower(): h['value'] for h in entry['request']['headers'] if h['name'].lower() not in ['content-length', 'cookie'] and not h['name'].startswith(':')},
+ arkHeader=get_headers(entry),
arkBody={p['name']: unquote(p['value']) for p in entry['request']['postData']['params'] if p['name'] not in ['rnd']},
arkCookies={c['name']: c['value'] for c in entry['request']['cookies']},
userAgent=""
@@ -123,11 +129,11 @@ def getN() -> str:
timestamp = str(int(time.time()))
return base64.b64encode(timestamp.encode()).decode()
-async def getArkoseAndAccessToken(proxy: str):
+async def getArkoseAndAccessToken(proxy: str) -> tuple[str, str, dict, dict]:
global chatArk, accessToken, cookies
if chatArk is None or accessToken is None:
- chatArk, accessToken, cookies = readHAR()
+ chatArk, accessToken, cookies, headers = readHAR()
if chatArk is None:
- return None, accessToken, cookies
+ return None, accessToken, cookies, headers
newReq = genArkReq(chatArk)
- return await sendRequest(newReq, proxy), accessToken, cookies
+ return await sendRequest(newReq, proxy), accessToken, cookies, headers