together 1.5.17__py3-none-any.whl → 2.0.0a8__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 +101 -63
- together/_base_client.py +1995 -0
- together/_client.py +1033 -0
- together/_compat.py +219 -0
- together/_constants.py +14 -0
- together/_exceptions.py +108 -0
- together/_files.py +123 -0
- together/_models.py +857 -0
- together/_qs.py +150 -0
- together/_resource.py +43 -0
- together/_response.py +830 -0
- together/_streaming.py +370 -0
- together/_types.py +260 -0
- together/_utils/__init__.py +64 -0
- together/_utils/_compat.py +45 -0
- together/_utils/_datetime_parse.py +136 -0
- together/_utils/_logs.py +25 -0
- together/_utils/_proxy.py +65 -0
- together/_utils/_reflection.py +42 -0
- together/_utils/_resources_proxy.py +24 -0
- together/_utils/_streams.py +12 -0
- together/_utils/_sync.py +58 -0
- together/_utils/_transform.py +457 -0
- together/_utils/_typing.py +156 -0
- together/_utils/_utils.py +421 -0
- together/_version.py +4 -0
- together/lib/.keep +4 -0
- together/lib/__init__.py +23 -0
- together/{cli → lib/cli}/api/endpoints.py +108 -75
- together/lib/cli/api/evals.py +588 -0
- together/{cli → lib/cli}/api/files.py +20 -17
- together/{cli/api/finetune.py → lib/cli/api/fine_tuning.py} +161 -120
- together/lib/cli/api/models.py +140 -0
- together/{cli → lib/cli}/api/utils.py +6 -7
- together/{cli → lib/cli}/cli.py +16 -24
- together/{constants.py → lib/constants.py} +17 -12
- together/lib/resources/__init__.py +11 -0
- together/lib/resources/files.py +999 -0
- together/lib/resources/fine_tuning.py +280 -0
- together/lib/resources/models.py +35 -0
- together/lib/types/__init__.py +13 -0
- together/lib/types/error.py +9 -0
- together/lib/types/fine_tuning.py +455 -0
- together/{utils → lib/utils}/__init__.py +6 -14
- together/{utils → lib/utils}/_log.py +11 -16
- together/lib/utils/files.py +628 -0
- together/lib/utils/serializer.py +10 -0
- together/{utils → lib/utils}/tools.py +19 -55
- together/resources/__init__.py +225 -33
- together/resources/audio/__init__.py +72 -21
- together/resources/audio/audio.py +198 -0
- together/resources/audio/speech.py +574 -122
- together/resources/audio/transcriptions.py +282 -0
- together/resources/audio/translations.py +256 -0
- together/resources/audio/voices.py +135 -0
- together/resources/batches.py +417 -0
- together/resources/chat/__init__.py +30 -21
- together/resources/chat/chat.py +102 -0
- together/resources/chat/completions.py +1063 -263
- together/resources/code_interpreter/__init__.py +33 -0
- together/resources/code_interpreter/code_interpreter.py +258 -0
- together/resources/code_interpreter/sessions.py +135 -0
- together/resources/completions.py +884 -225
- together/resources/embeddings.py +172 -68
- together/resources/endpoints.py +598 -395
- together/resources/evals.py +452 -0
- together/resources/files.py +398 -121
- together/resources/fine_tuning.py +1033 -0
- together/resources/hardware.py +181 -0
- together/resources/images.py +256 -108
- together/resources/jobs.py +214 -0
- together/resources/models.py +238 -90
- together/resources/rerank.py +190 -92
- together/resources/videos.py +374 -0
- together/types/__init__.py +65 -109
- together/types/audio/__init__.py +10 -0
- together/types/audio/speech_create_params.py +75 -0
- together/types/audio/transcription_create_params.py +54 -0
- together/types/audio/transcription_create_response.py +111 -0
- together/types/audio/translation_create_params.py +40 -0
- together/types/audio/translation_create_response.py +70 -0
- together/types/audio/voice_list_response.py +23 -0
- together/types/audio_speech_stream_chunk.py +16 -0
- together/types/autoscaling.py +13 -0
- together/types/autoscaling_param.py +15 -0
- together/types/batch_create_params.py +24 -0
- together/types/batch_create_response.py +14 -0
- together/types/batch_job.py +45 -0
- together/types/batch_list_response.py +10 -0
- together/types/chat/__init__.py +18 -0
- together/types/chat/chat_completion.py +60 -0
- together/types/chat/chat_completion_chunk.py +61 -0
- together/types/chat/chat_completion_structured_message_image_url_param.py +18 -0
- together/types/chat/chat_completion_structured_message_text_param.py +13 -0
- together/types/chat/chat_completion_structured_message_video_url_param.py +18 -0
- together/types/chat/chat_completion_usage.py +13 -0
- together/types/chat/chat_completion_warning.py +9 -0
- together/types/chat/completion_create_params.py +329 -0
- together/types/code_interpreter/__init__.py +5 -0
- together/types/code_interpreter/session_list_response.py +31 -0
- together/types/code_interpreter_execute_params.py +45 -0
- together/types/completion.py +42 -0
- together/types/completion_chunk.py +66 -0
- together/types/completion_create_params.py +138 -0
- together/types/dedicated_endpoint.py +44 -0
- together/types/embedding.py +24 -0
- together/types/embedding_create_params.py +31 -0
- together/types/endpoint_create_params.py +43 -0
- together/types/endpoint_list_avzones_response.py +11 -0
- together/types/endpoint_list_params.py +18 -0
- together/types/endpoint_list_response.py +41 -0
- together/types/endpoint_update_params.py +27 -0
- together/types/eval_create_params.py +263 -0
- together/types/eval_create_response.py +16 -0
- together/types/eval_list_params.py +21 -0
- together/types/eval_list_response.py +10 -0
- together/types/eval_status_response.py +100 -0
- together/types/evaluation_job.py +139 -0
- together/types/execute_response.py +108 -0
- together/types/file_delete_response.py +13 -0
- together/types/file_list.py +12 -0
- together/types/file_purpose.py +9 -0
- together/types/file_response.py +31 -0
- together/types/file_type.py +7 -0
- together/types/fine_tuning_cancel_response.py +194 -0
- together/types/fine_tuning_content_params.py +24 -0
- together/types/fine_tuning_delete_params.py +11 -0
- together/types/fine_tuning_delete_response.py +12 -0
- together/types/fine_tuning_list_checkpoints_response.py +21 -0
- together/types/fine_tuning_list_events_response.py +12 -0
- together/types/fine_tuning_list_response.py +199 -0
- together/types/finetune_event.py +41 -0
- together/types/finetune_event_type.py +33 -0
- together/types/finetune_response.py +177 -0
- together/types/hardware_list_params.py +16 -0
- together/types/hardware_list_response.py +58 -0
- together/types/image_data_b64.py +15 -0
- together/types/image_data_url.py +15 -0
- together/types/image_file.py +23 -0
- together/types/image_generate_params.py +85 -0
- together/types/job_list_response.py +47 -0
- together/types/job_retrieve_response.py +43 -0
- together/types/log_probs.py +18 -0
- together/types/model_list_response.py +10 -0
- together/types/model_object.py +42 -0
- together/types/model_upload_params.py +36 -0
- together/types/model_upload_response.py +23 -0
- together/types/rerank_create_params.py +36 -0
- together/types/rerank_create_response.py +36 -0
- together/types/tool_choice.py +23 -0
- together/types/tool_choice_param.py +23 -0
- together/types/tools_param.py +23 -0
- together/types/training_method_dpo.py +22 -0
- together/types/training_method_sft.py +18 -0
- together/types/video_create_params.py +86 -0
- together/types/video_job.py +57 -0
- together-2.0.0a8.dist-info/METADATA +680 -0
- together-2.0.0a8.dist-info/RECORD +164 -0
- {together-1.5.17.dist-info → together-2.0.0a8.dist-info}/WHEEL +1 -1
- together-2.0.0a8.dist-info/entry_points.txt +2 -0
- {together-1.5.17.dist-info → together-2.0.0a8.dist-info/licenses}/LICENSE +1 -1
- together/abstract/api_requestor.py +0 -729
- together/cli/api/chat.py +0 -276
- together/cli/api/completions.py +0 -119
- together/cli/api/images.py +0 -93
- together/cli/api/models.py +0 -55
- together/client.py +0 -176
- together/error.py +0 -194
- together/filemanager.py +0 -389
- together/legacy/__init__.py +0 -0
- together/legacy/base.py +0 -27
- together/legacy/complete.py +0 -93
- together/legacy/embeddings.py +0 -27
- together/legacy/files.py +0 -146
- together/legacy/finetune.py +0 -177
- together/legacy/images.py +0 -27
- together/legacy/models.py +0 -44
- together/resources/batch.py +0 -136
- together/resources/code_interpreter.py +0 -82
- together/resources/finetune.py +0 -1064
- together/together_response.py +0 -50
- together/types/abstract.py +0 -26
- together/types/audio_speech.py +0 -110
- together/types/batch.py +0 -53
- together/types/chat_completions.py +0 -197
- together/types/code_interpreter.py +0 -57
- together/types/common.py +0 -66
- together/types/completions.py +0 -107
- together/types/embeddings.py +0 -35
- together/types/endpoints.py +0 -123
- together/types/error.py +0 -16
- together/types/files.py +0 -90
- together/types/finetune.py +0 -398
- together/types/images.py +0 -44
- together/types/models.py +0 -45
- together/types/rerank.py +0 -43
- together/utils/api_helpers.py +0 -124
- together/utils/files.py +0 -425
- together/version.py +0 -6
- together-1.5.17.dist-info/METADATA +0 -525
- together-1.5.17.dist-info/RECORD +0 -69
- together-1.5.17.dist-info/entry_points.txt +0 -3
- /together/{abstract → lib/cli}/__init__.py +0 -0
- /together/{cli → lib/cli/api}/__init__.py +0 -0
- /together/{cli/api/__init__.py → py.typed} +0 -0
together/legacy/finetune.py
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import warnings
|
|
4
|
-
from typing import Any, Dict, List, Literal
|
|
5
|
-
|
|
6
|
-
import together
|
|
7
|
-
from together.legacy.base import API_KEY_WARNING, deprecated
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class Finetune:
|
|
11
|
-
@classmethod
|
|
12
|
-
@deprecated # type: ignore
|
|
13
|
-
def create(
|
|
14
|
-
cls,
|
|
15
|
-
training_file: str, # training file_id
|
|
16
|
-
model: str,
|
|
17
|
-
n_epochs: int = 1,
|
|
18
|
-
n_checkpoints: int | None = 1,
|
|
19
|
-
batch_size: int | None = 32,
|
|
20
|
-
learning_rate: float = 0.00001,
|
|
21
|
-
suffix: (
|
|
22
|
-
str | None
|
|
23
|
-
) = None, # resulting finetuned model name will include the suffix
|
|
24
|
-
estimate_price: bool = False,
|
|
25
|
-
wandb_api_key: str | None = None,
|
|
26
|
-
confirm_inputs: bool = False,
|
|
27
|
-
):
|
|
28
|
-
api_key = None
|
|
29
|
-
if together.api_key:
|
|
30
|
-
warnings.warn(API_KEY_WARNING)
|
|
31
|
-
api_key = together.api_key
|
|
32
|
-
|
|
33
|
-
if estimate_price:
|
|
34
|
-
raise ValueError("Price estimation is not supported in version >= 1.0.1")
|
|
35
|
-
|
|
36
|
-
if confirm_inputs:
|
|
37
|
-
raise ValueError("Input confirmation is not supported in version >= 1.0.1")
|
|
38
|
-
|
|
39
|
-
client = together.Together(api_key=api_key)
|
|
40
|
-
|
|
41
|
-
return client.fine_tuning.create(
|
|
42
|
-
training_file=training_file,
|
|
43
|
-
model=model,
|
|
44
|
-
n_epochs=n_epochs,
|
|
45
|
-
n_checkpoints=n_checkpoints,
|
|
46
|
-
batch_size=batch_size if isinstance(batch_size, int) else "max",
|
|
47
|
-
learning_rate=learning_rate,
|
|
48
|
-
suffix=suffix,
|
|
49
|
-
wandb_api_key=wandb_api_key,
|
|
50
|
-
).model_dump(exclude_none=True)
|
|
51
|
-
|
|
52
|
-
@classmethod
|
|
53
|
-
@deprecated # type: ignore
|
|
54
|
-
def list(
|
|
55
|
-
cls,
|
|
56
|
-
) -> Dict[str, Any]:
|
|
57
|
-
"""Legacy finetuning list function."""
|
|
58
|
-
|
|
59
|
-
api_key = None
|
|
60
|
-
if together.api_key:
|
|
61
|
-
warnings.warn(API_KEY_WARNING)
|
|
62
|
-
api_key = together.api_key
|
|
63
|
-
|
|
64
|
-
client = together.Together(api_key=api_key)
|
|
65
|
-
|
|
66
|
-
return client.fine_tuning.list().model_dump(exclude_none=True)
|
|
67
|
-
|
|
68
|
-
@classmethod
|
|
69
|
-
@deprecated # type: ignore
|
|
70
|
-
def retrieve(
|
|
71
|
-
cls,
|
|
72
|
-
fine_tune_id: str,
|
|
73
|
-
) -> Dict[str, Any]:
|
|
74
|
-
"""Legacy finetuning retrieve function."""
|
|
75
|
-
|
|
76
|
-
api_key = None
|
|
77
|
-
if together.api_key:
|
|
78
|
-
warnings.warn(API_KEY_WARNING)
|
|
79
|
-
api_key = together.api_key
|
|
80
|
-
|
|
81
|
-
client = together.Together(api_key=api_key)
|
|
82
|
-
|
|
83
|
-
return client.fine_tuning.retrieve(id=fine_tune_id).model_dump(
|
|
84
|
-
exclude_none=True
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
@classmethod
|
|
88
|
-
@deprecated # type: ignore
|
|
89
|
-
def cancel(
|
|
90
|
-
cls,
|
|
91
|
-
fine_tune_id: str,
|
|
92
|
-
) -> Dict[str, Any]:
|
|
93
|
-
"""Legacy finetuning cancel function."""
|
|
94
|
-
|
|
95
|
-
api_key = None
|
|
96
|
-
if together.api_key:
|
|
97
|
-
warnings.warn(API_KEY_WARNING)
|
|
98
|
-
api_key = together.api_key
|
|
99
|
-
|
|
100
|
-
client = together.Together(api_key=api_key)
|
|
101
|
-
|
|
102
|
-
return client.fine_tuning.cancel(id=fine_tune_id).model_dump(exclude_none=True)
|
|
103
|
-
|
|
104
|
-
@classmethod
|
|
105
|
-
@deprecated # type: ignore
|
|
106
|
-
def list_events(
|
|
107
|
-
cls,
|
|
108
|
-
fine_tune_id: str,
|
|
109
|
-
) -> Dict[str, Any]:
|
|
110
|
-
"""Legacy finetuning list events function."""
|
|
111
|
-
|
|
112
|
-
api_key = None
|
|
113
|
-
if together.api_key:
|
|
114
|
-
warnings.warn(API_KEY_WARNING)
|
|
115
|
-
api_key = together.api_key
|
|
116
|
-
|
|
117
|
-
client = together.Together(api_key=api_key)
|
|
118
|
-
|
|
119
|
-
return client.fine_tuning.list_events(id=fine_tune_id).model_dump(
|
|
120
|
-
exclude_none=True
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
@classmethod
|
|
124
|
-
@deprecated # type: ignore
|
|
125
|
-
def get_checkpoints(
|
|
126
|
-
cls,
|
|
127
|
-
fine_tune_id: str,
|
|
128
|
-
) -> List[Any]:
|
|
129
|
-
"""Legacy finetuning get checkpoints function."""
|
|
130
|
-
|
|
131
|
-
finetune_events = list(cls.retrieve(fine_tune_id=fine_tune_id)["events"])
|
|
132
|
-
|
|
133
|
-
saved_events = [i for i in finetune_events if i["type"] in ["CHECKPOINT_SAVE"]]
|
|
134
|
-
|
|
135
|
-
return saved_events
|
|
136
|
-
|
|
137
|
-
@classmethod
|
|
138
|
-
@deprecated # type: ignore
|
|
139
|
-
def get_job_status(cls, fine_tune_id: str) -> str:
|
|
140
|
-
"""Legacy finetuning get job status function."""
|
|
141
|
-
return str(cls.retrieve(fine_tune_id=fine_tune_id)["status"])
|
|
142
|
-
|
|
143
|
-
@classmethod
|
|
144
|
-
@deprecated # type: ignore
|
|
145
|
-
def is_final_model_available(cls, fine_tune_id: str) -> bool:
|
|
146
|
-
"""Legacy finetuning is final model available function."""
|
|
147
|
-
|
|
148
|
-
finetune_events = list(cls.retrieve(fine_tune_id=fine_tune_id)["events"])
|
|
149
|
-
|
|
150
|
-
for i in finetune_events:
|
|
151
|
-
if i["type"] in ["JOB_COMPLETE", "JOB_ERROR"]:
|
|
152
|
-
if i["checkpoint_path"] != "":
|
|
153
|
-
return False
|
|
154
|
-
else:
|
|
155
|
-
return True
|
|
156
|
-
return False
|
|
157
|
-
|
|
158
|
-
@classmethod
|
|
159
|
-
@deprecated # type: ignore
|
|
160
|
-
def download(
|
|
161
|
-
cls,
|
|
162
|
-
fine_tune_id: str,
|
|
163
|
-
output: str | None = None,
|
|
164
|
-
step: int | None = None,
|
|
165
|
-
) -> Dict[str, Any]:
|
|
166
|
-
"""Legacy finetuning download function."""
|
|
167
|
-
|
|
168
|
-
api_key = None
|
|
169
|
-
if together.api_key:
|
|
170
|
-
warnings.warn(API_KEY_WARNING)
|
|
171
|
-
api_key = together.api_key
|
|
172
|
-
|
|
173
|
-
client = together.Together(api_key=api_key)
|
|
174
|
-
|
|
175
|
-
return client.fine_tuning.download(
|
|
176
|
-
id=fine_tune_id, output=output, checkpoint_step=step
|
|
177
|
-
).model_dump(exclude_none=True)
|
together/legacy/images.py
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import warnings
|
|
2
|
-
from typing import Any, Dict
|
|
3
|
-
|
|
4
|
-
import together
|
|
5
|
-
from together.legacy.base import API_KEY_WARNING, deprecated
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class Image:
|
|
9
|
-
@classmethod
|
|
10
|
-
@deprecated # type: ignore
|
|
11
|
-
def create(
|
|
12
|
-
cls,
|
|
13
|
-
prompt: str,
|
|
14
|
-
**kwargs: Any,
|
|
15
|
-
) -> Dict[str, Any]:
|
|
16
|
-
"""Legacy image function."""
|
|
17
|
-
|
|
18
|
-
api_key = None
|
|
19
|
-
if together.api_key:
|
|
20
|
-
warnings.warn(API_KEY_WARNING)
|
|
21
|
-
api_key = together.api_key
|
|
22
|
-
|
|
23
|
-
client = together.Together(api_key=api_key)
|
|
24
|
-
|
|
25
|
-
return client.images.generate(prompt=prompt, **kwargs).model_dump(
|
|
26
|
-
exclude_none=True
|
|
27
|
-
)
|
together/legacy/models.py
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import warnings
|
|
2
|
-
from typing import Any, Dict, List
|
|
3
|
-
|
|
4
|
-
import together
|
|
5
|
-
from together.legacy.base import API_KEY_WARNING, deprecated
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class Models:
|
|
9
|
-
@classmethod
|
|
10
|
-
@deprecated # type: ignore
|
|
11
|
-
def list(
|
|
12
|
-
cls,
|
|
13
|
-
) -> List[Dict[str, Any]]:
|
|
14
|
-
"""Legacy model list function."""
|
|
15
|
-
|
|
16
|
-
api_key = None
|
|
17
|
-
if together.api_key:
|
|
18
|
-
warnings.warn(API_KEY_WARNING)
|
|
19
|
-
api_key = together.api_key
|
|
20
|
-
|
|
21
|
-
client = together.Together(api_key=api_key)
|
|
22
|
-
|
|
23
|
-
return [item.model_dump(exclude_none=True) for item in client.models.list()]
|
|
24
|
-
|
|
25
|
-
@classmethod
|
|
26
|
-
@deprecated # type: ignore
|
|
27
|
-
def info(
|
|
28
|
-
cls,
|
|
29
|
-
model: str,
|
|
30
|
-
) -> Dict[str, Any]:
|
|
31
|
-
"""Legacy model info function."""
|
|
32
|
-
|
|
33
|
-
api_key = None
|
|
34
|
-
if together.api_key:
|
|
35
|
-
warnings.warn(API_KEY_WARNING)
|
|
36
|
-
api_key = together.api_key
|
|
37
|
-
|
|
38
|
-
client = together.Together(api_key=api_key)
|
|
39
|
-
|
|
40
|
-
model_list = client.models.list()
|
|
41
|
-
|
|
42
|
-
for item in model_list:
|
|
43
|
-
if item.id == model:
|
|
44
|
-
return item.model_dump(exclude_none=True)
|
together/resources/batch.py
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from typing import List
|
|
4
|
-
|
|
5
|
-
from together.abstract import api_requestor
|
|
6
|
-
from together.together_response import TogetherResponse
|
|
7
|
-
from together.types import (
|
|
8
|
-
TogetherClient,
|
|
9
|
-
TogetherRequest,
|
|
10
|
-
BatchJob,
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class Batches:
|
|
15
|
-
def __init__(self, client: TogetherClient) -> None:
|
|
16
|
-
self._client = client
|
|
17
|
-
|
|
18
|
-
def create_batch(self, file_id: str, endpoint: str) -> BatchJob:
|
|
19
|
-
|
|
20
|
-
requestor = api_requestor.APIRequestor(
|
|
21
|
-
client=self._client,
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
parameter_payload = {
|
|
25
|
-
"input_file_id": file_id,
|
|
26
|
-
"endpoint": endpoint,
|
|
27
|
-
"completion_window": "24h",
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
response, _, _ = requestor.request(
|
|
31
|
-
options=TogetherRequest(
|
|
32
|
-
method="POST",
|
|
33
|
-
url=f"batches",
|
|
34
|
-
params=parameter_payload,
|
|
35
|
-
),
|
|
36
|
-
stream=False,
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
assert isinstance(response, TogetherResponse)
|
|
40
|
-
response_body = response.data.get("job", {})
|
|
41
|
-
return BatchJob(**response_body)
|
|
42
|
-
|
|
43
|
-
def get_batch(self, batch_job_id: str) -> BatchJob:
|
|
44
|
-
requestor = api_requestor.APIRequestor(
|
|
45
|
-
client=self._client,
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
response, _, _ = requestor.request(
|
|
49
|
-
options=TogetherRequest(
|
|
50
|
-
method="GET",
|
|
51
|
-
url=f"batches/{batch_job_id}",
|
|
52
|
-
),
|
|
53
|
-
stream=False,
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
assert isinstance(response, TogetherResponse)
|
|
57
|
-
return BatchJob(**response.data)
|
|
58
|
-
|
|
59
|
-
def list_batches(self) -> List[BatchJob]:
|
|
60
|
-
requestor = api_requestor.APIRequestor(
|
|
61
|
-
client=self._client,
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
response, _, _ = requestor.request(
|
|
65
|
-
options=TogetherRequest(
|
|
66
|
-
method="GET",
|
|
67
|
-
url="batches",
|
|
68
|
-
),
|
|
69
|
-
stream=False,
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
assert isinstance(response, TogetherResponse)
|
|
73
|
-
jobs = response.data or []
|
|
74
|
-
return [BatchJob(**job) for job in jobs]
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
class AsyncBatches:
|
|
78
|
-
def __init__(self, client: TogetherClient) -> None:
|
|
79
|
-
self._client = client
|
|
80
|
-
|
|
81
|
-
async def create_batch(self, file_id: str, endpoint: str) -> BatchJob:
|
|
82
|
-
requestor = api_requestor.APIRequestor(
|
|
83
|
-
client=self._client,
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
parameter_payload = {
|
|
87
|
-
"input_file_id": file_id,
|
|
88
|
-
"endpoint": endpoint,
|
|
89
|
-
"completion_window": "24h",
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
response, _, _ = await requestor.arequest(
|
|
93
|
-
options=TogetherRequest(
|
|
94
|
-
method="POST",
|
|
95
|
-
url=f"batches",
|
|
96
|
-
params=parameter_payload,
|
|
97
|
-
),
|
|
98
|
-
stream=False,
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
assert isinstance(response, TogetherResponse)
|
|
102
|
-
response_body = response.data.get("job", {})
|
|
103
|
-
return BatchJob(**response_body)
|
|
104
|
-
|
|
105
|
-
async def get_batch(self, batch_job_id: str) -> BatchJob:
|
|
106
|
-
requestor = api_requestor.APIRequestor(
|
|
107
|
-
client=self._client,
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
response, _, _ = await requestor.arequest(
|
|
111
|
-
options=TogetherRequest(
|
|
112
|
-
method="GET",
|
|
113
|
-
url=f"batches/{batch_job_id}",
|
|
114
|
-
),
|
|
115
|
-
stream=False,
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
assert isinstance(response, TogetherResponse)
|
|
119
|
-
return BatchJob(**response.data)
|
|
120
|
-
|
|
121
|
-
async def list_batches(self) -> List[BatchJob]:
|
|
122
|
-
requestor = api_requestor.APIRequestor(
|
|
123
|
-
client=self._client,
|
|
124
|
-
)
|
|
125
|
-
|
|
126
|
-
response, _, _ = await requestor.arequest(
|
|
127
|
-
options=TogetherRequest(
|
|
128
|
-
method="GET",
|
|
129
|
-
url="batches",
|
|
130
|
-
),
|
|
131
|
-
stream=False,
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
assert isinstance(response, TogetherResponse)
|
|
135
|
-
jobs = response.data or []
|
|
136
|
-
return [BatchJob(**job) for job in jobs]
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from typing import Any, Dict, List, Literal, Optional
|
|
4
|
-
from pydantic import ValidationError
|
|
5
|
-
|
|
6
|
-
from together.abstract import api_requestor
|
|
7
|
-
from together.together_response import TogetherResponse
|
|
8
|
-
from together.types import TogetherClient, TogetherRequest
|
|
9
|
-
from together.types.code_interpreter import ExecuteResponse, FileInput
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class CodeInterpreter:
|
|
13
|
-
"""Code Interpreter resource for executing code snippets."""
|
|
14
|
-
|
|
15
|
-
def __init__(self, client: TogetherClient) -> None:
|
|
16
|
-
self._client = client
|
|
17
|
-
|
|
18
|
-
def run(
|
|
19
|
-
self,
|
|
20
|
-
code: str,
|
|
21
|
-
language: Literal["python"],
|
|
22
|
-
session_id: Optional[str] = None,
|
|
23
|
-
files: Optional[List[Dict[str, Any]]] = None,
|
|
24
|
-
) -> ExecuteResponse:
|
|
25
|
-
"""Execute a code snippet, optionally with files.
|
|
26
|
-
|
|
27
|
-
Args:
|
|
28
|
-
code (str): Code snippet to execute
|
|
29
|
-
language (str): Programming language for the code to execute. Currently only supports Python.
|
|
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.
|
|
32
|
-
|
|
33
|
-
Returns:
|
|
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.
|
|
39
|
-
"""
|
|
40
|
-
requestor = api_requestor.APIRequestor(
|
|
41
|
-
client=self._client,
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
data: Dict[str, Any] = {
|
|
45
|
-
"code": code,
|
|
46
|
-
"language": language,
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if session_id is not None:
|
|
50
|
-
data["session_id"] = session_id
|
|
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
|
-
|
|
69
|
-
# Use absolute URL to bypass the /v1 prefix
|
|
70
|
-
response, _, _ = requestor.request(
|
|
71
|
-
options=TogetherRequest(
|
|
72
|
-
method="POST",
|
|
73
|
-
url="/tci/execute",
|
|
74
|
-
params=data,
|
|
75
|
-
),
|
|
76
|
-
stream=False,
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
assert isinstance(response, TogetherResponse)
|
|
80
|
-
|
|
81
|
-
# Return the response data directly since our types match the API structure
|
|
82
|
-
return ExecuteResponse(**response.data)
|