together 1.5.5__py3-none-any.whl → 1.5.6__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.
@@ -1,11 +1,12 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import Dict, Literal, Optional
3
+ from typing import Any, Dict, List, Literal, Optional
4
+ from pydantic import ValidationError
4
5
 
5
6
  from together.abstract import api_requestor
6
7
  from together.together_response import TogetherResponse
7
8
  from together.types import TogetherClient, TogetherRequest
8
- from together.types.code_interpreter import ExecuteResponse
9
+ from together.types.code_interpreter import ExecuteResponse, FileInput
9
10
 
10
11
 
11
12
  class CodeInterpreter:
@@ -19,22 +20,28 @@ class CodeInterpreter:
19
20
  code: str,
20
21
  language: Literal["python"],
21
22
  session_id: Optional[str] = None,
23
+ files: Optional[List[Dict[str, Any]]] = None,
22
24
  ) -> ExecuteResponse:
23
- """Execute a code snippet.
25
+ """Execute a code snippet, optionally with files.
24
26
 
25
27
  Args:
26
28
  code (str): Code snippet to execute
27
29
  language (str): Programming language for the code to execute. Currently only supports Python.
28
30
  session_id (str, optional): Identifier of the current session. Used to make follow-up calls.
31
+ files (List[Dict], optional): Files to upload to the session before executing the code.
29
32
 
30
33
  Returns:
31
34
  ExecuteResponse: Object containing execution results and outputs
