together 1.4.4__py3-none-any.whl → 1.4.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
together/client.py CHANGED
@@ -1,13 +1,15 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import os
4
- from typing import Dict
4
+ import sys
5
+ from typing import Dict, TYPE_CHECKING
5
6
 
6
7
  from together import resources
7
8
  from together.constants import BASE_URL, MAX_RETRIES, TIMEOUT_SECS
8
9
  from together.error import AuthenticationError
9
10
  from together.types import TogetherClient
10
11
  from together.utils import enforce_trailing_slash
12
+ from together.utils.api_helpers import get_google_colab_secret
11
13
 
12
14
 
13
15
  class Together:
@@ -44,6 +46,9 @@ class Together:
44
46
  if not api_key:
45
47
  api_key = os.environ.get("TOGETHER_API_KEY")
46
48
 
49
+ if not api_key and "google.colab" in sys.modules:
50
+ api_key = get_google_colab_secret("TOGETHER_API_KEY")
51
+
47
52
  if not api_key:
48
53
  raise AuthenticationError(
49
54
  "The api_key client option must be set either by passing api_key to the client or by setting the "
@@ -117,6 +122,9 @@ class AsyncTogether:
117
122
  if not api_key:
118
123
  api_key = os.environ.get("TOGETHER_API_KEY")
119
124
 
125
+ if not api_key and "google.colab" in sys.modules:
126
+ api_key = get_google_colab_secret("TOGETHER_API_KEY")
127
+
120
128
  if not api_key:
121
129
  raise AuthenticationError(
122
130
  "The api_key client option must be set either by passing api_key to the client or by setting the "
@@ -2,6 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import json
4
4
  import os
5
+ import sys
5
6
  import platform
6
7
  from typing import TYPE_CHECKING, Any, Dict
7
8
 
@@ -12,6 +13,7 @@ if TYPE_CHECKING:
12
13
  import together
13
14
  from together import error
14
15
  from together.utils._log import _console_log_level
16
+ from together.utils import log_info
15
17
 
16
18
 
17
19
  def get_headers(
@@ -82,3 +84,41 @@ def default_api_key(api_key: str | None = None) -> str | None:
82
84
  return os.environ.get("TOGETHER_API_KEY")
83
85
 
84
86
  raise error.AuthenticationError(together.constants.MISSING_API_KEY_MESSAGE)
87
+
88
+
89
+ def get_google_colab_secret(secret_name: str = "TOGETHER_API_KEY") -> str | None:
90
+ """
91
+ Checks to see if the user is running in Google Colab, and looks for the Together API Key secret.
92
+
93
+ Args:
94
+ secret_name (str, optional). Defaults to TOGETHER_API_KEY
95
+
96
+ Returns:
97
+ str: if the API key is found; None if an error occurred or the secret was not found.
98
+ """
99
+ # If running in Google Colab, check for Together in notebook secrets
100
+ if "google.colab" in sys.modules:
101
+ if TYPE_CHECKING:
102
+ from google.colab import userdata # type: ignore
103
+ else:
104
+ from google.colab import userdata
105
+
106
+ try:
107
+ api_key = userdata.get(secret_name)
108
+ if not isinstance(api_key, str):
109
+ return None
110
+ else:
111
+ return str(api_key)
112
+ except userdata.NotebookAccessError:
113
+ log_info(
114
+ "The TOGETHER_API_KEY Colab secret was found, but notebook access is disabled. Please enable notebook "
115
+ "access for the secret."
116
+ )
117
+ except userdata.SecretNotFoundError:
118
+ # warn and carry on
119
+ log_info("Colab: No Google Colab secret named TOGETHER_API_KEY was found.")
120
+
121
+ return None
122
+
123
+ else:
124
+ return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: together
3
- Version: 1.4.4
3
+ Version: 1.4.5
4
4
  Summary: Python client for Together's Cloud Platform!
5
5
  License: Apache-2.0
6
6
  Author: Together AI
@@ -12,7 +12,7 @@ together/cli/api/images.py,sha256=GADSeaNUHUVMtWovmccGuKc28IJ9E_v4vAEwYHJhu5o,26
12
12
  together/cli/api/models.py,sha256=xWEzu8ZpxM_Pz9KEjRPRVuv_v22RayYZ4QcgiezT5tE,1126
13
13
  together/cli/api/utils.py,sha256=IuqYWPnLI38_Bqd7lj8V_SnGdYc59pRmMbQmciS4FsM,1326
14
14
  together/cli/cli.py,sha256=YCDzbXpC5is0rs2PEkUPrIhYuzdyrihQ8GVR_TlDv5s,2054
15
- together/client.py,sha256=vOe9NOgDyDlrT5ppvNfJGzdOHnMWEPmJX2RbXUQXKno,5081
15
+ together/client.py,sha256=KKmO0LadgAyj8AXKrJCYwLDyxR7_CUB4uTmay1eiyFE,5420
16
16
  together/constants.py,sha256=UDJhEylJFmdm4bedBDpvqYXBj5Or3k7z9GWtkRY_dZQ,1526
17
17
  together/error.py,sha256=HU6247CyzCFjaxL9A0XYbXZ6fY_ebRg0FEYjI4Skogs,5515
18
18
  together/filemanager.py,sha256=QHhBn73oVFdgUpSYXYLmJzHJ9c5wYEMJC0ur6ZgDeYo,11269
@@ -54,12 +54,12 @@ together/types/models.py,sha256=nwQIZGHKZpX9I6mK8z56VW70YC6Ry6JGsVa0s99QVxc,1055
54
54
  together/types/rerank.py,sha256=qZfuXOn7MZ6ly8hpJ_MZ7OU_Bi1-cgYNSB20Wja8Qkk,1061
55
55
  together/utils/__init__.py,sha256=5fqvj4KT2rHxKSQot2TSyV_HcvkvkGiqAiaYuJwqtm0,786
56
56
  together/utils/_log.py,sha256=5IYNI-jYzxyIS-pUvhb0vE_Muo3MA7GgBhsu66TKP2w,1951
57
- together/utils/api_helpers.py,sha256=RSF7SRhbjHzroMOSWAXscflByM1r1ta_1SpxkAT22iE,2407
57
+ together/utils/api_helpers.py,sha256=2K0O6qeEQ2zVFvi5NBN5m2kjZJaS3-JfKFecQ7SmGaw,3746
58
58
  together/utils/files.py,sha256=rfp10qU0urtWOXXFeasFtO9xp-1KIhM3S43JxcnHmL0,16438
59
59
  together/utils/tools.py,sha256=H2MTJhEqtBllaDvOyZehIO_IVNK3P17rSDeILtJIVag,2964
60
60
  together/version.py,sha256=p03ivHyE0SyWU4jAnRTBi_sOwywVWoZPU4g2gzRgG-Y,126
61
- together-1.4.4.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
62
- together-1.4.4.dist-info/METADATA,sha256=ICtNOO5v35bKJFEtlgdVg4ORP0ofYO11vANs-QuowxY,14445
63
- together-1.4.4.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
64
- together-1.4.4.dist-info/entry_points.txt,sha256=G-b5NKW6lUUf1V1fH8IPTBb7jXnK7lhbX9H1zTEJXPs,50
65
- together-1.4.4.dist-info/RECORD,,
61
+ together-1.4.5.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
62
+ together-1.4.5.dist-info/METADATA,sha256=vIX519bvnuj6VrksF_aORHUmu4xFgzalx5CZVoFzKYk,14445
63
+ together-1.4.5.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
64
+ together-1.4.5.dist-info/entry_points.txt,sha256=G-b5NKW6lUUf1V1fH8IPTBb7jXnK7lhbX9H1zTEJXPs,50
65
+ together-1.4.5.dist-info/RECORD,,