together 1.5.34__py3-none-any.whl → 2.0.0a6__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.
Files changed (208) hide show
  1. together/__init__.py +101 -114
  2. together/_base_client.py +1995 -0
  3. together/_client.py +1033 -0
  4. together/_compat.py +219 -0
  5. together/_constants.py +14 -0
  6. together/_exceptions.py +108 -0
  7. together/_files.py +123 -0
  8. together/_models.py +857 -0
  9. together/_qs.py +150 -0
  10. together/_resource.py +43 -0
  11. together/_response.py +830 -0
  12. together/_streaming.py +370 -0
  13. together/_types.py +260 -0
  14. together/_utils/__init__.py +64 -0
  15. together/_utils/_compat.py +45 -0
  16. together/_utils/_datetime_parse.py +136 -0
  17. together/_utils/_logs.py +25 -0
  18. together/_utils/_proxy.py +65 -0
  19. together/_utils/_reflection.py +42 -0
  20. together/_utils/_resources_proxy.py +24 -0
  21. together/_utils/_streams.py +12 -0
  22. together/_utils/_sync.py +58 -0
  23. together/_utils/_transform.py +457 -0
  24. together/_utils/_typing.py +156 -0
  25. together/_utils/_utils.py +421 -0
  26. together/_version.py +4 -0
  27. together/lib/.keep +4 -0
  28. together/lib/__init__.py +23 -0
  29. together/{cli → lib/cli}/api/endpoints.py +65 -81
  30. together/{cli/api/evaluation.py → lib/cli/api/evals.py} +152 -43
  31. together/{cli → lib/cli}/api/files.py +20 -17
  32. together/{cli/api/finetune.py → lib/cli/api/fine_tuning.py} +116 -172
  33. together/{cli → lib/cli}/api/models.py +34 -27
  34. together/lib/cli/api/utils.py +50 -0
  35. together/{cli → lib/cli}/cli.py +16 -26
  36. together/{constants.py → lib/constants.py} +11 -24
  37. together/lib/resources/__init__.py +11 -0
  38. together/lib/resources/files.py +999 -0
  39. together/lib/resources/fine_tuning.py +280 -0
  40. together/lib/resources/models.py +35 -0
  41. together/lib/types/__init__.py +13 -0
  42. together/lib/types/error.py +9 -0
  43. together/lib/types/fine_tuning.py +397 -0
  44. together/{utils → lib/utils}/__init__.py +6 -14
  45. together/{utils → lib/utils}/_log.py +11 -16
  46. together/{utils → lib/utils}/files.py +90 -288
  47. together/lib/utils/serializer.py +10 -0
  48. together/{utils → lib/utils}/tools.py +19 -55
  49. together/resources/__init__.py +225 -39
  50. together/resources/audio/__init__.py +72 -48
  51. together/resources/audio/audio.py +198 -0
  52. together/resources/audio/speech.py +574 -128
  53. together/resources/audio/transcriptions.py +247 -261
  54. together/resources/audio/translations.py +221 -241
  55. together/resources/audio/voices.py +111 -41
  56. together/resources/batches.py +417 -0
  57. together/resources/chat/__init__.py +30 -21
  58. together/resources/chat/chat.py +102 -0
  59. together/resources/chat/completions.py +1063 -263
  60. together/resources/code_interpreter/__init__.py +33 -0
  61. together/resources/code_interpreter/code_interpreter.py +258 -0
  62. together/resources/code_interpreter/sessions.py +135 -0
  63. together/resources/completions.py +884 -225
  64. together/resources/embeddings.py +172 -68
  65. together/resources/endpoints.py +589 -477
  66. together/resources/evals.py +452 -0
  67. together/resources/files.py +397 -129
  68. together/resources/fine_tuning.py +1033 -0
  69. together/resources/hardware.py +181 -0
  70. together/resources/images.py +258 -104
  71. together/resources/jobs.py +214 -0
  72. together/resources/models.py +223 -193
  73. together/resources/rerank.py +190 -92
  74. together/resources/videos.py +286 -214
  75. together/types/__init__.py +66 -167
  76. together/types/audio/__init__.py +10 -0
  77. together/types/audio/speech_create_params.py +75 -0
  78. together/types/audio/transcription_create_params.py +54 -0
  79. together/types/audio/transcription_create_response.py +111 -0
  80. together/types/audio/translation_create_params.py +40 -0
  81. together/types/audio/translation_create_response.py +70 -0
  82. together/types/audio/voice_list_response.py +23 -0
  83. together/types/audio_speech_stream_chunk.py +16 -0
  84. together/types/autoscaling.py +13 -0
  85. together/types/autoscaling_param.py +15 -0
  86. together/types/batch_create_params.py +24 -0
  87. together/types/batch_create_response.py +14 -0
  88. together/types/batch_job.py +45 -0
  89. together/types/batch_list_response.py +10 -0
  90. together/types/chat/__init__.py +18 -0
  91. together/types/chat/chat_completion.py +60 -0
  92. together/types/chat/chat_completion_chunk.py +61 -0
  93. together/types/chat/chat_completion_structured_message_image_url_param.py +18 -0
  94. together/types/chat/chat_completion_structured_message_text_param.py +13 -0
  95. together/types/chat/chat_completion_structured_message_video_url_param.py +18 -0
  96. together/types/chat/chat_completion_usage.py +13 -0
  97. together/types/chat/chat_completion_warning.py +9 -0
  98. together/types/chat/completion_create_params.py +329 -0
  99. together/types/code_interpreter/__init__.py +5 -0
  100. together/types/code_interpreter/session_list_response.py +31 -0
  101. together/types/code_interpreter_execute_params.py +45 -0
  102. together/types/completion.py +42 -0
  103. together/types/completion_chunk.py +66 -0
  104. together/types/completion_create_params.py +138 -0
  105. together/types/dedicated_endpoint.py +44 -0
  106. together/types/embedding.py +24 -0
  107. together/types/embedding_create_params.py +31 -0
  108. together/types/endpoint_create_params.py +43 -0
  109. together/types/endpoint_list_avzones_response.py +11 -0
  110. together/types/endpoint_list_params.py +18 -0
  111. together/types/endpoint_list_response.py +41 -0
  112. together/types/endpoint_update_params.py +27 -0
  113. together/types/eval_create_params.py +263 -0
  114. together/types/eval_create_response.py +16 -0
  115. together/types/eval_list_params.py +21 -0
  116. together/types/eval_list_response.py +10 -0
  117. together/types/eval_status_response.py +100 -0
  118. together/types/evaluation_job.py +139 -0
  119. together/types/execute_response.py +108 -0
  120. together/types/file_delete_response.py +13 -0
  121. together/types/file_list.py +12 -0
  122. together/types/file_purpose.py +9 -0
  123. together/types/file_response.py +31 -0
  124. together/types/file_type.py +7 -0
  125. together/types/fine_tuning_cancel_response.py +194 -0
  126. together/types/fine_tuning_content_params.py +24 -0
  127. together/types/fine_tuning_delete_params.py +11 -0
  128. together/types/fine_tuning_delete_response.py +12 -0
  129. together/types/fine_tuning_list_checkpoints_response.py +21 -0
  130. together/types/fine_tuning_list_events_response.py +12 -0
  131. together/types/fine_tuning_list_response.py +199 -0
  132. together/types/finetune_event.py +41 -0
  133. together/types/finetune_event_type.py +33 -0
  134. together/types/finetune_response.py +177 -0
  135. together/types/hardware_list_params.py +16 -0
  136. together/types/hardware_list_response.py +58 -0
  137. together/types/image_data_b64.py +15 -0
  138. together/types/image_data_url.py +15 -0
  139. together/types/image_file.py +23 -0
  140. together/types/image_generate_params.py +85 -0
  141. together/types/job_list_response.py +47 -0
  142. together/types/job_retrieve_response.py +43 -0
  143. together/types/log_probs.py +18 -0
  144. together/types/model_list_response.py +10 -0
  145. together/types/model_object.py +42 -0
  146. together/types/model_upload_params.py +36 -0
  147. together/types/model_upload_response.py +23 -0
  148. together/types/rerank_create_params.py +36 -0
  149. together/types/rerank_create_response.py +36 -0
  150. together/types/tool_choice.py +23 -0
  151. together/types/tool_choice_param.py +23 -0
  152. together/types/tools_param.py +23 -0
  153. together/types/training_method_dpo.py +22 -0
  154. together/types/training_method_sft.py +18 -0
  155. together/types/video_create_params.py +86 -0
  156. together/types/video_create_response.py +10 -0
  157. together/types/video_job.py +57 -0
  158. together-2.0.0a6.dist-info/METADATA +729 -0
  159. together-2.0.0a6.dist-info/RECORD +165 -0
  160. {together-1.5.34.dist-info → together-2.0.0a6.dist-info}/WHEEL +1 -1
  161. together-2.0.0a6.dist-info/entry_points.txt +2 -0
  162. {together-1.5.34.dist-info → together-2.0.0a6.dist-info}/licenses/LICENSE +1 -1
  163. together/abstract/api_requestor.py +0 -770
  164. together/cli/api/chat.py +0 -298
  165. together/cli/api/completions.py +0 -119
  166. together/cli/api/images.py +0 -93
  167. together/cli/api/utils.py +0 -139
  168. together/client.py +0 -186
  169. together/error.py +0 -194
  170. together/filemanager.py +0 -635
  171. together/legacy/__init__.py +0 -0
  172. together/legacy/base.py +0 -27
  173. together/legacy/complete.py +0 -93
  174. together/legacy/embeddings.py +0 -27
  175. together/legacy/files.py +0 -146
  176. together/legacy/finetune.py +0 -177
  177. together/legacy/images.py +0 -27
  178. together/legacy/models.py +0 -44
  179. together/resources/batch.py +0 -165
  180. together/resources/code_interpreter.py +0 -82
  181. together/resources/evaluation.py +0 -808
  182. together/resources/finetune.py +0 -1388
  183. together/together_response.py +0 -50
  184. together/types/abstract.py +0 -26
  185. together/types/audio_speech.py +0 -311
  186. together/types/batch.py +0 -54
  187. together/types/chat_completions.py +0 -210
  188. together/types/code_interpreter.py +0 -57
  189. together/types/common.py +0 -67
  190. together/types/completions.py +0 -107
  191. together/types/embeddings.py +0 -35
  192. together/types/endpoints.py +0 -123
  193. together/types/error.py +0 -16
  194. together/types/evaluation.py +0 -93
  195. together/types/files.py +0 -93
  196. together/types/finetune.py +0 -464
  197. together/types/images.py +0 -42
  198. together/types/models.py +0 -96
  199. together/types/rerank.py +0 -43
  200. together/types/videos.py +0 -69
  201. together/utils/api_helpers.py +0 -124
  202. together/version.py +0 -6
  203. together-1.5.34.dist-info/METADATA +0 -583
  204. together-1.5.34.dist-info/RECORD +0 -77
  205. together-1.5.34.dist-info/entry_points.txt +0 -3
  206. /together/{abstract → lib/cli}/__init__.py +0 -0
  207. /together/{cli → lib/cli/api}/__init__.py +0 -0
  208. /together/{cli/api/__init__.py → py.typed} +0 -0