35
+
36
+ Raises:
37
+ ValidationError: If any dictionary in the `files` list does not conform to the
38
+ required structure or types.
32
39
  """
33
40
  requestor = api_requestor.APIRequestor(
34
41
  client=self._client,
35
42
  )
36
43
 
37
- data: Dict[str, str] = {
44
+ data: Dict[str, Any] = {
38
45
  "code": code,
39
46
  "language": language,
40
47
  }
@@ -42,6 +49,23 @@ class CodeInterpreter:
42
49
  if session_id is not None:
43
50
  data["session_id"] = session_id
44
51
 
52
+ if files is not None:
53
+ serialized_files = []
54
+ try:
55
+ for file_dict in files:
56
+ # Validate the dictionary by creating a FileInput instance
57
+ validated_file = FileInput(**file_dict)
58
+ # Serialize the validated model back to a dict for the API call
59
+ serialized_files.append(validated_file.model_dump())
60
+ except ValidationError as e:
61
+ raise ValueError(f"Invalid file input format: {e}") from e
62
+ except TypeError as e:
63
+ raise ValueError(
64
+ f"Invalid file input: Each item in 'files' must be a dictionary. Error: {e}"
65
+ ) from e
66
+
67
+ data["files"] = serialized_files
68
+
45
69
  # Use absolute URL to bypass the /v1 prefix
46
70
  response, _, _ = requestor.request(
47
71
  options=TogetherRequest(
@@ -600,7 +600,7 @@ class FineTuning:
600
600
  raise ValueError(
601
601
  "Only DEFAULT checkpoint type is allowed for FullTrainingType"
602
602
  )
603
- url += "&checkpoint=modelOutputPath"
603
+ url += "&checkpoint=model_output_path"
604
604
  elif isinstance(ft_job.training_type, LoRATrainingType):
605
605
  if checkpoint_type == DownloadCheckpointType.DEFAULT:
606
606
  checkpoint_type = DownloadCheckpointType.MERGED
@@ -7,6 +7,16 @@ from pydantic import Field
7
7
  from together.types.endpoints import TogetherJSONModel
8
8
 
9
9
 
10
+ class FileInput(TogetherJSONModel):
11
+ """File input to be uploaded to the code interpreter session."""
12
+
13
+ name: str = Field(description="The name of the file.")
14
+ encoding: Literal["string", "base64"] = Field(
15
+ description="Encoding of the file content. Use 'string' for text files and 'base64' for binary files."
16
+ )
17
+ content: str = Field(description="The content of the file, encoded as specified.")
18
+
19
+
10
20
  class InterpreterOutput(TogetherJSONModel):
11
21
  """Base class for interpreter output types."""
12
22
 
@@ -40,6 +50,7 @@ class ExecuteResponse(TogetherJSONModel):
40
50
 
41
51
 
42
52
  __all__ = [
53
+ "FileInput",
43
54
  "InterpreterOutput",
44
55
  "ExecuteResponseData",
45
56
  "ExecuteResponse",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: together
3
- Version: 1.5.5
3
+ Version: 1.5.6
4
4
  Summary: Python client for Together's Cloud Platform!
5
5
  License: Apache-2.0
6
6
  Author: Together AI
@@ -23,7 +23,7 @@ Requires-Dist: pillow (>=11.1.0,<12.0.0)
23
23
  Requires-Dist: pyarrow (>=10.0.1)
24
24
  Requires-Dist: pydantic (>=2.6.3,<3.0.0)
25
25
  Requires-Dist: requests (>=2.31.0,<3.0.0)
26
- Requires-Dist: rich (>=13.8.1,<14.0.0)
26
+ Requires-Dist: rich (>=13.8.1,<15.0.0)
27
27
  Requires-Dist: tabulate (>=0.9.0,<0.10.0)
28
28
  Requires-Dist: tqdm (>=4.66.2,<5.0.0)
29
29
  Requires-Dist: typer (>=0.9,<0.16)
@@ -220,6 +220,30 @@ async def async_chat_completion(messages):
220
220
  asyncio.run(async_chat_completion(messages))
221
221
  ```
222
222
 
223
+ #### Fetching logprobs
224
+
225
+ Logprobs are logarithms of token-level generation probabilities that indicate the likelihood of the generated token based on the previous tokens in the context. Logprobs allow us to estimate the model's confidence in its outputs, which can be used to decide how to optimally consume the model's output (e.g. rejecting low confidence outputs, retrying or ensembling model outputs etc).
226
+
227
+ ```python
228
+ from together import Together
229
+
230
+ client = Together()
231
+
232
+ response = client.chat.completions.create(
233
+ model="mistralai/Mixtral-8x7B-Instruct-v0.1",
234
+ messages=[{"role": "user", "content": "tell me about new york"}],
235
+ logprobs=1
236
+ )
237
+
238
+ response_lobprobs = response.choices[0].logprobs
239
+
240
+ print(dict(zip(response_lobprobs.tokens, response_lobprobs.token_logprobs)))
241
+ # {'New': -2.384e-07, ' York': 0.0, ',': 0.0, ' also': -0.20703125, ' known': -0.20214844, ' as': -8.34465e-07, ... }
242
+ ```
243
+
244
+ More details about using logprobs in Together's API can be found [here](https://docs.together.ai/docs/logprobs).
245
+
246
+
223
247
  ### Completions
224
248
 
225
249
  Completions are for code and language models shown [here](https://docs.together.ai/docs/inference-models). Below, a code model example is shown.
@@ -29,12 +29,12 @@ together/resources/audio/__init__.py,sha256=e7xp0Lkp_nMAHXcuFHS7dLXP_YqTPMMZIilW
29
29
  together/resources/audio/speech.py,sha256=81ib_gIo-Rxoaipx2Pi9ZsKnOTjeFPwSlBrcUkyX5xk,5211
30
30
  together/resources/chat/__init__.py,sha256=RsTptdP8MeGjcdIjze896-J27cRvCbUoMft0X2BVlQ8,617
31
31
  together/resources/chat/completions.py,sha256=jYiNZsWa8RyEacL0VgxWj1egJ857oU4nxIY8uqGHcaU,14459
32
- together/resources/code_interpreter.py,sha256=gkzBgGZ6XckrUIB_ml0ju3_ACtNT3116cqYFeupyYKM,1788
32
+ together/resources/code_interpreter.py,sha256=vbN8Mh5MG6HQvqra7p61leIyfebgbgJTM_q2A_Fylhw,2948
33
33
  together/resources/completions.py,sha256=5Wa-ZjPCxRcam6CDe7KgGYlTA7yJZMmd5TrRgGCL_ug,11726
34
34
  together/resources/embeddings.py,sha256=PTvLb82yjG_-iQOyuhsilp77Fr7gZ0o6WD2KeRnKoxs,2675
35
35
  together/resources/endpoints.py,sha256=NNjp-wyzOotzlscGGrANhOHxQBjHTN8f5kTQTH_CLvE,17177
36
36
  together/resources/files.py,sha256=bnPbaF25e4InBRPvHwXHXT-oSX1Z1sZRsnQW5wq82U4,4990
37
- together/resources/finetune.py,sha256=LgU-6VvxTS-3tSpDt-rrd5MHXOnCE8irkmv7393eq-c,36373
37
+ together/resources/finetune.py,sha256=rBXcArgvaDZZnb-h2E-CXiVclZy2Njf3Ar49AczmCmg,36375
38
38
  together/resources/images.py,sha256=LQUjKPaFxWTqOAPnyF1Pp7Rz4NLOYhmoKwshpYiprEM,4923
39
39
  together/resources/models.py,sha256=qgmAXv61Cq4oLxytenEZBywA8shldDHYxJ_EAu_4JWQ,3864
40
40
  together/resources/rerank.py,sha256=3Ju_aRSyZ1s_3zCSNZnSnEJErUVmt2xa3M8z1nvejMA,3931
@@ -43,7 +43,7 @@ together/types/__init__.py,sha256=VgIbE2AOK9c2TQUzkbRbyRkdia2COXJXl_wxPaoxR-M,26
43
43
  together/types/abstract.py,sha256=1lFQI_3WjsR_t1128AeKW0aTk6EiM6Gh1J3ZuyLLPao,642
44
44
  together/types/audio_speech.py,sha256=jlj8BZf3dkIDARF1P11fuenVLj4try8Yx4RN-EAkhOU,2609
45
45
  together/types/chat_completions.py,sha256=ggwt1LlBXTB_hZKbtLsjg8j-gXxO8pUUQfTrxUmRXHU,5078
46
- together/types/code_interpreter.py,sha256=Ali8Prv9TXqcvCMeYffWbOsTmljs8sgvWIY3-kkcQ7M,1331
46
+ together/types/code_interpreter.py,sha256=cjF8TKgRkJllHS4i24dWQZBGTRsG557eHSewOiip0Kk,1770
47
47
  together/types/common.py,sha256=kxZ-N9xtBsGYZBmbIWnZ0rfT3Pn8PFB7sAbp3iv96pw,1525
48
48
  together/types/completions.py,sha256=o3FR5ixsTUj-a3pmOUzbSQg-hESVhpqrC9UD__VCqr4,2971
49
49
  together/types/embeddings.py,sha256=J7grkYYn7xhqeKaBO2T-8XQRtHhkzYzymovtGdIUK5A,751
@@ -60,8 +60,8 @@ together/utils/api_helpers.py,sha256=2K0O6qeEQ2zVFvi5NBN5m2kjZJaS3-JfKFecQ7SmGaw
60
60
  together/utils/files.py,sha256=rfp10qU0urtWOXXFeasFtO9xp-1KIhM3S43JxcnHmL0,16438
61
61
  together/utils/tools.py,sha256=H2MTJhEqtBllaDvOyZehIO_IVNK3P17rSDeILtJIVag,2964
62
62
  together/version.py,sha256=p03ivHyE0SyWU4jAnRTBi_sOwywVWoZPU4g2gzRgG-Y,126
63
- together-1.5.5.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
64
- together-1.5.5.dist-info/METADATA,sha256=A3mwKnEnrcaDD4D8iYpKj_XfmFUf3BZziEK5qiKWXyg,14397
65
- together-1.5.5.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
66
- together-1.5.5.dist-info/entry_points.txt,sha256=G-b5NKW6lUUf1V1fH8IPTBb7jXnK7lhbX9H1zTEJXPs,50
67
- together-1.5.5.dist-info/RECORD,,
63
+ together-1.5.6.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
64
+ together-1.5.6.dist-info/METADATA,sha256=4GMfmJ6K69OC_tCH7geARH5B1CNYL8IpP9NIi9IXxVQ,15415
65
+ together-1.5.6.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
66
+ together-1.5.6.dist-info/entry_points.txt,sha256=G-b5NKW6lUUf1V1fH8IPTBb7jXnK7lhbX9H1zTEJXPs,50
67
+ together-1.5.6.dist-info/RECORD,,