Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/tabpfn_client/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@

import shutil

from httpx import ConnectError

from tabpfn_client.client import ServiceClient
from tabpfn_client.service_wrapper import UserAuthenticationClient
from tabpfn_client.constants import CACHE_DIR
from tabpfn_client.prompt_agent import PromptAgent
from tabpfn_client.ui import console, warn


CONNECTION_ERROR = RuntimeError(
"TabPFN is inaccessible at the moment, please try again later."
)


class Config:
def __new__(cls, *args, **kwargs):
"""
Expand All @@ -31,16 +38,17 @@ def init(use_server=True):
return

if use_server:
# check connection to server
if not UserAuthenticationClient.is_accessible_connection():
raise RuntimeError(
"TabPFN is inaccessible at the moment, please try again later."
try:
is_valid_token, access_token = (
UserAuthenticationClient.try_reuse_existing_token()
)
except ConnectError:
raise CONNECTION_ERROR

(
is_valid_token,
access_token,
) = UserAuthenticationClient.try_reuse_existing_token()
# TODO: no need to check connection again if token is valid, need to
# adjust tests accordingly.
if not UserAuthenticationClient.is_accessible_connection():
raise CONNECTION_ERROR

if is_valid_token:
PromptAgent.prompt_reusing_existing_token()
Expand Down