@@ -1,808 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from typing import Any, Dict, List, Optional, Union
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
- )
11
- from together.types.evaluation import (
12
- ClassifyParameters,
13
- CompareParameters,
14
- EvaluationCreateResponse,
15
- EvaluationJob,
16
- EvaluationStatusResponse,
17
- JudgeModelConfig,
18
- ModelRequest,
19
- ScoreParameters,
20
- )
21
-
22
-
23
- class Evaluation:
24
- def __init__(self, client: TogetherClient) -> None:
25
- self._client = client
26
-
27
- def create(
28
- self,
29
- type: str,
30
- judge_model: str,
31
- judge_model_source: str,
32
- judge_system_template: str,
33
- input_data_file_path: str,
34
- judge_external_api_token: Optional[str] = None,
35
- judge_external_base_url: Optional[str] = None,
36
- # Classify-specific parameters
37
- labels: Optional[List[str]] = None,
38
- pass_labels: Optional[List[str]] = None,
39
- # Score-specific parameters
40
- min_score: Optional[float] = None,
41
- max_score: Optional[float] = None,
42
- pass_threshold: Optional[float] = None,
43
- # Compare-specific parameters (model_a and model_b handled below)
44
- # Common optional parameters
45
- model_a: Optional[Union[str, Dict[str, Any]]] = None,
46
- model_b: Optional[Union[str, Dict[str, Any]]] = None,
47
- model_to_evaluate: Optional[Union[str, Dict[str, Any]]] = None,
48
- ) -> EvaluationCreateResponse:
49
- """
50
- Create a new evaluation job.
51
-
52
- Args:
53
- type: The type of evaluation ("classify", "score", or "compare")
54
- judge_model: Name or URL of the judge model
55
- judge_model_source: Source of the judge model ("serverless", "dedicated", or "external")
56
- judge_system_template: System template for the judge
57
- input_data_file_path: Path to input data file
58
- judge_external_api_token: Optional external API token for the judge model
59
- judge_external_base_url: Optional external base URLs for the judge model
60
- labels: List of classification labels (required for classify)
61
- pass_labels: List of labels considered as passing (required for classify)
62
- min_score: Minimum score value (required for score)
63
- max_score: Maximum score value (required for score)
64
- pass_threshold: Threshold score for passing (required for score)
65
- model_to_evaluate: Model to evaluate for classify/score types
66
- model_a: Model A for compare type
67
- model_b: Model B for compare type
68
-
69
- Returns:
70
- EvaluationCreateResponse with workflow_id and status
71
- """
72
- requestor = api_requestor.APIRequestor(
73
- client=self._client,
74
- )
75
-
76
- if judge_model_source == "external" and not judge_external_api_token:
77
- raise ValueError(
78
- "judge_external_api_token is required when judge_model_source is 'external'"
79
- )
80
-
81
- # Build judge config
82
- judge_config = JudgeModelConfig(
83
- model=judge_model,
84
- model_source=judge_model_source,
85
- system_template=judge_system_template,
86
- external_api_token=judge_external_api_token,
87
- external_base_url=judge_external_base_url,
88
- )
89
- parameters: Union[ClassifyParameters, ScoreParameters, CompareParameters]
90
- # Build parameters based on type
91
- if type == "classify":
92
- if labels is None or pass_labels is None:
93
- raise ValueError(
94
- "labels and pass_labels are required for classify evaluation"
95
- )
96
-
97
- # Validate that no score-specific parameters are provided
98
- if any(
99
- [
100
- min_score is not None,
101
- max_score is not None,
102
- pass_threshold is not None,
103
- ]
104
- ):
105
- raise ValueError(
106
- "min_score, max_score, and pass_threshold parameters are exclusive to the score mode"
107
- )
108
-
109
- # Validate that no compare-specific parameters are provided
110
- if any([model_a is not None, model_b is not None]):
111
- raise ValueError(
112
- "model_a and model_b parameters are exclusive to the compare mode"
113
- )
114
-
115
- parameters = ClassifyParameters(
116
- judge=judge_config,
117
- labels=labels,
118
- pass_labels=pass_labels,
119
- input_data_file_path=input_data_file_path,
120
- )
121
-
122
- # Handle model_to_evaluate
123
- if model_to_evaluate is not None:
124
- if isinstance(model_to_evaluate, str):
125
- parameters.model_to_evaluate = model_to_evaluate
126
- elif isinstance(model_to_evaluate, dict):
127
- # Validate that all required fields are present for model config
128
- required_fields = [
129
- "model",
130
- "model_source",
131
- "max_tokens",
132
- "temperature",
133
- "system_template",
134
- "input_template",
135
- ]
136
- missing_fields = [
137
- field
138
- for field in required_fields
139
- if field not in model_to_evaluate
140
- ]
141
- if missing_fields:
142
- raise ValueError(
143
- f"All model config parameters are required when using detailed configuration. "
144
- f"Missing: {', '.join(missing_fields)}"
145
- )
146
- if model_to_evaluate.get(
147
- "model_source"
148
- ) == "external" and not model_to_evaluate.get("external_api_token"):
149
- raise ValueError(
150
- "external_api_token is required when model_source is 'external' for model_to_evaluate"
151
- )
152
- parameters.model_to_evaluate = ModelRequest(**model_to_evaluate)
153
-
154
- elif type == "score":
155
- if min_score is None or max_score is None or pass_threshold is None:
156
- raise ValueError(
157
- "min_score, max_score, and pass_threshold are required for score evaluation"
158
- )
159
-
160
- # Validate that no classify-specific parameters are provided
161
- if any([labels is not None, pass_labels is not None]):
162
- raise ValueError(
163
- "labels and pass_labels parameters are exclusive to the classify mode"
164
- )
165
-
166
- # Validate that no compare-specific parameters are provided
167
- if any([model_a is not None, model_b is not None]):
168
- raise ValueError(
169
- "model_a and model_b parameters are exclusive to the compare mode"
170
- )
171
-
172
- parameters = ScoreParameters(
173
- judge=judge_config,
174
- min_score=min_score,
175
- max_score=max_score,
176
- pass_threshold=pass_threshold,
177
- input_data_file_path=input_data_file_path,
178
- )
179
-
180
- # Handle model_to_evaluate
181
- if model_to_evaluate is not None:
182
- if isinstance(model_to_evaluate, str):
183
- parameters.model_to_evaluate = model_to_evaluate
184
- elif isinstance(model_to_evaluate, dict):
185
- # Validate that all required fields are present for model config
186
- required_fields = [
187
- "model",
188
- "model_source",
189
- "max_tokens",
190
- "temperature",
191
- "system_template",
192
- "input_template",
193
- ]
194
- missing_fields = [
195
- field
196
- for field in required_fields
197
- if field not in model_to_evaluate
198
- ]
199
- if missing_fields:
200
- raise ValueError(
201
- f"All model config parameters are required when using detailed configuration. "
202
- f"Missing: {', '.join(missing_fields)}"
203
- )
204
- if model_to_evaluate.get(
205
- "model_source"
206
- ) == "external" and not model_to_evaluate.get("external_api_token"):
207
- raise ValueError(
208
- "external_api_token is required when model_source is 'external' for model_to_evaluate"
209
- )
210
- parameters.model_to_evaluate = ModelRequest(**model_to_evaluate)
211
-
212
- elif type == "compare":
213
- # Validate that model_a and model_b are provided
214
- if model_a is None or model_b is None:
215
- raise ValueError(
216
- "model_a and model_b parameters are required for compare evaluation"
217
- )
218
-
219
- # Validate that no classify-specific parameters are provided
220
- if any([labels is not None, pass_labels is not None]):
221
- raise ValueError(
222
- "labels and pass_labels parameters are exclusive to the classify mode"
223
- )
224
-
225
- # Validate that no score-specific parameters are provided
226
- if any(
227
- [
228
- min_score is not None,
229
- max_score is not None,
230
- pass_threshold is not None,
231
- ]
232
- ):
233
- raise ValueError(
234
- "min_score, max_score, and pass_threshold parameters are exclusive to the score mode"
235
- )
236
-
237
- # Validate that model_to_evaluate is not provided
238
- if model_to_evaluate is not None:
239
- raise ValueError(
240
- "model_to_evaluate parameter is exclusive to classify and score modes"
241
- )
242
-
243
- parameters = CompareParameters(
244
- judge=judge_config,
245
- input_data_file_path=input_data_file_path,
246
- )
247
-
248
- # Handle model_a
249
- if isinstance(model_a, str):
250
- parameters.model_a = model_a
251
- elif isinstance(model_a, dict):
252
- # Validate that all required fields are present for model config
253
- required_fields = [
254
- "model",
255
- "model_source",
256
- "max_tokens",
257
- "temperature",
258
- "system_template",
259
- "input_template",
260
- ]
261
- missing_fields = [
262
- field for field in required_fields if field not in model_a
263
- ]
264
- if missing_fields:
265
- raise ValueError(
266
- f"All model config parameters are required for model_a when using detailed configuration. "
267
- f"Missing: {', '.join(missing_fields)}"
268
- )
269
- if model_a.get("model_source") == "external" and not model_a.get(
270
- "external_api_token"
271
- ):
272
- raise ValueError(
273
- "external_api_token is required when model_source is 'external' for model_a"
274
- )
275
- parameters.model_a = ModelRequest(**model_a)
276
-
277
- # Handle model_b
278
- if isinstance(model_b, str):
279
- parameters.model_b = model_b
280
- elif isinstance(model_b, dict):
281
- # Validate that all required fields are present for model config
282
- required_fields = [
283
- "model",
284
- "model_source",
285
- "max_tokens",
286
- "temperature",
287
- "system_template",
288
- "input_template",
289
- ]
290
- missing_fields = [
291
- field for field in required_fields if field not in model_b
292
- ]
293
- if missing_fields:
294
- raise ValueError(
295
- f"All model config parameters are required for model_b when using detailed configuration. "
296
- f"Missing: {', '.join(missing_fields)}"
297
- )
298
- if model_b.get("model_source") == "external" and not model_b.get(
299
- "external_api_token"
300
- ):
301
- raise ValueError(
302
- "external_api_token is required when model_source is 'external' for model_b"
303
- )
304
- parameters.model_b = ModelRequest(**model_b)
305
-
306
- else:
307
- raise ValueError(
308
- f"Invalid evaluation type: {type}. Must be 'classify', 'score', or 'compare'"
309
- )
310
-
311
- payload = {
312
- "type": type,
313
- "parameters": parameters.model_dump(),
314
- }
315
-
316
- response, _, _ = requestor.request(
317
- options=TogetherRequest(
318
- method="POST",
319
- url="evaluation",
320
- params=payload,
321
- ),
322
- stream=False,
323
- )
324
-
325
- assert isinstance(response, TogetherResponse)
326
- return EvaluationCreateResponse(**response.data)
327
-
328
- def list(
329
- self,
330
- status: Optional[str] = None,
331
- limit: Optional[int] = None,
332
- ) -> List[EvaluationJob]:
333
- """
334
- List evaluation jobs.
335
-
336
- Args:
337
- status: Optional filter by job status
338
- limit: Optional limit on number of results (max 100)
339
-
340
- Returns:
341
- List of EvaluationJob objects
342
- """
343
- requestor = api_requestor.APIRequestor(
344
- client=self._client,
345
- )
346
-
347
- params: Dict[str, Any] = {}
348
- if status is not None:
349
- params["status"] = status
350
- if limit is not None:
351
- params["limit"] = limit
352
-
353
- response, _, _ = requestor.request(
354
- options=TogetherRequest(
355
- method="GET",
356
- url="evaluations",
357
- params=params if params else None,
358
- ),
359
- stream=False,
360
- )
361
-
362
- assert isinstance(response, TogetherResponse)
363
- jobs = response.data or []
364
- return [EvaluationJob(**job) for job in jobs]
365
-
366
- def retrieve(self, evaluation_id: str) -> EvaluationJob:
367
- """
368
- Get details of a specific evaluation job.
369
-
370
- Args:
371
- evaluation_id: The workflow ID of the evaluation job
372
-
373
- Returns:
374
- EvaluationJob object with full details
375
- """
376
- requestor = api_requestor.APIRequestor(
377
- client=self._client,
378
- )
379
-
380
- response, _, _ = requestor.request(
381
- options=TogetherRequest(
382
- method="GET",
383
- url=f"evaluation/{evaluation_id}",
384
- ),
385
- stream=False,
386
- )
387
-
388
- assert isinstance(response, TogetherResponse)
389
- return EvaluationJob(**response.data)
390
-
391
- def status(self, evaluation_id: str) -> EvaluationStatusResponse:
392
- """
393
- Get the status and results of a specific evaluation job.
394
-
395
- Args:
396
- evaluation_id: The workflow ID of the evaluation job
397
-
398
- Returns:
399
- EvaluationStatusResponse with status and results
400
- """
401
- requestor = api_requestor.APIRequestor(
402
- client=self._client,
403
- )
404
-
405
- response, _, _ = requestor.request(
406
- options=TogetherRequest(
407
- method="GET",
408
- url=f"evaluation/{evaluation_id}/status",
409
- ),
410
- stream=False,
411
- )
412
-
413
- assert isinstance(response, TogetherResponse)
414
- return EvaluationStatusResponse(**response.data)
415
-
416
-
417
- class AsyncEvaluation:
418
- def __init__(self, client: TogetherClient) -> None:
419
- self._client = client
420
-
421
- async def create(
422
- self,
423
- type: str,
424
- judge_model: str,
425
- judge_model_source: str,
426
- judge_system_template: str,
427
- input_data_file_path: str,
428
- judge_external_api_token: Optional[str] = None,
429
- judge_external_base_url: Optional[str] = None,
430
- # Classify-specific parameters
431
- labels: Optional[List[str]] = None,
432
- pass_labels: Optional[List[str]] = None,
433
- # Score-specific parameters
434
- min_score: Optional[float] = None,
435
- max_score: Optional[float] = None,
436
- pass_threshold: Optional[float] = None,
437
- # Compare-specific parameters (model_a and model_b handled below)
438
- # Common optional parameters
439
- model_to_evaluate: Optional[Union[str, Dict[str, Any]]] = None,
440
- model_a: Optional[Union[str, Dict[str, Any]]] = None,
441
- model_b: Optional[Union[str, Dict[str, Any]]] = None,
442
- ) -> EvaluationCreateResponse:
443
- """
444
- Create a new evaluation job.
445
-
446
- Args:
447
- type: The type of evaluation ("classify", "score", or "compare")
448
- judge_model: Name or URL of the judge model
449
- judge_model_source: Source of the judge model ("serverless", "dedicated", or "external")
450
- judge_system_template: System template for the judge
451
- input_data_file_path: Path to input data file
452
- judge_external_api_token: Optional external API token for the judge model
453
- judge_external_base_url: Optional external base URLs for the judge model
454
- labels: List of classification labels (required for classify)
455
- pass_labels: List of labels considered as passing (required for classify)
456
- min_score: Minimum score value (required for score)
457
- max_score: Maximum score value (required for score)
458
- pass_threshold: Threshold score for passing (required for score)
459
- model_to_evaluate: Model to evaluate for classify/score types
460
- model_a: Model A for compare type
461
- model_b: Model B for compare type
462
-
463
- Returns:
464
- EvaluationCreateResponse with workflow_id and status
465
- """
466
- requestor = api_requestor.APIRequestor(
467
- client=self._client,
468
- )
469
-
470
- if judge_model_source == "external" and not judge_external_api_token:
471
- raise ValueError(
472
- "judge_external_api_token is required when judge_model_source is 'external'"
473
- )
474
-
475
- # Build judge config
476
- judge_config = JudgeModelConfig(
477
- model=judge_model,
478
- model_source=judge_model_source,
479
- system_template=judge_system_template,
480
- external_api_token=judge_external_api_token,
481
- external_base_url=judge_external_base_url,
482
- )
483
- parameters: Union[ClassifyParameters, ScoreParameters, CompareParameters]
484
- # Build parameters based on type
485
- if type == "classify":
486
- if labels is None or pass_labels is None:
487
- raise ValueError(
488
- "labels and pass_labels are required for classify evaluation"
489
- )
490
-
491
- # Validate that no score-specific parameters are provided
492
- if any(
493
- [
494
- min_score is not None,
495
- max_score is not None,
496
- pass_threshold is not None,
497
- ]
498
- ):
499
- raise ValueError(
500
- "min_score, max_score, and pass_threshold parameters are exclusive to the score mode"
501
- )
502
-
503
- # Validate that no compare-specific parameters are provided
504
- if any([model_a is not None, model_b is not None]):
505
- raise ValueError(
506
- "model_a and model_b parameters are exclusive to the compare mode"
507
- )
508
-
509
- parameters = ClassifyParameters(
510
- judge=judge_config,
511
- labels=labels,
512
- pass_labels=pass_labels,
513
- input_data_file_path=input_data_file_path,
514
- )
515
-
516
- # Handle model_to_evaluate
517
- if model_to_evaluate is not None:
518
- if isinstance(model_to_evaluate, str):
519
- parameters.model_to_evaluate = model_to_evaluate
520
- elif isinstance(model_to_evaluate, dict):
521
- # Validate that all required fields are present for model config
522
- required_fields = [
523
- "model",
524
- "model_source",
525
- "max_tokens",
526
- "temperature",
527
- "system_template",
528
- "input_template",
529
- ]
530
- missing_fields = [
531
- field
532
- for field in required_fields
533
- if field not in model_to_evaluate
534
- ]
535
- if missing_fields:
536
- raise ValueError(
537
- f"All model config parameters are required when using detailed configuration. "
538
- f"Missing: {', '.join(missing_fields)}"
539
- )
540
- if model_to_evaluate.get(
541
- "model_source"
542
- ) == "external" and not model_to_evaluate.get("external_api_token"):
543
- raise ValueError(
544
- "external_api_token is required when model_source is 'external' for model_to_evaluate"
545
- )
546
- parameters.model_to_evaluate = ModelRequest(**model_to_evaluate)
547
-
548
- elif type == "score":
549
- if min_score is None or max_score is None or pass_threshold is None:
550
- raise ValueError(
551
- "min_score, max_score, and pass_threshold are required for score evaluation"
552
- )
553
-
554
- # Validate that no classify-specific parameters are provided
555
- if any([labels is not None, pass_labels is not None]):
556
- raise ValueError(
557
- "labels and pass_labels parameters are exclusive to the classify mode"
558
- )
559
-
560
- # Validate that no compare-specific parameters are provided
561
- if any([model_a is not None, model_b is not None]):
562
- raise ValueError(
563
- "model_a and model_b parameters are exclusive to the compare mode"
564
- )
565
-
566
- parameters = ScoreParameters(
567
- judge=judge_config,
568
- min_score=min_score,
569
- max_score=max_score,
570
- pass_threshold=pass_threshold,
571
- input_data_file_path=input_data_file_path,
572
- )
573
-
574
- # Handle model_to_evaluate
575
- if model_to_evaluate is not None:
576
- if isinstance(model_to_evaluate, str):
577
- parameters.model_to_evaluate = model_to_evaluate
578
- elif isinstance(model_to_evaluate, dict):
579
- # Validate that all required fields are present for model config
580
- required_fields = [
581
- "model",
582
- "model_source",
583
- "max_tokens",
584
- "temperature",
585
- "system_template",
586
- "input_template",
587
- ]
588
- missing_fields = [
589
- field
590
- for field in required_fields
591
- if field not in model_to_evaluate
592
- ]
593
- if missing_fields:
594
- raise ValueError(
595
- f"All model config parameters are required when using detailed configuration. "
596
- f"Missing: {', '.join(missing_fields)}"
597
- )
598
- if model_to_evaluate.get(
599
- "model_source"
600
- ) == "external" and not model_to_evaluate.get("external_api_token"):
601
- raise ValueError(
602
- "external_api_token is required when model_source is 'external' for model_to_evaluate"
603
- )
604
- parameters.model_to_evaluate = ModelRequest(**model_to_evaluate)
605
-
606
- elif type == "compare":
607
- parameters = CompareParameters(
608
- judge=judge_config,
609
- input_data_file_path=input_data_file_path,
610
- )
611
-
612
- # Validate that model_a and model_b are provided
613
- if model_a is None or model_b is None:
614
- raise ValueError(
615
- "model_a and model_b parameters are required for compare evaluation"
616
- )
617
-
618
- # Validate that no classify-specific parameters are provided
619
- if any([labels is not None, pass_labels is not None]):
620
- raise ValueError(
621
- "labels and pass_labels parameters are exclusive to the classify mode"
622
- )
623
-
624
- # Validate that no score-specific parameters are provided
625
- if any(
626
- [
627
- min_score is not None,
628
- max_score is not None,
629
- pass_threshold is not None,
630
- ]
631
- ):
632
- raise ValueError(
633
- "min_score, max_score, and pass_threshold parameters are exclusive to the score mode"
634
- )
635
-
636
- # Validate that model_to_evaluate is not provided
637
- if model_to_evaluate is not None:
638
- raise ValueError(
639
- "model_to_evaluate parameter is exclusive to classify and score modes"
640
- )
641
-
642
- # Handle model_a
643
- if isinstance(model_a, str):
644
- parameters.model_a = model_a
645
- elif isinstance(model_a, dict):
646
- # Validate that all required fields are present for model config
647
- required_fields = [
648
- "model",
649
- "model_source",
650
- "max_tokens",
651
- "temperature",
652
- "system_template",
653
- "input_template",
654
- ]
655
- missing_fields = [
656
- field for field in required_fields if field not in model_a
657
- ]
658
- if missing_fields:
659
- raise ValueError(
660
- f"All model config parameters are required for model_a when using detailed configuration. "
661
- f"Missing: {', '.join(missing_fields)}"
662
- )
663
- if model_a.get("model_source") == "external" and not model_a.get(
664
- "external_api_token"
665
- ):
666
- raise ValueError(
667
- "external_api_token is required when model_source is 'external' for model_a"
668
- )
669
- parameters.model_a = ModelRequest(**model_a)
670
-
671
- # Handle model_b
672
- if isinstance(model_b, str):
673
- parameters.model_b = model_b
674
- elif isinstance(model_b, dict):
675
- # Validate that all required fields are present for model config
676
- required_fields = [
677
- "model",
678
- "model_source",
679
- "max_tokens",
680
- "temperature",
681
- "system_template",
682
- "input_template",
683
- ]
684
- missing_fields = [
685
- field for field in required_fields if field not in model_b
686
- ]
687
- if missing_fields:
688
- raise ValueError(
689
- f"All model config parameters are required for model_b when using detailed configuration. "
690
- f"Missing: {', '.join(missing_fields)}"
691
- )
692
- if model_b.get("model_source") == "external" and not model_b.get(
693
- "external_api_token"
694
- ):
695
- raise ValueError(
696
- "external_api_token is required when model_source is 'external' for model_b"
697
- )
698
- parameters.model_b = ModelRequest(**model_b)
699
-
700
- else:
701
- raise ValueError(
702
- f"Invalid evaluation type: {type}. Must be 'classify', 'score', or 'compare'"
703
- )
704
-
705
- payload = {
706
- "type": type,
707
- "parameters": parameters.model_dump(),
708
- }
709
-
710
- response, _, _ = await requestor.arequest(
711
- options=TogetherRequest(
712
- method="POST",
713
- url="evaluation",
714
- params=payload,
715
- ),
716
- stream=False,
717
- )
718
-
719
- assert isinstance(response, TogetherResponse)
720
- return EvaluationCreateResponse(**response.data)
721
-
722
- async def list(
723
- self,
724
- status: Optional[str] = None,
725
- limit: Optional[int] = None,
726
- ) -> List[EvaluationJob]:
727
- """
728
- List evaluation jobs.
729
-
730
- Args:
731
- status: Optional filter by job status
732
- limit: Optional limit on number of results (max 100)
733
-
734
- Returns:
735
- List of EvaluationJob objects
736
- """
737
- requestor = api_requestor.APIRequestor(
738
- client=self._client,
739
- )
740
-
741
- params: Dict[str, Any] = {}
742
- if status is not None:
743
- params["status"] = status
744
- if limit is not None:
745
- params["limit"] = limit
746
-
747
- response, _, _ = await requestor.arequest(
748
- options=TogetherRequest(
749
- method="GET",
750
- url="evaluations",
751
- params=params if params else None,
752
- ),
753
- stream=False,
754
- )
755
-
756
- assert isinstance(response, TogetherResponse)
757
- jobs = response.data or []
758
- return [EvaluationJob(**job) for job in jobs]
759
-
760
- async def retrieve(self, evaluation_id: str) -> EvaluationJob:
761
- """
762
- Get details of a specific evaluation job.
763
-
764
- Args:
765
- evaluation_id: The workflow ID of the evaluation job
766
-
767
- Returns:
768
- EvaluationJob object with full details
769
- """
770
- requestor = api_requestor.APIRequestor(
771
- client=self._client,
772
- )
773
-
774
- response, _, _ = await requestor.arequest(
775
- options=TogetherRequest(
776
- method="GET",
777
- url=f"evaluation/{evaluation_id}",
778
- ),
779
- stream=False,
780
- )
781
-
782
- assert isinstance(response, TogetherResponse)
783
- return EvaluationJob(**response.data)
784
-
785
- async def status(self, evaluation_id: str) -> EvaluationStatusResponse:
786
- """
787
- Get the status and results of a specific evaluation job.
788
-
789
- Args:
790
- evaluation_id: The workflow ID of the evaluation job
791
-
792
- Returns:
793
- EvaluationStatusResponse with status and results
794
- """
795
- requestor = api_requestor.APIRequestor(
796
- client=self._client,
797
- )
798
-
799
- response, _, _ = await requestor.arequest(
800
- options=TogetherRequest(
801
- method="GET",
802
- url=f"evaluation/{evaluation_id}/status",
803
- ),
804
- stream=False,
805
- )
806
-
807
- assert isinstance(response, TogetherResponse)
808
- return EvaluationStatusResponse(**response.data)