(self)
| 66 | print(inout, file=sys.stderr) |
| 67 | |
| 68 | def _setup(self): |
| 69 | if self.options is not None: |
| 70 | # If track is enabled, create the chat log and id log files if they don't exist |
| 71 | if not isinstance(self.options.track, bool): |
| 72 | raise Exceptions.PyChatGPTException("Options to track conversation must be a boolean.") |
| 73 | if not isinstance(self.options.log, bool): |
| 74 | raise Exceptions.PyChatGPTException("Options to log must be a boolean.") |
| 75 | |
| 76 | if self.options.track: |
| 77 | if self.options.chat_log is not None: |
| 78 | self._create_if_not_exists(os.path.abspath(self.options.chat_log)) |
| 79 | self.options.chat_log = os.path.abspath(self.options.chat_log) |
| 80 | else: |
| 81 | # Create a chat log file called chat_log.txt |
| 82 | self.options.chat_log = "chat_log.txt" |
| 83 | self._create_if_not_exists(self.options.chat_log) |
| 84 | |
| 85 | if self.options.id_log is not None: |
| 86 | self._create_if_not_exists(os.path.abspath(self.options.id_log)) |
| 87 | self.options.id_log = os.path.abspath(self.options.id_log) |
| 88 | else: |
| 89 | # Create a chat log file called id_log.txt |
| 90 | self.options.id_log = "id_log.txt" |
| 91 | self._create_if_not_exists(self.options.id_log) |
| 92 | |
| 93 | if self.options.proxies is not None: |
| 94 | if not isinstance(self.options.proxies, dict): |
| 95 | if not isinstance(self.options.proxies, str): |
| 96 | raise Exceptions.PyChatGPTException("Proxies must be a string or dictionary.") |
| 97 | else: |
| 98 | self.proxies = {"http": self.options.proxies, "https": self.options.proxies} |
| 99 | self.log(f"{Fore.GREEN}>> Using proxies: True.") |
| 100 | |
| 101 | if self.options.track: |
| 102 | self.log(f"{Fore.GREEN}>> Tracking conversation enabled.") |
| 103 | if not isinstance(self.options.chat_log, str) or not isinstance(self.options.id_log, str): |
| 104 | raise Exceptions.PyChatGPTException( |
| 105 | "When saving a chat, file paths for chat_log and id_log must be strings.") |
| 106 | elif len(self.options.chat_log) == 0 or len(self.options.id_log) == 0: |
| 107 | raise Exceptions.PyChatGPTException( |
| 108 | "When saving a chat, file paths for chat_log and id_log cannot be empty.") |
| 109 | |
| 110 | self.__chat_history = [] |
| 111 | else: |
| 112 | self.options = Options() |
| 113 | |
| 114 | |
| 115 | if not self.email or not self.password: |
| 116 | self.log(f"{Fore.RED}>> You must provide an email and password when initializing the class.") |
| 117 | raise Exceptions.PyChatGPTException("You must provide an email and password when initializing the class.") |
| 118 | |
| 119 | if not isinstance(self.email, str) or not isinstance(self.password, str): |
| 120 | self.log(f"{Fore.RED}>> Email and password must be strings.") |
| 121 | raise Exceptions.PyChatGPTException("Email and password must be strings.") |
| 122 | |
| 123 | if len(self.email) == 0 or len(self.password) == 0: |
| 124 | self.log(f"{Fore.RED}>> Email cannot be empty.") |
| 125 | raise Exceptions.PyChatGPTException("Email cannot be empty.") |
no test coverage detected