together 1.1.2__tar.gz → 1.1.4__tar.gz
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-1.1.2 → together-1.1.4}/PKG-INFO +44 -29
- {together-1.1.2 → together-1.1.4}/README.md +42 -27
- {together-1.1.2 → together-1.1.4}/pyproject.toml +10 -3
- {together-1.1.2 → together-1.1.4}/src/together/cli/api/chat.py +31 -2
- {together-1.1.2 → together-1.1.4}/src/together/cli/api/completions.py +11 -1
- {together-1.1.2 → together-1.1.4}/src/together/cli/api/finetune.py +12 -2
- {together-1.1.2 → together-1.1.4}/src/together/resources/chat/completions.py +46 -0
- {together-1.1.2 → together-1.1.4}/src/together/resources/completions.py +47 -1
- {together-1.1.2 → together-1.1.4}/src/together/types/chat_completions.py +18 -1
- {together-1.1.2 → together-1.1.4}/src/together/types/completions.py +19 -1
- {together-1.1.2 → together-1.1.4}/LICENSE +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/__init__.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/abstract/__init__.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/abstract/api_requestor.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/cli/__init__.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/cli/api/__init__.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/cli/api/files.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/cli/api/images.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/cli/api/models.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/cli/cli.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/client.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/constants.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/error.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/filemanager.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/legacy/__init__.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/legacy/base.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/legacy/complete.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/legacy/embeddings.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/legacy/files.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/legacy/finetune.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/legacy/images.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/legacy/models.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/resources/__init__.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/resources/chat/__init__.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/resources/embeddings.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/resources/files.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/resources/finetune.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/resources/images.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/resources/models.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/together_response.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/types/__init__.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/types/abstract.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/types/common.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/types/embeddings.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/types/error.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/types/files.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/types/finetune.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/types/images.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/types/models.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/utils/__init__.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/utils/_log.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/utils/api_helpers.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/utils/files.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/utils/tools.py +0 -0
- {together-1.1.2 → together-1.1.4}/src/together/version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: together
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.4
|
|
4
4
|
Summary: Python client for Together's Cloud Platform!
|
|
5
5
|
Home-page: https://github.com/togethercomputer/together-python
|
|
6
6
|
License: Apache-2.0
|
|
@@ -17,7 +17,7 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
18
|
Requires-Dist: aiohttp (>=3.9.3,<4.0.0)
|
|
19
19
|
Requires-Dist: click (>=8.1.7,<9.0.0)
|
|
20
|
-
Requires-Dist: eval-type-backport (>=0.1.3,<0.
|
|
20
|
+
Requires-Dist: eval-type-backport (>=0.1.3,<0.3.0)
|
|
21
21
|
Requires-Dist: filelock (>=3.13.1,<4.0.0)
|
|
22
22
|
Requires-Dist: numpy (>=1.23.5) ; python_version < "3.12"
|
|
23
23
|
Requires-Dist: numpy (>=1.26.0) ; python_version >= "3.12"
|
|
@@ -32,32 +32,46 @@ Project-URL: Bug Tracker, https://github.com/togethercomputer/together-python/is
|
|
|
32
32
|
Project-URL: Repository, https://github.com/togethercomputer/together-python
|
|
33
33
|
Description-Content-Type: text/markdown
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
<div align="center">
|
|
36
|
+
<a href="https://www.together.ai/">
|
|
37
|
+
<img alt="together.ai" height="100px" src="https://assets-global.website-files.com/64f6f2c0e3f4c5a91c1e823a/654693d569494912cfc0c0d4_favicon.svg">
|
|
38
|
+
</a>
|
|
39
|
+
</div>
|
|
36
40
|
|
|
37
|
-
#
|
|
41
|
+
# Together Python API library
|
|
42
|
+
|
|
43
|
+
[](https://pypi.org/project/together/)
|
|
44
|
+
[](https://discord.com/invite/9Rk6sSeWEG)
|
|
45
|
+
[](https://twitter.com/togethercompute)
|
|
46
|
+
|
|
47
|
+
The [Together Python API Library](https://pypi.org/project/together/) is the official Python client for Together's API platform, providing a convenient way for interacting with the REST APIs and enables easy integrations with Python 3.8+ applications with easy to use synchronous and asynchronous clients.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
38
52
|
|
|
39
53
|
> 🚧
|
|
40
|
-
> The
|
|
54
|
+
> The Library was rewritten in v1.0.0 released in April of 2024. There were significant changes made.
|
|
41
55
|
|
|
42
|
-
To install Together Python Library from
|
|
56
|
+
To install Together Python Library from PyPI, simply run:
|
|
43
57
|
|
|
44
58
|
```shell Shell
|
|
45
59
|
pip install --upgrade together
|
|
46
60
|
```
|
|
47
61
|
|
|
48
|
-
|
|
62
|
+
### Setting up API Key
|
|
49
63
|
|
|
50
64
|
> 🚧 You will need to create an account with [Together.ai](https://api.together.xyz/) to obtain a Together API Key.
|
|
51
65
|
|
|
52
66
|
Once logged in to the Together Playground, you can find available API keys in [this settings page](https://api.together.xyz/settings/api-keys).
|
|
53
67
|
|
|
54
|
-
|
|
68
|
+
#### Setting environment variable
|
|
55
69
|
|
|
56
70
|
```shell
|
|
57
71
|
export TOGETHER_API_KEY=xxxxx
|
|
58
72
|
```
|
|
59
73
|
|
|
60
|
-
|
|
74
|
+
#### Using the client
|
|
61
75
|
|
|
62
76
|
```python
|
|
63
77
|
from together import Together
|
|
@@ -65,11 +79,11 @@ from together import Together
|
|
|
65
79
|
client = Together(api_key="xxxxx")
|
|
66
80
|
```
|
|
67
81
|
|
|
68
|
-
This
|
|
82
|
+
This repo contains both a Python Library and a CLI. We'll demonstrate how to use both below.
|
|
69
83
|
|
|
70
|
-
|
|
84
|
+
## Usage – Python Client
|
|
71
85
|
|
|
72
|
-
|
|
86
|
+
### Chat Completions
|
|
73
87
|
|
|
74
88
|
```python
|
|
75
89
|
import os
|
|
@@ -84,7 +98,7 @@ response = client.chat.completions.create(
|
|
|
84
98
|
print(response.choices[0].message.content)
|
|
85
99
|
```
|
|
86
100
|
|
|
87
|
-
|
|
101
|
+
#### Streaming
|
|
88
102
|
|
|
89
103
|
```python
|
|
90
104
|
import os
|
|
@@ -101,7 +115,7 @@ for chunk in stream:
|
|
|
101
115
|
print(chunk.choices[0].delta.content or "", end="", flush=True)
|
|
102
116
|
```
|
|
103
117
|
|
|
104
|
-
|
|
118
|
+
#### Async usage
|
|
105
119
|
|
|
106
120
|
```python
|
|
107
121
|
import os, asyncio
|
|
@@ -130,7 +144,7 @@ async def async_chat_completion(messages):
|
|
|
130
144
|
asyncio.run(async_chat_completion(messages))
|
|
131
145
|
```
|
|
132
146
|
|
|
133
|
-
|
|
147
|
+
### Completions
|
|
134
148
|
|
|
135
149
|
Completions are for code and language models shown [here](https://docs.together.ai/docs/inference-models). Below, a code model example is shown.
|
|
136
150
|
|
|
@@ -143,11 +157,12 @@ client = Together(api_key=os.environ.get("TOGETHER_API_KEY"))
|
|
|
143
157
|
response = client.completions.create(
|
|
144
158
|
model="codellama/CodeLlama-34b-Python-hf",
|
|
145
159
|
prompt="Write a Next.js component with TailwindCSS for a header component.",
|
|
160
|
+
max_tokens=200,
|
|
146
161
|
)
|
|
147
162
|
print(response.choices[0].text)
|
|
148
163
|
```
|
|
149
164
|
|
|
150
|
-
|
|
165
|
+
#### Streaming
|
|
151
166
|
|
|
152
167
|
```python
|
|
153
168
|
import os
|
|
@@ -164,7 +179,7 @@ for chunk in stream:
|
|
|
164
179
|
print(chunk.choices[0].delta.content or "", end="", flush=True)
|
|
165
180
|
```
|
|
166
181
|
|
|
167
|
-
|
|
182
|
+
#### Async usage
|
|
168
183
|
|
|
169
184
|
```python
|
|
170
185
|
import os, asyncio
|
|
@@ -193,7 +208,7 @@ async def async_chat_completion(prompts):
|
|
|
193
208
|
asyncio.run(async_chat_completion(prompts))
|
|
194
209
|
```
|
|
195
210
|
|
|
196
|
-
|
|
211
|
+
### Image generation
|
|
197
212
|
|
|
198
213
|
```python
|
|
199
214
|
import os
|
|
@@ -210,7 +225,7 @@ response = client.images.generate(
|
|
|
210
225
|
print(response.data[0].b64_json)
|
|
211
226
|
```
|
|
212
227
|
|
|
213
|
-
|
|
228
|
+
### Embeddings
|
|
214
229
|
|
|
215
230
|
```python
|
|
216
231
|
from typing import List
|
|
@@ -229,7 +244,7 @@ embeddings = get_embeddings(input_texts, model='togethercomputer/m2-bert-80M-8k-
|
|
|
229
244
|
print(embeddings)
|
|
230
245
|
```
|
|
231
246
|
|
|
232
|
-
|
|
247
|
+
### Files
|
|
233
248
|
|
|
234
249
|
The files API is used for fine-tuning and allows developers to upload data to fine-tune on. It also has several methods to list all files, retrive files, and delete files. Please refer to our fine-tuning docs [here](https://docs.together.ai/docs/fine-tuning-python).
|
|
235
250
|
|
|
@@ -246,7 +261,7 @@ client.files.retrieve_content(id="file-d0d318cb-b7d9-493a-bd70-1cfe089d3815") #
|
|
|
246
261
|
client.files.delete(id="file-d0d318cb-b7d9-493a-bd70-1cfe089d3815") # deletes a file
|
|
247
262
|
```
|
|
248
263
|
|
|
249
|
-
|
|
264
|
+
### Fine-tunes
|
|
250
265
|
|
|
251
266
|
The finetune API is used for fine-tuning and allows developers to create finetuning jobs. It also has several methods to list all jobs, retrive statuses and get checkpoints. Please refer to our fine-tuning docs [here](https://docs.together.ai/docs/fine-tuning-python).
|
|
252
267
|
|
|
@@ -273,7 +288,7 @@ client.fine_tuning.list_events(id="ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b") #
|
|
|
273
288
|
client.fine_tuning.download(id="ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b") # downloads compressed fine-tuned model or checkpoint to local disk
|
|
274
289
|
```
|
|
275
290
|
|
|
276
|
-
|
|
291
|
+
### Models
|
|
277
292
|
|
|
278
293
|
This lists all the models that Together supports.
|
|
279
294
|
|
|
@@ -289,9 +304,9 @@ for model in models:
|
|
|
289
304
|
print(model)
|
|
290
305
|
```
|
|
291
306
|
|
|
292
|
-
|
|
307
|
+
## Usage – CLI
|
|
293
308
|
|
|
294
|
-
|
|
309
|
+
### Chat Completions
|
|
295
310
|
|
|
296
311
|
```bash
|
|
297
312
|
together chat.completions \
|
|
@@ -302,7 +317,7 @@ together chat.completions \
|
|
|
302
317
|
|
|
303
318
|
The Chat Completions CLI enables streaming tokens to stdout by default. To disable streaming, use `--no-stream`.
|
|
304
319
|
|
|
305
|
-
|
|
320
|
+
### Completions
|
|
306
321
|
|
|
307
322
|
```bash
|
|
308
323
|
together completions \
|
|
@@ -314,7 +329,7 @@ together completions \
|
|
|
314
329
|
|
|
315
330
|
The Completions CLI enables streaming tokens to stdout by default. To disable streaming, use `--no-stream`.
|
|
316
331
|
|
|
317
|
-
|
|
332
|
+
### Image Generations
|
|
318
333
|
|
|
319
334
|
```bash
|
|
320
335
|
together images generate \
|
|
@@ -325,7 +340,7 @@ together images generate \
|
|
|
325
340
|
|
|
326
341
|
The image is opened in the default image viewer by default. To disable this, use `--no-show`.
|
|
327
342
|
|
|
328
|
-
|
|
343
|
+
### Files
|
|
329
344
|
|
|
330
345
|
```bash
|
|
331
346
|
# Help
|
|
@@ -350,7 +365,7 @@ together files retrieve-content file-6f50f9d1-5b95-416c-9040-0799b2b4b894
|
|
|
350
365
|
together files delete file-6f50f9d1-5b95-416c-9040-0799b2b4b894
|
|
351
366
|
```
|
|
352
367
|
|
|
353
|
-
|
|
368
|
+
### Fine-tuning
|
|
354
369
|
|
|
355
370
|
```bash
|
|
356
371
|
# Help
|
|
@@ -377,7 +392,7 @@ together fine-tuning cancel ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
|
|
|
377
392
|
together fine-tuning download ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
|
|
378
393
|
```
|
|
379
394
|
|
|
380
|
-
|
|
395
|
+
### Models
|
|
381
396
|
|
|
382
397
|
```bash
|
|
383
398
|
# Help
|
|
@@ -1,29 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://www.together.ai/">
|
|
3
|
+
<img alt="together.ai" height="100px" src="https://assets-global.website-files.com/64f6f2c0e3f4c5a91c1e823a/654693d569494912cfc0c0d4_favicon.svg">
|
|
4
|
+
</a>
|
|
5
|
+
</div>
|
|
2
6
|
|
|
3
|
-
#
|
|
7
|
+
# Together Python API library
|
|
8
|
+
|
|
9
|
+
[](https://pypi.org/project/together/)
|
|
10
|
+
[](https://discord.com/invite/9Rk6sSeWEG)
|
|
11
|
+
[](https://twitter.com/togethercompute)
|
|
12
|
+
|
|
13
|
+
The [Together Python API Library](https://pypi.org/project/together/) is the official Python client for Together's API platform, providing a convenient way for interacting with the REST APIs and enables easy integrations with Python 3.8+ applications with easy to use synchronous and asynchronous clients.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
4
18
|
|
|
5
19
|
> 🚧
|
|
6
|
-
> The
|
|
20
|
+
> The Library was rewritten in v1.0.0 released in April of 2024. There were significant changes made.
|
|
7
21
|
|
|
8
|
-
To install Together Python Library from
|
|
22
|
+
To install Together Python Library from PyPI, simply run:
|
|
9
23
|
|
|
10
24
|
```shell Shell
|
|
11
25
|
pip install --upgrade together
|
|
12
26
|
```
|
|
13
27
|
|
|
14
|
-
|
|
28
|
+
### Setting up API Key
|
|
15
29
|
|
|
16
30
|
> 🚧 You will need to create an account with [Together.ai](https://api.together.xyz/) to obtain a Together API Key.
|
|
17
31
|
|
|
18
32
|
Once logged in to the Together Playground, you can find available API keys in [this settings page](https://api.together.xyz/settings/api-keys).
|
|
19
33
|
|
|
20
|
-
|
|
34
|
+
#### Setting environment variable
|
|
21
35
|
|
|
22
36
|
```shell
|
|
23
37
|
export TOGETHER_API_KEY=xxxxx
|
|
24
38
|
```
|
|
25
39
|
|
|
26
|
-
|
|
40
|
+
#### Using the client
|
|
27
41
|
|
|
28
42
|
```python
|
|
29
43
|
from together import Together
|
|
@@ -31,11 +45,11 @@ from together import Together
|
|
|
31
45
|
client = Together(api_key="xxxxx")
|
|
32
46
|
```
|
|
33
47
|
|
|
34
|
-
This
|
|
48
|
+
This repo contains both a Python Library and a CLI. We'll demonstrate how to use both below.
|
|
35
49
|
|
|
36
|
-
|
|
50
|
+
## Usage – Python Client
|
|
37
51
|
|
|
38
|
-
|
|
52
|
+
### Chat Completions
|
|
39
53
|
|
|
40
54
|
```python
|
|
41
55
|
import os
|
|
@@ -50,7 +64,7 @@ response = client.chat.completions.create(
|
|
|
50
64
|
print(response.choices[0].message.content)
|
|
51
65
|
```
|
|
52
66
|
|
|
53
|
-
|
|
67
|
+
#### Streaming
|
|
54
68
|
|
|
55
69
|
```python
|
|
56
70
|
import os
|
|
@@ -67,7 +81,7 @@ for chunk in stream:
|
|
|
67
81
|
print(chunk.choices[0].delta.content or "", end="", flush=True)
|
|
68
82
|
```
|
|
69
83
|
|
|
70
|
-
|
|
84
|
+
#### Async usage
|
|
71
85
|
|
|
72
86
|
```python
|
|
73
87
|
import os, asyncio
|
|
@@ -96,7 +110,7 @@ async def async_chat_completion(messages):
|
|
|
96
110
|
asyncio.run(async_chat_completion(messages))
|
|
97
111
|
```
|
|
98
112
|
|
|
99
|
-
|
|
113
|
+
### Completions
|
|
100
114
|
|
|
101
115
|
Completions are for code and language models shown [here](https://docs.together.ai/docs/inference-models). Below, a code model example is shown.
|
|
102
116
|
|
|
@@ -109,11 +123,12 @@ client = Together(api_key=os.environ.get("TOGETHER_API_KEY"))
|
|
|
109
123
|
response = client.completions.create(
|
|
110
124
|
model="codellama/CodeLlama-34b-Python-hf",
|
|
111
125
|
prompt="Write a Next.js component with TailwindCSS for a header component.",
|
|
126
|
+
max_tokens=200,
|
|
112
127
|
)
|
|
113
128
|
print(response.choices[0].text)
|
|
114
129
|
```
|
|
115
130
|
|
|
116
|
-
|
|
131
|
+
#### Streaming
|
|
117
132
|
|
|
118
133
|
```python
|
|
119
134
|
import os
|
|
@@ -130,7 +145,7 @@ for chunk in stream:
|
|
|
130
145
|
print(chunk.choices[0].delta.content or "", end="", flush=True)
|
|
131
146
|
```
|
|
132
147
|
|
|
133
|
-
|
|
148
|
+
#### Async usage
|
|
134
149
|
|
|
135
150
|
```python
|
|
136
151
|
import os, asyncio
|
|
@@ -159,7 +174,7 @@ async def async_chat_completion(prompts):
|
|
|
159
174
|
asyncio.run(async_chat_completion(prompts))
|
|
160
175
|
```
|
|
161
176
|
|
|
162
|
-
|
|
177
|
+
### Image generation
|
|
163
178
|
|
|
164
179
|
```python
|
|
165
180
|
import os
|
|
@@ -176,7 +191,7 @@ response = client.images.generate(
|
|
|
176
191
|
print(response.data[0].b64_json)
|
|
177
192
|
```
|
|
178
193
|
|
|
179
|
-
|
|
194
|
+
### Embeddings
|
|
180
195
|
|
|
181
196
|
```python
|
|
182
197
|
from typing import List
|
|
@@ -195,7 +210,7 @@ embeddings = get_embeddings(input_texts, model='togethercomputer/m2-bert-80M-8k-
|
|
|
195
210
|
print(embeddings)
|
|
196
211
|
```
|
|
197
212
|
|
|
198
|
-
|
|
213
|
+
### Files
|
|
199
214
|
|
|
200
215
|
The files API is used for fine-tuning and allows developers to upload data to fine-tune on. It also has several methods to list all files, retrive files, and delete files. Please refer to our fine-tuning docs [here](https://docs.together.ai/docs/fine-tuning-python).
|
|
201
216
|
|
|
@@ -212,7 +227,7 @@ client.files.retrieve_content(id="file-d0d318cb-b7d9-493a-bd70-1cfe089d3815") #
|
|
|
212
227
|
client.files.delete(id="file-d0d318cb-b7d9-493a-bd70-1cfe089d3815") # deletes a file
|
|
213
228
|
```
|
|
214
229
|
|
|
215
|
-
|
|
230
|
+
### Fine-tunes
|
|
216
231
|
|
|
217
232
|
The finetune API is used for fine-tuning and allows developers to create finetuning jobs. It also has several methods to list all jobs, retrive statuses and get checkpoints. Please refer to our fine-tuning docs [here](https://docs.together.ai/docs/fine-tuning-python).
|
|
218
233
|
|
|
@@ -239,7 +254,7 @@ client.fine_tuning.list_events(id="ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b") #
|
|
|
239
254
|
client.fine_tuning.download(id="ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b") # downloads compressed fine-tuned model or checkpoint to local disk
|
|
240
255
|
```
|
|
241
256
|
|
|
242
|
-
|
|
257
|
+
### Models
|
|
243
258
|
|
|
244
259
|
This lists all the models that Together supports.
|
|
245
260
|
|
|
@@ -255,9 +270,9 @@ for model in models:
|
|
|
255
270
|
print(model)
|
|
256
271
|
```
|
|
257
272
|
|
|
258
|
-
|
|
273
|
+
## Usage – CLI
|
|
259
274
|
|
|
260
|
-
|
|
275
|
+
### Chat Completions
|
|
261
276
|
|
|
262
277
|
```bash
|
|
263
278
|
together chat.completions \
|
|
@@ -268,7 +283,7 @@ together chat.completions \
|
|
|
268
283
|
|
|
269
284
|
The Chat Completions CLI enables streaming tokens to stdout by default. To disable streaming, use `--no-stream`.
|
|
270
285
|
|
|
271
|
-
|
|
286
|
+
### Completions
|
|
272
287
|
|
|
273
288
|
```bash
|
|
274
289
|
together completions \
|
|
@@ -280,7 +295,7 @@ together completions \
|
|
|
280
295
|
|
|
281
296
|
The Completions CLI enables streaming tokens to stdout by default. To disable streaming, use `--no-stream`.
|
|
282
297
|
|
|
283
|
-
|
|
298
|
+
### Image Generations
|
|
284
299
|
|
|
285
300
|
```bash
|
|
286
301
|
together images generate \
|
|
@@ -291,7 +306,7 @@ together images generate \
|
|
|
291
306
|
|
|
292
307
|
The image is opened in the default image viewer by default. To disable this, use `--no-show`.
|
|
293
308
|
|
|
294
|
-
|
|
309
|
+
### Files
|
|
295
310
|
|
|
296
311
|
```bash
|
|
297
312
|
# Help
|
|
@@ -316,7 +331,7 @@ together files retrieve-content file-6f50f9d1-5b95-416c-9040-0799b2b4b894
|
|
|
316
331
|
together files delete file-6f50f9d1-5b95-416c-9040-0799b2b4b894
|
|
317
332
|
```
|
|
318
333
|
|
|
319
|
-
|
|
334
|
+
### Fine-tuning
|
|
320
335
|
|
|
321
336
|
```bash
|
|
322
337
|
# Help
|
|
@@ -343,7 +358,7 @@ together fine-tuning cancel ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
|
|
|
343
358
|
together fine-tuning download ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
|
|
344
359
|
```
|
|
345
360
|
|
|
346
|
-
|
|
361
|
+
### Models
|
|
347
362
|
|
|
348
363
|
```bash
|
|
349
364
|
# Help
|
|
@@ -12,7 +12,7 @@ build-backend = "poetry.masonry.api"
|
|
|
12
12
|
|
|
13
13
|
[tool.poetry]
|
|
14
14
|
name = "together"
|
|
15
|
-
version = "1.1.
|
|
15
|
+
version = "1.1.4"
|
|
16
16
|
authors = [
|
|
17
17
|
"Together AI <support@together.ai>"
|
|
18
18
|
]
|
|
@@ -36,7 +36,7 @@ tabulate = "^0.9.0"
|
|
|
36
36
|
pydantic = "^2.6.3"
|
|
37
37
|
aiohttp = "^3.9.3"
|
|
38
38
|
filelock = "^3.13.1"
|
|
39
|
-
eval-type-backport = "
|
|
39
|
+
eval-type-backport = ">=0.1.3,<0.3.0"
|
|
40
40
|
click = "^8.1.7"
|
|
41
41
|
pillow = "^10.3.0"
|
|
42
42
|
pyarrow = ">=10.0.1"
|
|
@@ -50,7 +50,7 @@ optional = true
|
|
|
50
50
|
|
|
51
51
|
[tool.poetry.group.quality.dependencies]
|
|
52
52
|
black = ">=23.1,<25.0"
|
|
53
|
-
ruff = "
|
|
53
|
+
ruff = ">=0.3.2,<0.5.0"
|
|
54
54
|
types-tqdm = "^4.65.0.0"
|
|
55
55
|
types-tabulate = "^0.9.0.3"
|
|
56
56
|
pre-commit = "3.5.0"
|
|
@@ -66,6 +66,13 @@ pytest = ">=7.4.2,<9.0.0"
|
|
|
66
66
|
pytest-watch = "^4.2.0"
|
|
67
67
|
tox = "^4.14.1"
|
|
68
68
|
|
|
69
|
+
[tool.poetry.group.examples]
|
|
70
|
+
optional = true
|
|
71
|
+
|
|
72
|
+
[tool.poetry.group.examples.dependencies]
|
|
73
|
+
datasets = "^2.18.0"
|
|
74
|
+
transformers = "^4.39.3"
|
|
75
|
+
|
|
69
76
|
|
|
70
77
|
[tool.poetry.urls]
|
|
71
78
|
"Homepage" = "https://github.com/togethercomputer/together-python"
|
|
@@ -28,6 +28,9 @@ class ChatShell(cmd.Cmd):
|
|
|
28
28
|
top_p: float | None = None,
|
|
29
29
|
top_k: int | None = None,
|
|
30
30
|
repetition_penalty: float | None = None,
|
|
31
|
+
presence_penalty: float | None = None,
|
|
32
|
+
frequency_penalty: float | None = None,
|
|
33
|
+
min_p: float | None = None,
|
|
31
34
|
safety_model: str | None = None,
|
|
32
35
|
system_message: str | None = None,
|
|
33
36
|
) -> None:
|
|
@@ -40,6 +43,9 @@ class ChatShell(cmd.Cmd):
|
|
|
40
43
|
self.top_p = top_p
|
|
41
44
|
self.top_k = top_k
|
|
42
45
|
self.repetition_penalty = repetition_penalty
|
|
46
|
+
self.presence_penalty = presence_penalty
|
|
47
|
+
self.frequency_penalty = frequency_penalty
|
|
48
|
+
self.min_p = min_p
|
|
43
49
|
self.safety_model = safety_model
|
|
44
50
|
self.system_message = system_message
|
|
45
51
|
|
|
@@ -69,6 +75,9 @@ class ChatShell(cmd.Cmd):
|
|
|
69
75
|
top_p=self.top_p,
|
|
70
76
|
top_k=self.top_k,
|
|
71
77
|
repetition_penalty=self.repetition_penalty,
|
|
78
|
+
presence_penalty=self.presence_penalty,
|
|
79
|
+
frequency_penalty=self.frequency_penalty,
|
|
80
|
+
min_p=self.min_p,
|
|
72
81
|
safety_model=self.safety_model,
|
|
73
82
|
stream=True,
|
|
74
83
|
):
|
|
@@ -76,13 +85,12 @@ class ChatShell(cmd.Cmd):
|
|
|
76
85
|
assert isinstance(chunk, ChatCompletionChunk)
|
|
77
86
|
assert chunk.choices
|
|
78
87
|
assert chunk.choices[0].delta
|
|
79
|
-
assert chunk.choices[0].delta.content
|
|
80
88
|
|
|
81
89
|
token = chunk.choices[0].delta.content
|
|
82
90
|
|
|
83
91
|
click.echo(token, nl=False)
|
|
84
92
|
|
|
85
|
-
output += token
|
|
93
|
+
output += token or ""
|
|
86
94
|
|
|
87
95
|
click.echo("\n")
|
|
88
96
|
|
|
@@ -109,6 +117,10 @@ class ChatShell(cmd.Cmd):
|
|
|
109
117
|
@click.option("--temperature", type=float, help="Sampling temperature")
|
|
110
118
|
@click.option("--top-p", type=int, help="Top p sampling")
|
|
111
119
|
@click.option("--top-k", type=float, help="Top k sampling")
|
|
120
|
+
@click.option("--repetition-penalty", type=float, help="Repetition penalty")
|
|
121
|
+
@click.option("--presence-penalty", type=float, help="Presence penalty")
|
|
122
|
+
@click.option("--frequency-penalty", type=float, help="Frequency penalty")
|
|
123
|
+
@click.option("--min-p", type=float, help="Minimum p")
|
|
112
124
|
@click.option("--safety-model", type=str, help="Moderation model")
|
|
113
125
|
@click.option("--system-message", type=str, help="System message to use for the chat")
|
|
114
126
|
def interactive(
|
|
@@ -120,6 +132,9 @@ def interactive(
|
|
|
120
132
|
top_p: float | None = None,
|
|
121
133
|
top_k: int | None = None,
|
|
122
134
|
repetition_penalty: float | None = None,
|
|
135
|
+
presence_penalty: float | None = None,
|
|
136
|
+
frequency_penalty: float | None = None,
|
|
137
|
+
min_p: float | None = None,
|
|
123
138
|
safety_model: str | None = None,
|
|
124
139
|
system_message: str | None = None,
|
|
125
140
|
) -> None:
|
|
@@ -135,6 +150,9 @@ def interactive(
|
|
|
135
150
|
top_p=top_p,
|
|
136
151
|
top_k=top_k,
|
|
137
152
|
repetition_penalty=repetition_penalty,
|
|
153
|
+
presence_penalty=presence_penalty,
|
|
154
|
+
frequency_penalty=frequency_penalty,
|
|
155
|
+
min_p=min_p,
|
|
138
156
|
safety_model=safety_model,
|
|
139
157
|
system_message=system_message,
|
|
140
158
|
).cmdloop()
|
|
@@ -158,6 +176,11 @@ def interactive(
|
|
|
158
176
|
@click.option("--top-p", type=int, help="Top p sampling")
|
|
159
177
|
@click.option("--top-k", type=float, help="Top k sampling")
|
|
160
178
|
@click.option("--repetition-penalty", type=float, help="Repetition penalty")
|
|
179
|
+
@click.option("--presence-penalty", type=float, help="Presence penalty sampling method")
|
|
180
|
+
@click.option(
|
|
181
|
+
"--frequency-penalty", type=float, help="Frequency penalty sampling method"
|
|
182
|
+
)
|
|
183
|
+
@click.option("--min-p", type=float, help="Min p sampling")
|
|
161
184
|
@click.option("--no-stream", is_flag=True, help="Disable streaming")
|
|
162
185
|
@click.option("--logprobs", type=int, help="Return logprobs. Only works with --raw.")
|
|
163
186
|
@click.option("--echo", is_flag=True, help="Echo prompt. Only works with --raw.")
|
|
@@ -174,6 +197,9 @@ def chat(
|
|
|
174
197
|
top_p: float | None = None,
|
|
175
198
|
top_k: int | None = None,
|
|
176
199
|
repetition_penalty: float | None = None,
|
|
200
|
+
presence_penalty: float | None = None,
|
|
201
|
+
frequency_penalty: float | None = None,
|
|
202
|
+
min_p: float | None = None,
|
|
177
203
|
no_stream: bool = False,
|
|
178
204
|
logprobs: int | None = None,
|
|
179
205
|
echo: bool | None = None,
|
|
@@ -195,6 +221,9 @@ def chat(
|
|
|
195
221
|
max_tokens=max_tokens,
|
|
196
222
|
stop=stop,
|
|
197
223
|
repetition_penalty=repetition_penalty,
|
|
224
|
+
presence_penalty=presence_penalty,
|
|
225
|
+
frequency_penalty=frequency_penalty,
|
|
226
|
+
min_p=min_p,
|
|
198
227
|
stream=not no_stream,
|
|
199
228
|
logprobs=logprobs,
|
|
200
229
|
echo=echo,
|
|
@@ -14,7 +14,6 @@ from together.types.completions import CompletionChoicesChunk, CompletionRespons
|
|
|
14
14
|
@click.pass_context
|
|
15
15
|
@click.argument("prompt", type=str, required=True)
|
|
16
16
|
@click.option("--model", type=str, required=True, help="Model name")
|
|
17
|
-
@click.option("--no-stream", is_flag=True, help="Disable streaming")
|
|
18
17
|
@click.option("--max-tokens", type=int, help="Max tokens to generate")
|
|
19
18
|
@click.option(
|
|
20
19
|
"--stop", type=str, multiple=True, help="List of strings to stop generation"
|
|
@@ -22,6 +21,11 @@ from together.types.completions import CompletionChoicesChunk, CompletionRespons
|
|
|
22
21
|
@click.option("--temperature", type=float, help="Sampling temperature")
|
|
23
22
|
@click.option("--top-p", type=int, help="Top p sampling")
|
|
24
23
|
@click.option("--top-k", type=float, help="Top k sampling")
|
|
24
|
+
@click.option("--repetition-penalty", type=float, help="Repetition penalty")
|
|
25
|
+
@click.option("--presence-penalty", type=float, help="Presence penalty")
|
|
26
|
+
@click.option("--frequency-penalty", type=float, help="Frequency penalty")
|
|
27
|
+
@click.option("--min-p", type=float, help="Minimum p")
|
|
28
|
+
@click.option("--no-stream", is_flag=True, help="Disable streaming")
|
|
25
29
|
@click.option("--logprobs", type=int, help="Return logprobs. Only works with --raw.")
|
|
26
30
|
@click.option("--echo", is_flag=True, help="Echo prompt. Only works with --raw.")
|
|
27
31
|
@click.option("--n", type=int, help="Number of output generations")
|
|
@@ -37,6 +41,9 @@ def completions(
|
|
|
37
41
|
top_p: float | None = None,
|
|
38
42
|
top_k: int | None = None,
|
|
39
43
|
repetition_penalty: float | None = None,
|
|
44
|
+
presence_penalty: float | None = None,
|
|
45
|
+
frequency_penalty: float | None = None,
|
|
46
|
+
min_p: float | None = None,
|
|
40
47
|
no_stream: bool = False,
|
|
41
48
|
logprobs: int | None = None,
|
|
42
49
|
echo: bool | None = None,
|
|
@@ -56,6 +63,9 @@ def completions(
|
|
|
56
63
|
max_tokens=max_tokens,
|
|
57
64
|
stop=stop,
|
|
58
65
|
repetition_penalty=repetition_penalty,
|
|
66
|
+
presence_penalty=presence_penalty,
|
|
67
|
+
frequency_penalty=frequency_penalty,
|
|
68
|
+
min_p=min_p,
|
|
59
69
|
stream=not no_stream,
|
|
60
70
|
logprobs=logprobs,
|
|
61
71
|
echo=echo,
|
|
@@ -107,10 +107,20 @@ def retrieve(ctx: click.Context, fine_tune_id: str) -> None:
|
|
|
107
107
|
@fine_tuning.command()
|
|
108
108
|
@click.pass_context
|
|
109
109
|
@click.argument("fine_tune_id", type=str, required=True)
|
|
110
|
-
|
|
110
|
+
@click.option(
|
|
111
|
+
"--quiet", is_flag=True, help="Do not prompt for confirmation before cancelling job"
|
|
112
|
+
)
|
|
113
|
+
def cancel(ctx: click.Context, fine_tune_id: str, quiet: bool = False) -> None:
|
|
111
114
|
"""Cancel fine-tuning job"""
|
|
112
115
|
client: Together = ctx.obj
|
|
113
|
-
|
|
116
|
+
if not quiet:
|
|
117
|
+
confirm_response = input(
|
|
118
|
+
"You will be billed for any completed training steps upon cancellation. "
|
|
119
|
+
f"Do you want to cancel job {fine_tune_id}? [y/N]"
|
|
120
|
+
)
|
|
121
|
+
if "y" not in confirm_response.lower():
|
|
122
|
+
click.echo({"status": "Cancel not submitted"})
|
|
123
|
+
return
|
|
114
124
|
response = client.fine_tuning.cancel(fine_tune_id)
|
|
115
125
|
|
|
116
126
|
click.echo(json.dumps(response.model_dump(), indent=4))
|
|
@@ -28,6 +28,10 @@ class ChatCompletions:
|
|
|
28
28
|
top_p: float | None = None,
|
|
29
29
|
top_k: int | None = None,
|
|
30
30
|
repetition_penalty: float | None = None,
|
|
31
|
+
presence_penalty: float | None = None,
|
|
32
|
+
frequency_penalty: float | None = None,
|
|
33
|
+
min_p: float | None = None,
|
|
34
|
+
logit_bias: Dict[str, float] | None = None,
|
|
31
35
|
stream: bool = False,
|
|
32
36
|
logprobs: int | None = None,
|
|
33
37
|
echo: bool | None = None,
|
|
@@ -59,6 +63,21 @@ class ChatCompletions:
|
|
|
59
63
|
repetition_penalty (float, optional): A number that controls the diversity of generated text
|
|
60
64
|
by reducing the likelihood of repeated sequences. Higher values decrease repetition.
|
|
61
65
|
Defaults to None.
|
|
66
|
+
presence_penalty (float, optional): A number that controls the likelihood of tokens based on if they have
|
|
67
|
+
appeared in the text. Positive values decrease the likelihood of repeated tokens or phrases.
|
|
68
|
+
Must be in the range [-2, 2].
|
|
69
|
+
Defaults to None.
|
|
70
|
+
frequency_penalty (float, optional): A number that controls the likelihood of tokens based on the frequency
|
|
71
|
+
of their appearance in the text. Positive decrease the likelihood of repeated tokens or phrases.
|
|
72
|
+
Must be in the range [-2, 2].
|
|
73
|
+
Defaults to None.
|
|
74
|
+
min_p (float, optional): A number that controls the minimum percentage value that a token must reach to
|
|
75
|
+
be considered during sampling.
|
|
76
|
+
Must be in the range [0, 1].
|
|
77
|
+
Defaults to None.
|
|
78
|
+
logit_bias (Dict[str, float], optional): A dictionary of tokens and their bias values that modify the
|
|
79
|
+
likelihood of specific tokens being sampled. Bias values must be in the range [-100, 100].
|
|
80
|
+
Defaults to None.
|
|
62
81
|
stream (bool, optional): Flag indicating whether to stream the generated completions.
|
|
63
82
|
Defaults to False.
|
|
64
83
|
logprobs (int, optional): Number of top-k logprobs to return
|
|
@@ -100,6 +119,10 @@ class ChatCompletions:
|
|
|
100
119
|
max_tokens=max_tokens,
|
|
101
120
|
stop=stop,
|
|
102
121
|
repetition_penalty=repetition_penalty,
|
|
122
|
+
presence_penalty=presence_penalty,
|
|
123
|
+
frequency_penalty=frequency_penalty,
|
|
124
|
+
min_p=min_p,
|
|
125
|
+
logit_bias=logit_bias,
|
|
103
126
|
stream=stream,
|
|
104
127
|
logprobs=logprobs,
|
|
105
128
|
echo=echo,
|
|
@@ -142,6 +165,10 @@ class AsyncChatCompletions:
|
|
|
142
165
|
top_p: float | None = None,
|
|
143
166
|
top_k: int | None = None,
|
|
144
167
|
repetition_penalty: float | None = None,
|
|
168
|
+
presence_penalty: float | None = None,
|
|
169
|
+
frequency_penalty: float | None = None,
|
|
170
|
+
min_p: float | None = None,
|
|
171
|
+
logit_bias: Dict[str, float] | None = None,
|
|
145
172
|
stream: bool = False,
|
|
146
173
|
logprobs: int | None = None,
|
|
147
174
|
echo: bool | None = None,
|
|
@@ -173,6 +200,21 @@ class AsyncChatCompletions:
|
|
|
173
200
|
repetition_penalty (float, optional): A number that controls the diversity of generated text
|
|
174
201
|
by reducing the likelihood of repeated sequences. Higher values decrease repetition.
|
|
175
202
|
Defaults to None.
|
|
203
|
+
presence_penalty (float, optional): A number that controls the likelihood of tokens based on if they have
|
|
204
|
+
appeared in the text. Positive values decrease the likelihood of repeated tokens or phrases.
|
|
205
|
+
Must be in the range [-2, 2].
|
|
206
|
+
Defaults to None.
|
|
207
|
+
frequency_penalty (float, optional): A number that controls the likelihood of tokens based on the frequency
|
|
208
|
+
of their appearance in the text. Positive decrease the likelihood of repeated tokens or phrases.
|
|
209
|
+
Must be in the range [-2, 2].
|
|
210
|
+
Defaults to None.
|
|
211
|
+
min_p (float, optional): A number that controls the minimum percentage value that a token must reach to
|
|
212
|
+
be considered during sampling.
|
|
213
|
+
Must be in the range [0, 1].
|
|
214
|
+
Defaults to None.
|
|
215
|
+
logit_bias (Dict[str, float], optional): A dictionary of tokens and their bias values that modify the
|
|
216
|
+
likelihood of specific tokens being sampled. Bias values must be in the range [-100, 100].
|
|
217
|
+
Defaults to None.
|
|
176
218
|
stream (bool, optional): Flag indicating whether to stream the generated completions.
|
|
177
219
|
Defaults to False.
|
|
178
220
|
logprobs (int, optional): Number of top-k logprobs to return
|
|
@@ -214,6 +256,10 @@ class AsyncChatCompletions:
|
|
|
214
256
|
max_tokens=max_tokens,
|
|
215
257
|
stop=stop,
|
|
216
258
|
repetition_penalty=repetition_penalty,
|
|
259
|
+
presence_penalty=presence_penalty,
|
|
260
|
+
frequency_penalty=frequency_penalty,
|
|
261
|
+
min_p=min_p,
|
|
262
|
+
logit_bias=logit_bias,
|
|
217
263
|
stream=stream,
|
|
218
264
|
logprobs=logprobs,
|
|
219
265
|
echo=echo,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import AsyncGenerator, Iterator, List
|
|
3
|
+
from typing import AsyncGenerator, Dict, Iterator, List
|
|
4
4
|
|
|
5
5
|
from together.abstract import api_requestor
|
|
6
6
|
from together.together_response import TogetherResponse
|
|
@@ -28,6 +28,10 @@ class Completions:
|
|
|
28
28
|
top_p: float | None = None,
|
|
29
29
|
top_k: int | None = None,
|
|
30
30
|
repetition_penalty: float | None = None,
|
|
31
|
+
presence_penalty: float | None = None,
|
|
32
|
+
frequency_penalty: float | None = None,
|
|
33
|
+
min_p: float | None = None,
|
|
34
|
+
logit_bias: Dict[str, float] | None = None,
|
|
31
35
|
stream: bool = False,
|
|
32
36
|
logprobs: int | None = None,
|
|
33
37
|
echo: bool | None = None,
|
|
@@ -55,6 +59,21 @@ class Completions:
|
|
|
55
59
|
repetition_penalty (float, optional): A number that controls the diversity of generated text
|
|
56
60
|
by reducing the likelihood of repeated sequences. Higher values decrease repetition.
|
|
57
61
|
Defaults to None.
|
|
62
|
+
presence_penalty (float, optional): A number that controls the likelihood of tokens based on if they have
|
|
63
|
+
appeared in the text. Positive values decrease the likelihood of repeated tokens or phrases.
|
|
64
|
+
Must be in the range [-2, 2].
|
|
65
|
+
Defaults to None.
|
|
66
|
+
frequency_penalty (float, optional): A number that controls the likelihood of tokens based on the frequency
|
|
67
|
+
of their appearance in the text. Positive decrease the likelihood of repeated tokens or phrases.
|
|
68
|
+
Must be in the range [-2, 2].
|
|
69
|
+
Defaults to None.
|
|
70
|
+
min_p (float, optional): A number that controls the minimum percentage value that a token must reach to
|
|
71
|
+
be considered during sampling.
|
|
72
|
+
Must be in the range [0, 1].
|
|
73
|
+
Defaults to None.
|
|
74
|
+
logit_bias (Dict[str, float], optional): A dictionary of tokens and their bias values that modify the
|
|
75
|
+
likelihood of specific tokens being sampled. Bias values must be in the range [-100, 100].
|
|
76
|
+
Defaults to None.
|
|
58
77
|
stream (bool, optional): Flag indicating whether to stream the generated completions.
|
|
59
78
|
Defaults to False.
|
|
60
79
|
logprobs (int, optional): Number of top-k logprobs to return
|
|
@@ -85,6 +104,10 @@ class Completions:
|
|
|
85
104
|
max_tokens=max_tokens,
|
|
86
105
|
stop=stop,
|
|
87
106
|
repetition_penalty=repetition_penalty,
|
|
107
|
+
presence_penalty=presence_penalty,
|
|
108
|
+
frequency_penalty=frequency_penalty,
|
|
109
|
+
min_p=min_p,
|
|
110
|
+
logit_bias=logit_bias,
|
|
88
111
|
stream=stream,
|
|
89
112
|
logprobs=logprobs,
|
|
90
113
|
echo=echo,
|
|
@@ -124,6 +147,10 @@ class AsyncCompletions:
|
|
|
124
147
|
top_p: float | None = None,
|
|
125
148
|
top_k: int | None = None,
|
|
126
149
|
repetition_penalty: float | None = None,
|
|
150
|
+
presence_penalty: float | None = None,
|
|
151
|
+
frequency_penalty: float | None = None,
|
|
152
|
+
min_p: float | None = None,
|
|
153
|
+
logit_bias: Dict[str, float] | None = None,
|
|
127
154
|
stream: bool = False,
|
|
128
155
|
logprobs: int | None = None,
|
|
129
156
|
echo: bool | None = None,
|
|
@@ -151,6 +178,21 @@ class AsyncCompletions:
|
|
|
151
178
|
repetition_penalty (float, optional): A number that controls the diversity of generated text
|
|
152
179
|
by reducing the likelihood of repeated sequences. Higher values decrease repetition.
|
|
153
180
|
Defaults to None.
|
|
181
|
+
presence_penalty (float, optional): A number that controls the likelihood of tokens based on if they have
|
|
182
|
+
appeared in the text. Positive values decrease the likelihood of repeated tokens or phrases.
|
|
183
|
+
Must be in the range [-2, 2].
|
|
184
|
+
Defaults to None.
|
|
185
|
+
frequency_penalty (float, optional): A number that controls the likelihood of tokens based on the frequency
|
|
186
|
+
of their appearance in the text. Positive decrease the likelihood of repeated tokens or phrases.
|
|
187
|
+
Must be in the range [-2, 2].
|
|
188
|
+
Defaults to None.
|
|
189
|
+
min_p (float, optional): A number that controls the minimum percentage value that a token must reach to
|
|
190
|
+
be considered during sampling.
|
|
191
|
+
Must be in the range [0, 1].
|
|
192
|
+
Defaults to None.
|
|
193
|
+
logit_bias (Dict[str, float], optional): A dictionary of tokens and their bias values that modify the
|
|
194
|
+
likelihood of specific tokens being sampled. Bias values must be in the range [-100, 100].
|
|
195
|
+
Defaults to None.
|
|
154
196
|
stream (bool, optional): Flag indicating whether to stream the generated completions.
|
|
155
197
|
Defaults to False.
|
|
156
198
|
logprobs (int, optional): Number of top-k logprobs to return
|
|
@@ -181,6 +223,10 @@ class AsyncCompletions:
|
|
|
181
223
|
max_tokens=max_tokens,
|
|
182
224
|
stop=stop,
|
|
183
225
|
repetition_penalty=repetition_penalty,
|
|
226
|
+
presence_penalty=presence_penalty,
|
|
227
|
+
frequency_penalty=frequency_penalty,
|
|
228
|
+
min_p=min_p,
|
|
229
|
+
logit_bias=logit_bias,
|
|
184
230
|
stream=stream,
|
|
185
231
|
logprobs=logprobs,
|
|
186
232
|
echo=echo,
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
import warnings
|
|
3
4
|
from enum import Enum
|
|
4
5
|
from typing import Any, Dict, List
|
|
5
6
|
|
|
6
|
-
from pydantic import Field
|
|
7
|
+
from pydantic import Field, model_validator
|
|
8
|
+
from typing_extensions import Self
|
|
7
9
|
|
|
8
10
|
from together.types.abstract import BaseModel
|
|
9
11
|
from together.types.common import (
|
|
@@ -20,6 +22,7 @@ class MessageRole(str, Enum):
|
|
|
20
22
|
ASSISTANT = "assistant"
|
|
21
23
|
SYSTEM = "system"
|
|
22
24
|
USER = "user"
|
|
25
|
+
TOOL = "tool"
|
|
23
26
|
|
|
24
27
|
|
|
25
28
|
class ResponseFormatType(str, Enum):
|
|
@@ -86,6 +89,10 @@ class ChatCompletionRequest(BaseModel):
|
|
|
86
89
|
top_p: float | None = None
|
|
87
90
|
top_k: int | None = None
|
|
88
91
|
repetition_penalty: float | None = None
|
|
92
|
+
presence_penalty: float | None = None
|
|
93
|
+
frequency_penalty: float | None = None
|
|
94
|
+
min_p: float | None = None
|
|
95
|
+
logit_bias: Dict[str, float] | None = None
|
|
89
96
|
# stream SSE token chunks
|
|
90
97
|
stream: bool = False
|
|
91
98
|
# return logprobs
|
|
@@ -102,6 +109,16 @@ class ChatCompletionRequest(BaseModel):
|
|
|
102
109
|
tools: List[Tools] | None = None
|
|
103
110
|
tool_choice: ToolChoice | ToolChoiceEnum | None = None
|
|
104
111
|
|
|
112
|
+
# Raise warning if repetition_penalty is used with presence_penalty or frequency_penalty
|
|
113
|
+
@model_validator(mode="after")
|
|
114
|
+
def verify_parameters(self) -> Self:
|
|
115
|
+
if self.repetition_penalty:
|
|
116
|
+
if self.presence_penalty or self.frequency_penalty:
|
|
117
|
+
warnings.warn(
|
|
118
|
+
"repetition_penalty is not advisable to be used alongside presence_penalty or frequency_penalty"
|
|
119
|
+
)
|
|
120
|
+
return self
|
|
121
|
+
|
|
105
122
|
|
|
106
123
|
class ChatCompletionChoicesData(BaseModel):
|
|
107
124
|
index: int | None = None
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import warnings
|
|
4
|
+
from typing import Dict, List
|
|
5
|
+
|
|
6
|
+
from pydantic import model_validator
|
|
7
|
+
from typing_extensions import Self
|
|
4
8
|
|
|
5
9
|
from together.types.abstract import BaseModel
|
|
6
10
|
from together.types.common import (
|
|
@@ -27,6 +31,10 @@ class CompletionRequest(BaseModel):
|
|
|
27
31
|
top_p: float | None = None
|
|
28
32
|
top_k: int | None = None
|
|
29
33
|
repetition_penalty: float | None = None
|
|
34
|
+
presence_penalty: float | None = None
|
|
35
|
+
frequency_penalty: float | None = None
|
|
36
|
+
min_p: float | None = None
|
|
37
|
+
logit_bias: Dict[str, float] | None = None
|
|
30
38
|
# stream SSE token chunks
|
|
31
39
|
stream: bool = False
|
|
32
40
|
# return logprobs
|
|
@@ -39,6 +47,16 @@ class CompletionRequest(BaseModel):
|
|
|
39
47
|
# moderation model
|
|
40
48
|
safety_model: str | None = None
|
|
41
49
|
|
|
50
|
+
# Raise warning if repetition_penalty is used with presence_penalty or frequency_penalty
|
|
51
|
+
@model_validator(mode="after")
|
|
52
|
+
def verify_parameters(self) -> Self:
|
|
53
|
+
if self.repetition_penalty:
|
|
54
|
+
if self.presence_penalty or self.frequency_penalty:
|
|
55
|
+
warnings.warn(
|
|
56
|
+
"repetition_penalty is not advisable to be used alongside presence_penalty or frequency_penalty"
|
|
57
|
+
)
|
|
58
|
+
return self
|
|
59
|
+
|
|
42
60
|
|
|
43
61
|
class CompletionChoicesData(BaseModel):
|
|
44
62
|
index: int
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|