Save access_token and an hour from now on CHATGPT_ACCESS_TOKEN CHATGPT_ACCESS_TOKEN_EXPIRY environment variables :param expiry: :param access_token: :return:
(access_token: str, expiry: int or None = None)
| 396 | |
| 397 | @staticmethod |
| 398 | def save_access_token(access_token: str, expiry: int or None = None): |
| 399 | """ |
| 400 | Save access_token and an hour from now on CHATGPT_ACCESS_TOKEN CHATGPT_ACCESS_TOKEN_EXPIRY environment variables |
| 401 | :param expiry: |
| 402 | :param access_token: |
| 403 | :return: |
| 404 | """ |
| 405 | try: |
| 406 | print(f"{Fore.GREEN}[OpenAI][9] {Fore.WHITE}Saving access token...") |
| 407 | expiry = expiry or int(time.time()) + 3600 |
| 408 | |
| 409 | # Get path using os, it's in ./classes/auth.json |
| 410 | path = os.path.dirname(os.path.abspath(__file__)) |
| 411 | path = os.path.join(path, "auth.json") |
| 412 | with open(path, "w") as f: |
| 413 | f.write(json.dumps({"access_token": access_token, "expires_at": expiry})) |
| 414 | |
| 415 | print(f"{Fore.GREEN}[OpenAI][8] {Fore.WHITE}Saved access token") |
| 416 | except Exception as e: |
| 417 | raise e |
no outgoing calls
no test coverage detected