From a26421bcd8b8580650fa05b3fb4f8fdfa0ef9921 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sun, 21 Apr 2024 15:15:55 +0200 Subject: Add image model list --- g4f/Provider/openai/har_file.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'g4f/Provider/openai') diff --git a/g4f/Provider/openai/har_file.py b/g4f/Provider/openai/har_file.py index 52cd8260..c1b3b9f1 100644 --- a/g4f/Provider/openai/har_file.py +++ b/g4f/Provider/openai/har_file.py @@ -59,17 +59,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 +127,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 -- cgit v1.2.3