Skip to content

Commit

Permalink
patch : Minor ones
Browse files Browse the repository at this point in the history
  • Loading branch information
Simatwa committed Apr 18, 2024
1 parent 7641f33 commit 62aafcf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
4 changes: 1 addition & 3 deletions WebChatGPT/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(
model: str = "text-davinci-002-render-sha",
conversation_index: int = 1,
locale: str = "en-US",
user_agent: str = "Mozilla/5.0 (X11; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0",
user_agent: str = utils.request_headers["User-Agent"],
timeout: tuple = 30,
disable_history_and_training: bool = False,
trace: bool = False,
Expand Down Expand Up @@ -84,8 +84,6 @@ def __init__(
self.__index = conversation_index
self.__title_cache = {}
self.stream_chunk_size = 64
# self.register_ws =self.session.post("https://chat.openai.com/backend-api/register-websocket")
# Websocket(self.register_ws.json(),self).run()

def __generate_payload(self, prompt: str) -> dict:
return utils.generate_payload(self, prompt)
Expand Down
12 changes: 6 additions & 6 deletions WebChatGPT/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
headers = request_headers = {
"Accept": "text/event-stream",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en-US",
"Alt-Used": "chat.openai.com",
"Accept-Language": "en-US,en;q=0.5",
# "Alt-Used": "chat.openai.com",
"Authorization": f"Bearer %(value)s",
"Connection": "keep-alive",
"Content-Type": "application/json",
Expand All @@ -26,7 +26,7 @@
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:124.0) Gecko/20100101 Firefox/124.0",
"OAI-Language": locale.getlocale()[0].replace("_", "-"),
}

Expand Down Expand Up @@ -103,12 +103,12 @@ def get_request_headers_and_append_auth(self) -> dict:
headers=request_headers,
)
# This sh*t here is raising http 403 in Python 3.9. Consider fixing it.
if not resp.ok:
self.auth = resp.json()
if not resp.ok or not self.auth:
raise VerificationError(
f"Failed to fetch Auth value ({resp.status_code}, {resp.reason}), supply path to correct cookies. "
+ __common_error_support_info
)
self.auth = resp.json()
if self.auth.get("error"):
raise CookieExpiredError(
"Your cookies have expired, login to `chat.openai.com` and then export new ones."
Expand Down Expand Up @@ -151,7 +151,7 @@ def is_json(response: object, info: str = ""):
content_type = response.headers.get("content-type")
if not "application/json" in content_type:
raise Exception(
f"Failed to fetch {info} - `{content_type}` : \n {response.text}"
f"Failed to fetch {info} - ({response.status_code}, {response.reason}) `{content_type}` : \n {response.text}"
)
return response.json()

Expand Down
2 changes: 1 addition & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,4 @@ More console chat manipulation features.
**What's new?*

- patch : Fail to generate response. Resolves #15 #14
- patch : Drop support for websocket.
- patch : Drop support for websocket.

0 comments on commit 62aafcf

Please sign in to comment.