From 1e2cf48cbac7e8fa13882f41e023a67fd9f286b7 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Fri, 5 Apr 2024 21:00:35 +0200 Subject: Add authless OpenaiChat --- g4f/Provider/openai/har_file.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'g4f/Provider/openai') diff --git a/g4f/Provider/openai/har_file.py b/g4f/Provider/openai/har_file.py index 68fe7420..8936c131 100644 --- a/g4f/Provider/openai/har_file.py +++ b/g4f/Provider/openai/har_file.py @@ -11,6 +11,9 @@ from copy import deepcopy from .crypt import decrypt, encrypt from ...requests import StreamSession +class NoValidHarFileError(Exception): + ... + class arkReq: def __init__(self, arkURL, arkBx, arkHeader, arkBody, arkCookies, userAgent): self.arkURL = arkURL @@ -39,7 +42,7 @@ def readHAR(): if harPath: break if not harPath: - raise RuntimeError("No .har file found") + raise NoValidHarFileError("No .har file found") for path in harPath: with open(path, 'rb') as file: try: @@ -54,7 +57,7 @@ def readHAR(): accessToken = json.loads(v["response"]["content"]["text"]).get("accessToken") cookies = {c['name']: c['value'] for c in v['request']['cookies']} if not accessToken: - RuntimeError("No accessToken found in .har files") + raise NoValidHarFileError("No accessToken found in .har files") if not chatArks: return None, accessToken, cookies return chatArks.pop(), accessToken, cookies @@ -75,9 +78,6 @@ def parseHAREntry(entry) -> arkReq: return tmpArk def genArkReq(chatArk: arkReq) -> arkReq: - if not chatArk: - raise RuntimeError("No .har file with arkose found") - tmpArk: arkReq = deepcopy(chatArk) if tmpArk is None or not tmpArk.arkBody or not tmpArk.arkHeader: raise RuntimeError("The .har file is not valid") -- cgit v1.2.3