Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
Fix headless detection
Browse files Browse the repository at this point in the history
  • Loading branch information
terry3041 committed Dec 13, 2022
1 parent f9b51aa commit 64b4f33
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ resp = api1.send_message('Hello, world!')
print(resp['message'])

api1.reset_conversation() # reset the conversation
api1.close() # close the session
```

## Frequently Asked Questions
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pyChatGPT"
version = "0.3.1"
version = "0.3.2"
authors = [
{ name="terry3041", email="[email protected]" },
]
Expand Down
7 changes: 5 additions & 2 deletions src/pyChatGPT/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ def clear_screen():

clear_screen()
print(
'Conversation started. Type "reset" to reset the conversation. Type "reauth" to reauthenticate.'
'Conversation started. Type "reset" to reset the conversation. Type "quit" to quit.'
)
while True:
prompt = input('\nYou: ')
if prompt.lower() == 'reset':
chat.reset_conversation()
clear_screen()
print(
'Conversation started. Type "reset" to reset the conversation. Type "reauth" to reauthenticate.'
'Conversation started. Type "reset" to reset the conversation. Type "quit" to quit.'
)
continue
if prompt.lower() == 'quit':
chat.close()
break
print('\nChatGPT: ', end='')
response = chat.send_message(prompt)
print(response['message'])
14 changes: 12 additions & 2 deletions src/pyChatGPT/pyChatGPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

from pyvirtualdisplay import Display
import markdownify
import re
import platform
import os
import re


class ChatGPT:
Expand All @@ -33,9 +34,18 @@ def __init__(
raise ValueError('Invalid proxy format')

self.session_token = session_token
self.is_headless = os.name == 'posix' and 'DISPLAY' not in os.environ
self.is_headless = platform.system() == 'Linux' and 'DISPLAY' not in os.environ
self.__init_browser()

def close(self) -> None:
'''
Close the browser and stop the virtual display (if any)
'''
if hasattr(self, 'driver'):
self.driver.quit()
if hasattr(self, 'display'):
self.display.stop()

def __init_browser(self) -> None:
'''
Get the Cloudflare cookies & user-agent
Expand Down

0 comments on commit 64b4f33

Please sign in to comment.