|
9 | 9 | from together.error import AuthenticationError |
10 | 10 | from together.types import TogetherClient |
11 | 11 | from together.utils import enforce_trailing_slash |
| 12 | +from together.utils.api_helpers import get_google_colab_secret |
12 | 13 |
|
13 | 14 |
|
14 | 15 | class Together: |
@@ -45,22 +46,8 @@ def __init__( |
45 | 46 | if not api_key: |
46 | 47 | api_key = os.environ.get("TOGETHER_API_KEY") |
47 | 48 |
|
48 | | - # If running in Google Colab, check notebook secrets |
49 | 49 | if not api_key and "google.colab" in sys.modules: |
50 | | - if TYPE_CHECKING: |
51 | | - from google.colab import userdata # type: ignore |
52 | | - else: |
53 | | - from google.colab import userdata |
54 | | - try: |
55 | | - api_key = userdata.get("TOGETHER_API_KEY") |
56 | | - except userdata.NotebookAccessError: |
57 | | - print( |
58 | | - "The TOGETHER_API_KEY Colab secret was found, but notebook access is disabled. Please enable notebook " |
59 | | - "access for the secret." |
60 | | - ) |
61 | | - except userdata.SecretNotFoundError: |
62 | | - # warn and carry on |
63 | | - print("Colab: No Google Colab secret named TOGETHER_API_KEY was found.") |
| 50 | + api_key = get_google_colab_secret("TOGETHER_API_KEY") |
64 | 51 |
|
65 | 52 | if not api_key: |
66 | 53 | raise AuthenticationError( |
@@ -135,6 +122,9 @@ def __init__( |
135 | 122 | if not api_key: |
136 | 123 | api_key = os.environ.get("TOGETHER_API_KEY") |
137 | 124 |
|
| 125 | + if not api_key and "google.colab" in sys.modules: |
| 126 | + api_key = get_google_colab_secret("TOGETHER_API_KEY") |
| 127 | + |
138 | 128 | if not api_key: |
139 | 129 | raise AuthenticationError( |
140 | 130 | "The api_key client option must be set either by passing api_key to the client or by setting the " |
|
0 commit comments