together 0.2.8__py3-none-any.whl → 0.2.10__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/__init__.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import os
2
2
  import sys
3
3
  import urllib.parse
4
+ from typing import Type
4
5
 
5
6
  from .version import VERSION
6
7
 
@@ -41,6 +42,27 @@ from .image import Image
41
42
  from .models import Models
42
43
 
43
44
 
45
+ class Together:
46
+ complete: Type[Complete]
47
+ completion: Type[Completion]
48
+ embeddings: Type[Embeddings]
49
+ files: Type[Files]
50
+ finetune: Type[Finetune]
51
+ image: Type[Image]
52
+ models: Type[Models]
53
+
54
+ def __init__(
55
+ self,
56
+ ) -> None:
57
+ self.complete = Complete
58
+ self.completion = Completion
59
+ self.embeddings = Embeddings
60
+ self.files = Files
61
+ self.finetune = Finetune
62
+ self.image = Image
63
+ self.models = Models
64
+
65
+
44
66
  __all__ = [
45
67
  "api_key",
46
68
  "api_base",
@@ -63,4 +85,5 @@ __all__ = [
63
85
  "MISSING_API_KEY_MESSAGE",
64
86
  "BACKOFF_FACTOR",
65
87
  "min_samples",
88
+ "Together",
66
89
  ]
@@ -90,6 +90,13 @@ def add_parser(subparsers: argparse._SubParsersAction[argparse.ArgumentParser])
90
90
  action="store_true",
91
91
  help="temperature for the LM",
92
92
  )
93
+ subparser.add_argument(
94
+ "--safety-model",
95
+ "-sm",
96
+ default=None,
97
+ type=str,
98
+ help="The name of the safety model to use for moderation.",
99
+ )
93
100
  subparser.set_defaults(func=_run_complete)
94
101
 
95
102
 
@@ -142,6 +149,7 @@ def _run_complete(args: argparse.Namespace) -> None:
142
149
  top_k=args.top_k,
143
150
  repetition_penalty=args.repetition_penalty,
144
151
  logprobs=args.logprobs,
152
+ safety_model=args.safety_model,
145
153
  )
146
154
  except together.AuthenticationError:
147
155
  logger.critical(together.MISSING_API_KEY_MESSAGE)
@@ -159,6 +167,7 @@ def _run_complete(args: argparse.Namespace) -> None:
159
167
  top_p=args.top_p,
160
168
  top_k=args.top_k,
161
169
  repetition_penalty=args.repetition_penalty,
170
+ safety_model=args.safety_model,
162
171
  raw=args.raw,
163
172
  ):
164
173
  if not args.raw:
@@ -1,7 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import argparse
4
- import json
5
4
 
6
5
  import together
7
6
  from together import Embeddings
@@ -42,7 +41,7 @@ def _run_complete(args: argparse.Namespace) -> None:
42
41
  model=args.model,
43
42
  )
44
43
 
45
- print(json.dumps(response, indent=4))
44
+ print([e.embedding for e in response.data])
46
45
  except together.AuthenticationError:
47
46
  logger.critical(together.MISSING_API_KEY_MESSAGE)
48
47
  exit(0)
together/complete.py CHANGED
@@ -24,6 +24,7 @@ class Complete:
24
24
  logprobs: Optional[int] = None,
25
25
  api_key: Optional[str] = None,
26
26
  cast: bool = False,
27
+ safety_model: Optional[str] = None,
27
28
  ) -> Union[Dict[str, Any], TogetherResponse]:
28
29
  if model == "":
29
30
  model = together.default_text_model
@@ -38,6 +39,7 @@ class Complete:
38
39
  "stop": stop,
39
40
  "repetition_penalty": repetition_penalty,
40
41
  "logprobs": logprobs,
42
+ "safety_model": safety_model,
41
43
  }
42
44
 
43
45
  # send request
@@ -70,6 +72,7 @@ class Complete:
70
72
  raw: Optional[bool] = False,
71
73
  api_key: Optional[str] = None,
72
74
  cast: Optional[bool] = False,
75
+ safety_model: Optional[str] = None,
73
76
  ) -> Union[Iterator[str], Iterator[TogetherResponse]]:
