together 0.2.5__py3-none-any.whl → 0.2.7__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 +16 -0
- together/cli/cli.py +2 -1
- together/commands/chat.py +20 -12
- together/commands/complete.py +34 -26
- together/commands/embeddings.py +48 -0
- together/commands/files.py +75 -9
- together/commands/finetune.py +132 -117
- together/commands/image.py +14 -11
- together/commands/models.py +81 -16
- together/complete.py +2 -4
- together/embeddings.py +35 -0
- together/error.py +4 -0
- together/files.py +12 -9
- together/finetune.py +23 -48
- together/image.py +1 -2
- together/models.py +5 -10
- together/utils.py +35 -23
- together/version.py +6 -1
- {together-0.2.5.dist-info → together-0.2.7.dist-info}/METADATA +68 -225
- together-0.2.7.dist-info/RECORD +27 -0
- {together-0.2.5.dist-info → together-0.2.7.dist-info}/WHEEL +1 -1
- together-0.2.7.dist-info/entry_points.txt +3 -0
- together-0.2.5.dist-info/RECORD +0 -25
- together-0.2.5.dist-info/entry_points.txt +0 -2
- {together-0.2.5.dist-info/licenses → together-0.2.7.dist-info}/LICENSE +0 -0
together/commands/finetune.py
CHANGED
|
@@ -4,8 +4,14 @@ import argparse
|
|
|
4
4
|
import json
|
|
5
5
|
import os
|
|
6
6
|
|
|
7
|
+
from tabulate import tabulate
|
|
8
|
+
|
|
9
|
+
import together
|
|
7
10
|
from together import Finetune
|
|
8
|
-
from together.utils import parse_timestamp
|
|
11
|
+
from together.utils import finetune_price_to_dollars, get_logger, parse_timestamp
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
logger = get_logger(str(__name__))
|
|
9
15
|
|
|
10
16
|
|
|
11
17
|
def add_parser(subparsers: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
|
|
@@ -22,7 +28,6 @@ def add_parser(subparsers: argparse._SubParsersAction[argparse.ArgumentParser])
|
|
|
22
28
|
_add_download(child_parsers)
|
|
23
29
|
_add_status(child_parsers)
|
|
24
30
|
_add_checkpoints(child_parsers)
|
|
25
|
-
# _add_delete_model(child_parsers)
|
|
26
31
|
|
|
27
32
|
|
|
28
33
|
def _add_create(parser: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
|
|
@@ -43,13 +48,6 @@ def _add_create(parser: argparse._SubParsersAction[argparse.ArgumentParser]) ->
|
|
|
43
48
|
required=False,
|
|
44
49
|
action="store_true",
|
|
45
50
|
)
|
|
46
|
-
# subparser.add_argument(
|
|
47
|
-
# "--validation-file",
|
|
48
|
-
# "-v",
|
|
49
|
-
# default=None,
|
|
50
|
-
# help="The ID of an uploaded file that contains validation data.",
|
|
51
|
-
# type=str,
|
|
52
|
-
# )
|
|
53
51
|
subparser.add_argument(
|
|
54
52
|
"--model",
|
|
55
53
|
"-m",
|
|
@@ -90,46 +88,6 @@ def _add_create(parser: argparse._SubParsersAction[argparse.ArgumentParser]) ->
|
|
|
90
88
|
help="The learning rate multiplier to use for training. Default=0.00001",
|
|
91
89
|
type=float,
|
|
92
90
|
)
|
|
93
|
-
# subparser.add_argument(
|
|
94
|
-
# "--warmup-steps",
|
|
95
|
-
# "-ws",
|
|
96
|
-
# default=0,
|
|
97
|
-
# help="Warmup steps",
|
|
98
|
-
# type=int,
|
|
99
|
-
# )
|
|
100
|
-
# subparser.add_argument(
|
|
101
|
-
# "--train-warmup-steps",
|
|
102
|
-
# "-tws",
|
|
103
|
-
# default=0,
|
|
104
|
-
# help="Train warmup steps",
|
|
105
|
-
# type=int,
|
|
106
|
-
# )
|
|
107
|
-
# subparser.add_argument(
|
|
108
|
-
# "--sequence-length",
|
|
109
|
-
# "-sl",
|
|
110
|
-
# default=2048,
|
|
111
|
-
# help="Max sequence length",
|
|
112
|
-
# type=int,
|
|
113
|
-
# )
|
|
114
|
-
# subparser.add_argument(
|
|
115
|
-
# "--seed",
|
|
116
|
-
# default=42,
|
|
117
|
-
# help="Training seed",
|
|
118
|
-
# type=int,
|
|
119
|
-
# )
|
|
120
|
-
# subparser.add_argument(
|
|
121
|
-
# "--fp32",
|
|
122
|
-
# help="Enable FP32 training. Defaults to false (FP16 training).",
|
|
123
|
-
# default=False,
|
|
124
|
-
# action="store_true",
|
|
125
|
-
# )
|
|
126
|
-
# subparser.add_argument(
|
|
127
|
-
# "--checkpoint-steps",
|
|
128
|
-
# "-b",
|
|
129
|
-
# default=0,
|
|
130
|
-
# help="Number of steps between each checkpoint. Defaults to 0 = checkpoints per epoch.",
|
|
131
|
-
# type=int,
|
|
132
|
-
# )
|
|
133
91
|
subparser.add_argument(
|
|
134
92
|
"--suffix",
|
|
135
93
|
"-s",
|
|
@@ -162,53 +120,69 @@ def _add_create(parser: argparse._SubParsersAction[argparse.ArgumentParser]) ->
|
|
|
162
120
|
|
|
163
121
|
subparser.set_defaults(func=_run_create)
|
|
164
122
|
|
|
165
|
-
# End of create_finetune
|
|
166
|
-
|
|
167
123
|
|
|
168
124
|
def _add_list(parser: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
|
|
169
125
|
# List_Finetune
|
|
170
|
-
|
|
171
|
-
|
|
126
|
+
subparser = parser.add_parser("list")
|
|
127
|
+
subparser.add_argument(
|
|
128
|
+
"--raw",
|
|
129
|
+
help="Raw JSON dump of response",
|
|
130
|
+
default=False,
|
|
131
|
+
action="store_true",
|
|
132
|
+
)
|
|
133
|
+
subparser.set_defaults(func=_run_list)
|
|
172
134
|
|
|
173
135
|
|
|
174
136
|
def _add_retrieve(parser: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
|
|
175
|
-
|
|
176
|
-
|
|
137
|
+
subparser = parser.add_parser("retrieve")
|
|
138
|
+
subparser.add_argument(
|
|
177
139
|
"fine_tune_id",
|
|
178
140
|
metavar="FINETUNE-ID",
|
|
179
141
|
default=None,
|
|
180
142
|
help="Fine-tuning ID",
|
|
181
143
|
type=str,
|
|
182
144
|
)
|
|
183
|
-
|
|
145
|
+
subparser.add_argument(
|
|
146
|
+
"--raw",
|
|
147
|
+
help="Raw JSON dump of response",
|
|
148
|
+
default=False,
|
|
149
|
+
action="store_true",
|
|
150
|
+
)
|
|
151
|
+
subparser.set_defaults(func=_run_retrieve)
|
|
184
152
|
|
|
185
153
|
|
|
186
154
|
def _add_cancel(parser: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
|
|
187
155
|
# Cancel Finetune
|
|
188
|
-
|
|
189
|
-
|
|
156
|
+
subparser = parser.add_parser("cancel")
|
|
157
|
+
subparser.add_argument(
|
|
190
158
|
"fine_tune_id",
|
|
191
159
|
metavar="FINETUNE-ID",
|
|
192
160
|
default=None,
|
|
193
161
|
help="Fine-tuning ID",
|
|
194
162
|
type=str,
|
|
195
163
|
)
|
|
196
|
-
|
|
164
|
+
subparser.set_defaults(func=_run_cancel)
|
|
197
165
|
|
|
198
166
|
|
|
199
167
|
def _add_list_events(
|
|
200
168
|
parser: argparse._SubParsersAction[argparse.ArgumentParser],
|
|
201
169
|
) -> None:
|
|
202
170
|
# List finetune events
|
|
203
|
-
|
|
204
|
-
|
|
171
|
+
subparser = parser.add_parser("list-events")
|
|
172
|
+
subparser.add_argument(
|
|
205
173
|
"fine_tune_id",
|
|
206
174
|
metavar="FINETUNE-ID",
|
|
207
175
|
default=None,
|
|
208
176
|
help="Fine-tuning ID",
|
|
209
177
|
type=str,
|
|
210
178
|
)
|
|
211
|
-
|
|
179
|
+
subparser.add_argument(
|
|
180
|
+
"--raw",
|
|
181
|
+
help="Raw JSON dump of response",
|
|
182
|
+
default=False,
|
|
183
|
+
action="store_true",
|
|
184
|
+
)
|
|
185
|
+
subparser.set_defaults(func=_run_list_events)
|
|
212
186
|
|
|
213
187
|
|
|
214
188
|
def _add_download(parser: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
|
|
@@ -269,22 +243,6 @@ def _add_checkpoints(
|
|
|
269
243
|
checkpoint_parser.set_defaults(func=_run_checkpoint)
|
|
270
244
|
|
|
271
245
|
|
|
272
|
-
# def _add_delete_model(
|
|
273
|
-
# parser: argparse._SubParsersAction[argparse.ArgumentParser],
|
|
274
|
-
# ) -> None:
|
|
275
|
-
# # Delete finetune model
|
|
276
|
-
# delete_finetune_model_parser = parser.add_parser("delete-model")
|
|
277
|
-
# delete_finetune_model_parser.add_argument(
|
|
278
|
-
# "--model",
|
|
279
|
-
# "-m",
|
|
280
|
-
# default=None,
|
|
281
|
-
# help="Model name",
|
|
282
|
-
# type=str,
|
|
283
|
-
# required=True,
|
|
284
|
-
# )
|
|
285
|
-
# delete_finetune_model_parser.set_defaults(func=_run_delete_model)
|
|
286
|
-
|
|
287
|
-
|
|
288
246
|
def _run_create(args: argparse.Namespace) -> None:
|
|
289
247
|
finetune = Finetune()
|
|
290
248
|
|
|
@@ -297,70 +255,127 @@ def _run_create(args: argparse.Namespace) -> None:
|
|
|
297
255
|
args.batch_size = 144
|
|
298
256
|
else:
|
|
299
257
|
args.batch_size = 32
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
estimate_price=args.estimate_price,
|
|
317
|
-
wandb_api_key=args.wandb_api_key if not args.no_wandb_api_key else None,
|
|
318
|
-
confirm_inputs=not args.quiet,
|
|
319
|
-
)
|
|
258
|
+
try:
|
|
259
|
+
response = finetune.create(
|
|
260
|
+
training_file=args.training_file, # training file_id
|
|
261
|
+
model=args.model,
|
|
262
|
+
n_epochs=args.n_epochs,
|
|
263
|
+
n_checkpoints=args.n_checkpoints,
|
|
264
|
+
batch_size=args.batch_size,
|
|
265
|
+
learning_rate=args.learning_rate,
|
|
266
|
+
suffix=args.suffix,
|
|
267
|
+
estimate_price=args.estimate_price,
|
|
268
|
+
wandb_api_key=args.wandb_api_key if not args.no_wandb_api_key else None,
|
|
269
|
+
confirm_inputs=not args.quiet,
|
|
270
|
+
)
|
|
271
|
+
except together.AuthenticationError:
|
|
272
|
+
logger.critical(together.MISSING_API_KEY_MESSAGE)
|
|
273
|
+
exit(0)
|
|
320
274
|
|
|
321
275
|
print(json.dumps(response, indent=4))
|
|
322
276
|
|
|
323
277
|
|
|
324
278
|
def _run_list(args: argparse.Namespace) -> None:
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
279
|
+
try:
|
|
280
|
+
response = Finetune.list()
|
|
281
|
+
except together.AuthenticationError:
|
|
282
|
+
logger.critical(together.MISSING_API_KEY_MESSAGE)
|
|
283
|
+
exit(0)
|
|
284
|
+
response["data"].sort(key=lambda x: parse_timestamp(x["created_at"]))
|
|
285
|
+
if args.raw:
|
|
286
|
+
print(json.dumps(response, indent=4))
|
|
287
|
+
else:
|
|
288
|
+
display_list = []
|
|
289
|
+
for i in response["data"]:
|
|
290
|
+
display_list.append(
|
|
291
|
+
{
|
|
292
|
+
"Fine-tune ID": i.get("id"),
|
|
293
|
+
"Model Output Name": i.get("model_output_name"),
|
|
294
|
+
"Status": i.get("status"),
|
|
295
|
+
"Created At": i.get("created_at"),
|
|
296
|
+
"Price": finetune_price_to_dollars(
|
|
297
|
+
float(str(i.get("total_price")))
|
|
298
|
+
), # convert to string for mypy typing
|
|
299
|
+
}
|
|
300
|
+
)
|
|
301
|
+
table = tabulate(display_list, headers="keys", tablefmt="grid", showindex=True)
|
|
302
|
+
print(table)
|
|
330
303
|
|
|
331
304
|
|
|
332
305
|
def _run_retrieve(args: argparse.Namespace) -> None:
|
|
333
|
-
|
|
334
|
-
|
|
306
|
+
try:
|
|
307
|
+
response = Finetune.retrieve(args.fine_tune_id)
|
|
308
|
+
except together.AuthenticationError:
|
|
309
|
+
logger.critical(together.MISSING_API_KEY_MESSAGE)
|
|
310
|
+
exit(0)
|
|
311
|
+
if args.raw:
|
|
312
|
+
print(json.dumps(response, indent=4))
|
|
313
|
+
else:
|
|
314
|
+
table_data = [
|
|
315
|
+
{"Key": key, "Value": value}
|
|
316
|
+
for key, value in response.items()
|
|
317
|
+
if key not in ["events", "model_output_path"]
|
|
318
|
+
]
|
|
319
|
+
table = tabulate(table_data, tablefmt="grid")
|
|
320
|
+
print(table)
|
|
335
321
|
|
|
336
322
|
|
|
337
323
|
def _run_cancel(args: argparse.Namespace) -> None:
|
|
338
|
-
|
|
324
|
+
try:
|
|
325
|
+
response = Finetune.cancel(args.fine_tune_id)
|
|
326
|
+
except together.AuthenticationError:
|
|
327
|
+
logger.critical(together.MISSING_API_KEY_MESSAGE)
|
|
328
|
+
exit(0)
|
|
339
329
|
print(json.dumps(response, indent=4))
|
|
340
330
|
|
|
341
331
|
|
|
342
332
|
def _run_list_events(args: argparse.Namespace) -> None:
|
|
343
|
-
|
|
344
|
-
|
|
333
|
+
try:
|
|
334
|
+
response = Finetune.list_events(args.fine_tune_id)
|
|
335
|
+
except together.AuthenticationError:
|
|
336
|
+
logger.critical(together.MISSING_API_KEY_MESSAGE)
|
|
337
|
+
exit(0)
|
|
338
|
+
if args.raw:
|
|
339
|
+
print(json.dumps(response, indent=4))
|
|
340
|
+
else:
|
|
341
|
+
display_list = []
|
|
342
|
+
for i in response["data"]:
|
|
343
|
+
display_list.append(
|
|
344
|
+
{
|
|
345
|
+
"Message": i.get("message"),
|
|
346
|
+
"Type": i.get("type"),
|
|
347
|
+
"Hash": i.get("hash"),
|
|
348
|
+
}
|
|
349
|
+
)
|
|
350
|
+
table = tabulate(display_list, headers="keys", tablefmt="grid", showindex=True)
|
|
351
|
+
print(table)
|
|
345
352
|
|
|
346
353
|
|
|
347
354
|
def _run_download(args: argparse.Namespace) -> None:
|
|
348
|
-
|
|
355
|
+
try:
|
|
356
|
+
response = Finetune.download(
|
|
357
|
+
args.fine_tune_id, args.output, args.checkpoint_step
|
|
358
|
+
)
|
|
359
|
+
except together.AuthenticationError:
|
|
360
|
+
logger.critical(together.MISSING_API_KEY_MESSAGE)
|
|
361
|
+
exit(0)
|
|
349
362
|
print(response)
|
|
350
363
|
|
|
351
364
|
|
|
352
365
|
def _run_status(args: argparse.Namespace) -> None:
|
|
353
|
-
|
|
366
|
+
try:
|
|
367
|
+
response = Finetune.get_job_status(args.fine_tune_id)
|
|
368
|
+
except together.AuthenticationError:
|
|
369
|
+
logger.critical(together.MISSING_API_KEY_MESSAGE)
|
|
370
|
+
exit(0)
|
|
354
371
|
print(response)
|
|
355
372
|
|
|
356
373
|
|
|
357
374
|
def _run_checkpoint(args: argparse.Namespace) -> None:
|
|
358
|
-
|
|
375
|
+
try:
|
|
376
|
+
checkpoints = Finetune.get_checkpoints(args.fine_tune_id)
|
|
377
|
+
except together.AuthenticationError:
|
|
378
|
+
logger.critical(together.MISSING_API_KEY_MESSAGE)
|
|
379
|
+
exit(0)
|
|
359
380
|
print(json.dumps(checkpoints, indent=4))
|
|
360
381
|
print(f"\n{len(checkpoints)} checkpoints found")
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
# def _run_delete_model(args: argparse.Namespace) -> None:
|
|
364
|
-
# finetune = Finetune(args.endpoint)
|
|
365
|
-
# response = finetune.delete_finetune_model(args.model)
|
|
366
|
-
# print(json.dumps(response))
|
together/commands/image.py
CHANGED
|
@@ -124,16 +124,19 @@ def _save_image(args: argparse.Namespace, response: Dict[str, Any]) -> None:
|
|
|
124
124
|
|
|
125
125
|
def _run_complete(args: argparse.Namespace) -> None:
|
|
126
126
|
complete = Image()
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
127
|
+
try:
|
|
128
|
+
response = complete.create(
|
|
129
|
+
prompt=args.prompt,
|
|
130
|
+
model=args.model,
|
|
131
|
+
steps=args.steps,
|
|
132
|
+
seed=args.seed,
|
|
133
|
+
results=args.results,
|
|
134
|
+
height=args.height,
|
|
135
|
+
width=args.width,
|
|
136
|
+
negative_prompt=args.negative_prompt,
|
|
137
|
+
)
|
|
138
|
+
except together.AuthenticationError:
|
|
139
|
+
logger.critical(together.MISSING_API_KEY_MESSAGE)
|
|
140
|
+
exit(0)
|
|
138
141
|
|
|
139
142
|
_save_image(args, response)
|
together/commands/models.py
CHANGED
|
@@ -3,7 +3,13 @@ from __future__ import annotations
|
|
|
3
3
|
import argparse
|
|
4
4
|
import json
|
|
5
5
|
|
|
6
|
+
from tabulate import tabulate
|
|
7
|
+
|
|
6
8
|
import together
|
|
9
|
+
from together.utils import get_logger
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
logger = get_logger(str(__name__))
|
|
7
13
|
|
|
8
14
|
|
|
9
15
|
def add_parser(
|
|
@@ -26,9 +32,15 @@ def _add_list(
|
|
|
26
32
|
parser: argparse._SubParsersAction[argparse.ArgumentParser],
|
|
27
33
|
) -> None:
|
|
28
34
|
subparser = parser.add_parser("list")
|
|
35
|
+
subparser.add_argument(
|
|
36
|
+
"--details",
|
|
37
|
+
help="List all details",
|
|
38
|
+
default=False,
|
|
39
|
+
action="store_true",
|
|
40
|
+
)
|
|
29
41
|
subparser.add_argument(
|
|
30
42
|
"--raw",
|
|
31
|
-
help="Raw
|
|
43
|
+
help="Raw JSON dump of response",
|
|
32
44
|
default=False,
|
|
33
45
|
action="store_true",
|
|
34
46
|
)
|
|
@@ -107,18 +119,51 @@ def _add_ready(
|
|
|
107
119
|
|
|
108
120
|
|
|
109
121
|
def _run_list(args: argparse.Namespace) -> None:
|
|
110
|
-
|
|
122
|
+
try:
|
|
123
|
+
response = together.Models.list()
|
|
124
|
+
except together.AuthenticationError:
|
|
125
|
+
logger.critical(together.MISSING_API_KEY_MESSAGE)
|
|
126
|
+
exit(0)
|
|
111
127
|
if args.raw:
|
|
112
128
|
print(json.dumps(response, indent=4))
|
|
113
129
|
else:
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
130
|
+
if not args.details:
|
|
131
|
+
display_list = []
|
|
132
|
+
for i in response:
|
|
133
|
+
display_list.append(
|
|
134
|
+
{
|
|
135
|
+
"Name": i.get("display_name"),
|
|
136
|
+
"Model String": i.get("name"),
|
|
137
|
+
"Type": i.get("display_type"),
|
|
138
|
+
}
|
|
139
|
+
)
|
|
140
|
+
else:
|
|
141
|
+
display_list = []
|
|
142
|
+
for i in response:
|
|
143
|
+
display_list.append(
|
|
144
|
+
{
|
|
145
|
+
"Name": i.get("display_name"),
|
|
146
|
+
"Model String": i.get("name"),
|
|
147
|
+
"Type": i.get("display_type"),
|
|
148
|
+
"Parameters": i.get("num_parameters"),
|
|
149
|
+
"Context": i.get("context_length"),
|
|
150
|
+
"Hardware": i.get("hardware_label"),
|
|
151
|
+
}
|
|
152
|
+
)
|
|
153
|
+
table = tabulate(display_list, headers="keys", tablefmt="grid")
|
|
154
|
+
print(table)
|
|
118
155
|
|
|
119
156
|
|
|
120
157
|
def _run_info(args: argparse.Namespace) -> None:
|
|
121
|
-
|
|
158
|
+
try:
|
|
159
|
+
model_info = together.Models.info(args.model)
|
|
160
|
+
except together.AuthenticationError:
|
|
161
|
+
logger.critical(together.MISSING_API_KEY_MESSAGE)
|
|
162
|
+
exit(0)
|
|
163
|
+
|
|
164
|
+
if args.raw:
|
|
165
|
+
print(json.dumps(model_info, indent=4))
|
|
166
|
+
else:
|
|
122
167
|
hidden_keys = [
|
|
123
168
|
"_id",
|
|
124
169
|
"modelInstanceConfig",
|
|
@@ -130,17 +175,25 @@ def _run_info(args: argparse.Namespace) -> None:
|
|
|
130
175
|
"pricing_tier",
|
|
131
176
|
"hardware_label",
|
|
132
177
|
"depth",
|
|
178
|
+
"descriptionLink",
|
|
133
179
|
]
|
|
134
|
-
else:
|
|
135
|
-
hidden_keys = []
|
|
136
180
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
181
|
+
table_data = [
|
|
182
|
+
{"Key": key, "Value": value}
|
|
183
|
+
for key, value in model_info.items()
|
|
184
|
+
if key not in hidden_keys
|
|
185
|
+
]
|
|
186
|
+
table = tabulate(table_data, tablefmt="grid")
|
|
187
|
+
print(table)
|
|
140
188
|
|
|
141
189
|
|
|
142
190
|
def _run_instances(args: argparse.Namespace) -> None:
|
|
143
|
-
|
|
191
|
+
try:
|
|
192
|
+
response = together.Models.instances()
|
|
193
|
+
except together.AuthenticationError:
|
|
194
|
+
logger.critical(together.MISSING_API_KEY_MESSAGE)
|
|
195
|
+
exit(0)
|
|
196
|
+
|
|
144
197
|
if args.raw:
|
|
145
198
|
print(json.dumps(response, indent=4))
|
|
146
199
|
else:
|
|
@@ -149,15 +202,27 @@ def _run_instances(args: argparse.Namespace) -> None:
|
|
|
149
202
|
|
|
150
203
|
|
|
151
204
|
def _run_start(args: argparse.Namespace) -> None:
|
|
152
|
-
|
|
205
|
+
try:
|
|
206
|
+
response = together.Models.start(args.model)
|
|
207
|
+
except together.AuthenticationError:
|
|
208
|
+
logger.critical(together.MISSING_API_KEY_MESSAGE)
|
|
209
|
+
exit(0)
|
|
153
210
|
print(json.dumps(response, indent=4))
|
|
154
211
|
|
|
155
212
|
|
|
156
213
|
def _run_stop(args: argparse.Namespace) -> None:
|
|
157
|
-
|
|
214
|
+
try:
|
|
215
|
+
response = together.Models.stop(args.model)
|
|
216
|
+
except together.AuthenticationError:
|
|
217
|
+
logger.critical(together.MISSING_API_KEY_MESSAGE)
|
|
218
|
+
exit(0)
|
|
158
219
|
print(json.dumps(response, indent=4))
|
|
159
220
|
|
|
160
221
|
|
|
161
222
|
def _run_ready(args: argparse.Namespace) -> None:
|
|
162
|
-
|
|
223
|
+
try:
|
|
224
|
+
response = together.Models.ready(args.model)
|
|
225
|
+
except together.AuthenticationError:
|
|
226
|
+
logger.critical(together.MISSING_API_KEY_MESSAGE)
|
|
227
|
+
exit(0)
|
|
163
228
|
print(json.dumps(response, indent=4))
|
together/complete.py
CHANGED
|
@@ -41,8 +41,7 @@ class Complete:
|
|
|
41
41
|
response = create_post_request(
|
|
42
42
|
url=together.api_base_complete, json=parameter_payload
|
|
43
43
|
)
|
|
44
|
-
|
|
45
|
-
return {}
|
|
44
|
+
|
|
46
45
|
try:
|
|
47
46
|
response_json = dict(response.json())
|
|
48
47
|
|
|
@@ -86,8 +85,7 @@ class Complete:
|
|
|
86
85
|
response = create_post_request(
|
|
87
86
|
url=together.api_base_complete, json=parameter_payload, stream=True
|
|
88
87
|
)
|
|
89
|
-
|
|
90
|
-
return {}
|
|
88
|
+
|
|
91
89
|
output = ""
|
|
92
90
|
client = sse_client(response)
|
|
93
91
|
for event in client.events():
|
together/embeddings.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from typing import Any, Dict, Optional
|
|
2
|
+
|
|
3
|
+
import together
|
|
4
|
+
from together.utils import create_post_request, get_logger
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
logger = get_logger(str(__name__))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Embeddings:
|
|
11
|
+
@classmethod
|
|
12
|
+
def create(
|
|
13
|
+
self,
|
|
14
|
+
input: str,
|
|
15
|
+
model: Optional[str] = "",
|
|
16
|
+
) -> Dict[str, Any]:
|
|
17
|
+
if model == "":
|
|
18
|
+
model = together.default_embedding_model
|
|
19
|
+
|
|
20
|
+
parameter_payload = {
|
|
21
|
+
"input": input,
|
|
22
|
+
"model": model,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
# send request
|
|
26
|
+
response = create_post_request(
|
|
27
|
+
url=together.api_base_embeddings, json=parameter_payload
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
try:
|
|
31
|
+
response_json = dict(response.json())
|
|
32
|
+
|
|
33
|
+
except Exception as e:
|
|
34
|
+
raise together.JSONError(e, http_status=response.status_code)
|
|
35
|
+
return response_json
|
together/error.py
CHANGED
together/files.py
CHANGED
|
@@ -5,8 +5,10 @@ import urllib.parse
|
|
|
5
5
|
from typing import Any, Dict, List, Mapping, Optional, Union
|
|
6
6
|
|
|
7
7
|
import requests
|
|
8
|
+
from requests.adapters import HTTPAdapter
|
|
8
9
|
from tqdm import tqdm
|
|
9
10
|
from tqdm.utils import CallbackIOWrapper
|
|
11
|
+
from urllib3.util import Retry
|
|
10
12
|
|
|
11
13
|
import together
|
|
12
14
|
from together.utils import (
|
|
@@ -27,11 +29,10 @@ logger = get_logger(str(__name__))
|
|
|
27
29
|
|
|
28
30
|
class Files:
|
|
29
31
|
@classmethod
|
|
30
|
-
def list(self) -> Dict[str, List[Dict[str, Union[str, int]]]]:
|
|
32
|
+
def list(self) -> Dict[str, List[Dict[str, Union[str, int, float]]]]:
|
|
31
33
|
# send request
|
|
32
34
|
response = create_get_request(together.api_base_files)
|
|
33
|
-
|
|
34
|
-
return {}
|
|
35
|
+
|
|
35
36
|
return response_to_dict(response)
|
|
36
37
|
|
|
37
38
|
@classmethod
|
|
@@ -63,6 +64,13 @@ class Files:
|
|
|
63
64
|
|
|
64
65
|
session = requests.Session()
|
|
65
66
|
|
|
67
|
+
retry_strategy = Retry(
|
|
68
|
+
total=together.MAX_CONNECTION_RETRIES,
|
|
69
|
+
backoff_factor=together.BACKOFF_FACTOR,
|
|
70
|
+
)
|
|
71
|
+
retry_adapter = HTTPAdapter(max_retries=retry_strategy)
|
|
72
|
+
session.mount("https://", retry_adapter)
|
|
73
|
+
|
|
66
74
|
init_endpoint = together.api_base_files[:-1]
|
|
67
75
|
|
|
68
76
|
logger.debug(
|
|
@@ -133,10 +141,6 @@ class Files:
|
|
|
133
141
|
logger.critical(f"Response error raised: {e}")
|
|
134
142
|
raise together.ResponseError(e)
|
|
135
143
|
|
|
136
|
-
# output_dict["filename"] = os.path.basename(file)
|
|
137
|
-
# output_dict["id"] = str(file_id)
|
|
138
|
-
# output_dict["object"] = "file"
|
|
139
|
-
|
|
140
144
|
return {
|
|
141
145
|
"filename": os.path.basename(file),
|
|
142
146
|
"id": str(file_id),
|
|
@@ -168,8 +172,7 @@ class Files:
|
|
|
168
172
|
retrieve_url = urllib.parse.urljoin(together.api_base_files, file_id)
|
|
169
173
|
logger.info(f"Retrieve URL: {retrieve_url}")
|
|
170
174
|
response = create_get_request(retrieve_url)
|
|
171
|
-
|
|
172
|
-
return {}
|
|
175
|
+
|
|
173
176
|
return response_to_dict(response)
|
|
174
177
|
|
|
175
178
|
@classmethod
|