74
77
  """
75
78
  Prints streaming responses and returns the completed text.
@@ -88,6 +91,7 @@ class Complete:
88
91
  "stop": stop,
89
92
  "repetition_penalty": repetition_penalty,
90
93
  "stream_tokens": True,
94
+ "safety_model": safety_model,
91
95
  }
92
96
 
93
97
  # send request
together/embeddings.py CHANGED
@@ -1,4 +1,5 @@
1
- from typing import Any, Dict, Optional
1
+ import concurrent.futures
2
+ from typing import Any, Dict, List, Optional, Union
2
3
 
3
4
  import together
4
5
  from together.utils import create_post_request, get_logger
@@ -7,29 +8,57 @@ from together.utils import create_post_request, get_logger
7
8
  logger = get_logger(str(__name__))
8
9
 
9
10
 
11
+ class DataItem:
12
+ def __init__(self, embedding: List[float]):
13
+ self.embedding = embedding
14
+
15
+
16
+ class EmbeddingsOutput:
17
+ def __init__(self, data: List[DataItem]):
18
+ self.data = data
19
+
20
+
10
21
  class Embeddings:
11
22
  @classmethod
12
23
  def create(
13
- self,
14
- input: str,
24
+ cls,
25
+ input: Union[str, List[str]],
15
26
  model: Optional[str] = "",
16
- ) -> Dict[str, Any]:
27
+ ) -> EmbeddingsOutput:
17
28
  if model == "":
18
29
  model = together.default_embedding_model
19
30
 
20
- parameter_payload = {
21
- "input": input,
22
- "model": model,
23
- }
31
+ if isinstance(input, str):
32
+ parameter_payload = {
33
+ "input": input,
34
+ "model": model,
35
+ }
36
+
37
+ response = cls._process_input(parameter_payload)
38
+
39
+ return EmbeddingsOutput([DataItem(response["data"][0]["embedding"])])
24
40
 
41
+ elif isinstance(input, list):
42
+ # If input is a list, process each string concurrently
43
+ with concurrent.futures.ThreadPoolExecutor() as executor:
44
+ parameter_payloads = [{"input": item, "model": model} for item in input]
45
+ results = list(executor.map(cls._process_input, parameter_payloads))
46
+
47
+ return EmbeddingsOutput(
48
+ [DataItem(item["data"][0]["embedding"]) for item in results]
49
+ )
50
+
51
+ @classmethod
52
+ def _process_input(cls, parameter_payload: Dict[str, Any]) -> Dict[str, Any]:
25
53
  # send request
26
54
  response = create_post_request(
27
55
  url=together.api_base_embeddings, json=parameter_payload
28
56
  )
29
57
 
58
+ # return the json as a DotDict
30
59
  try:
31
60
  response_json = dict(response.json())
32
-
33
61
  except Exception as e:
34
62
  raise together.JSONError(e, http_status=response.status_code)
63
+
35
64
  return response_json
together/utils.py CHANGED
@@ -75,6 +75,18 @@ def parse_timestamp(timestamp: str) -> datetime:
75
75
  raise ValueError("Timestamp does not match any expected format")
76
76
 
77
77
 
78
+ def response_status_exception(response: requests.Response) -> None:
79
+ if response.status_code == 429:
80
+ raise together.RateLimitError(
81
+ message="Too many requests received. Please pace your requests."
82
+ )
83
+ elif response.status_code == 500:
84
+ raise Exception("server encountered an unexpected condition")
85
+ elif response.status_code == 401:
86
+ raise Exception("invalid authentication credentials")
87
+ response.raise_for_status()
88
+
89
+
78
90
  def create_post_request(
79
91
  url: str,
80
92
  headers: Optional[Dict[Any, Any]] = None,
@@ -99,15 +111,7 @@ def create_post_request(
99
111
  except requests.exceptions.RequestException as e:
100
112
  raise together.ResponseError(e)
101
113
 
102
- if response.status_code == 429:
103
- raise together.RateLimitError(
104
- message="Too many requests received. Please pace your requests."
105
- )
106
- elif response.status_code == 500:
107
- raise Exception("Invalid API key supplied.")
108
- elif response.status_code == 401:
109
- raise Exception("API Key not supplied")
110
- response.raise_for_status()
114
+ response_status_exception(response)
111
115
 
112
116
  return response
113
117
 
@@ -139,15 +143,7 @@ def create_get_request(
139
143
  except requests.exceptions.RequestException as e:
140
144
  raise together.ResponseError(e)
141
145
 
142
- if response.status_code == 429:
143
- raise together.RateLimitError(
144
- message="Too many requests received. Please pace your requests."
145
- )
146
- elif response.status_code == 500:
147
- raise Exception("Invalid API key supplied.")
148
- elif response.status_code == 401:
149
- raise Exception("API Key not supplied")
150
- response.raise_for_status()
146
+ response_status_exception(response)
151
147
 
152
148
  return response
153
149
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: together
3
- Version: 0.2.8
3
+ Version: 0.2.10
4
4
  Summary: Python client for Together's Cloud Platform!
5
5
  Home-page: https://github.com/togethercomputer/together
6
6
  License: Apache-2.0
@@ -481,16 +481,6 @@ print(output_text)
481
481
  Space Robots are a great way to get your kids interested in science. After all, they are the future!
482
482
  ```
483
483
 
484
- ## Embeddings API
485
-
486
- Embeddings are vector representations of sequences. You can use these vectors for measuring the overall similarity between texts. Embeddings are useful for tasks such as search and retrieval.
487
-
488
- ```python
489
- resp = together.Embeddings.create("embed this sentence into a single vector", model="togethercomputer/bert-base-uncased")
490
-
491
- print(resp['data'][0]['embedding']) # [0.06659205, 0.07896972, 0.007910785 ........]
492
- ```
493
-
494
484
  ## Colab Tutorial
495
485
 
496
486
  Follow along in our Colab (Google Colaboratory) Notebook Tutorial [Example Finetuning Project](https://colab.research.google.com/drive/11DwtftycpDSgp3Z1vnV-Cy68zvkGZL4K?usp=sharing).
@@ -1,16 +1,16 @@
1
- together/__init__.py,sha256=jm3pfhOf8VnPm64l6CN2Dpx_A4AkX-icbGOMvUE_lHo,1727
1
+ together/__init__.py,sha256=nSapPqW45Ik_ACPunhBnwabZ3YunW9FPTcoj0Ex9iyg,2251
2
2
  together/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  together/cli/cli.py,sha256=aALVTU7hhPdiSm0P175UXCwkBphP5DMi3mLEJ10K-1o,1655
4
4
  together/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  together/commands/chat.py,sha256=MbnTZz0rOAH6fwE_REL8SBvanzySmof8Tywna-UAtZE,4343
6
- together/commands/complete.py,sha256=5dhLkzQbmax34o0UizcxgzG2aiREM2Ii9lZ2je6zO6g,5554
7
- together/commands/embeddings.py,sha256=HzBh_SNtlmeUH3RuCNhPCLPjw1X_gSKgPu6-lRqs3P4,1181
6
+ together/commands/complete.py,sha256=GEH5SFyMQycfIu3ukbW5Pkj9CRm_htfskDjEwLZgXhE,5833
7
+ together/commands/embeddings.py,sha256=6JDz-Jd1lXSUWTb6ESKDnHPgjMXPP9YrDkJNPq82EaI,1175
8
8
  together/commands/files.py,sha256=nlM21PIklCD1ebc9Vlw5KKr8tyqwwfS4zw5BEj9UXAg,5890
9
9
  together/commands/finetune.py,sha256=4f-VZWnfZeRs39MvTnu_kYpoI53bpSmYtVbboY4N-C8,11240
10
10
  together/commands/image.py,sha256=2JWI597OO77nPJR9cBiJspZ74ijrCtZgcAF538H_AMA,4007
11
11
  together/commands/models.py,sha256=MOkn_IZw4NnhnQyFHAmRvXsqT9_tz26xLTD7mTuDO_E,6201
12
- together/complete.py,sha256=6fJ9lYP2hdvVVcllKSgOHetc755GtE3WGwagum-YfNY,5333
13
- together/embeddings.py,sha256=v7p4lSS6wQf6e2jncBeJQg3l-e6ae4kgVrMnvIfmnN8,815
12
+ together/complete.py,sha256=T51DEzvWVKrp6CnQyEwLTaaFbcZE25EJW8oGxXUWUnM,5505
13
+ together/embeddings.py,sha256=uIHVmvYMci-8CoNJCAXk9zcAFyhxZRuxv5Mw8tGOSrg,1884
14
14
  together/error.py,sha256=OlEuDG1E-O__fvKpwQ3mL3QxGNJ-OsMgmKwp-aJiG-4,2631
15
15
  together/files.py,sha256=1NFojMHHV8HfND2NmMVHhZcQljRM-iMLwXocnMJBRt0,12256
16
16
  together/finetune.py,sha256=VwYbhSwqwh0emCanHCoFTA9yu1zg4-0tBQQH9KFxfdA,12187
@@ -19,10 +19,10 @@ together/models.py,sha256=KQ-0OZ_H2-K8SPwhUwhFvDdRgBX4B48KQiPA3Sy9JhM,3072
19
19
  together/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
20
  together/tools/conversation.py,sha256=m_rt0VBkpweHV0DXZwQmaXeGGfnUr96fHqdRjabfLBk,1859
21
21
  together/types.py,sha256=8dVfnuA4zOXoKXf5lLZJmRTzkLbpajG_uPLTsdGfNF0,3063
22
- together/utils.py,sha256=hNT4ijYr1CVa3sn8gtFAbDcPyUe6U250Xn8a9XcfB_M,5334
22
+ together/utils.py,sha256=OEgwqky7P5NwkhA8ptsn0IRN5M4Z4UPT06uYeGOgKoQ,5144
23
23
  together/version.py,sha256=p03ivHyE0SyWU4jAnRTBi_sOwywVWoZPU4g2gzRgG-Y,126
24
- together-0.2.8.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
25
- together-0.2.8.dist-info/METADATA,sha256=URNmYONXxfwYozgmCQYp09WY-_KEaj_28uxJ8U5NJaw,27070
26
- together-0.2.8.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
27
- together-0.2.8.dist-info/entry_points.txt,sha256=G-b5NKW6lUUf1V1fH8IPTBb7jXnK7lhbX9H1zTEJXPs,50
28
- together-0.2.8.dist-info/RECORD,,
24
+ together-0.2.10.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
25
+ together-0.2.10.dist-info/METADATA,sha256=RtoA0wRDdqGCxscFSUHgNPk1OhaDfZLFXYJAyc8feyE,26635
26
+ together-0.2.10.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
27
+ together-0.2.10.dist-info/entry_points.txt,sha256=G-b5NKW6lUUf1V1fH8IPTBb7jXnK7lhbX9H1zTEJXPs,50
28
+ together-0.2.10.dist-info/RECORD,,