together 0.1.1__py3-none-any.whl → 0.1.2__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 CHANGED
@@ -14,6 +14,7 @@ api_base = "https://api.together.xyz/"
14
14
  api_base_complete = urllib.parse.urljoin(api_base, "/api/inference")
15
15
  api_base_files = urllib.parse.urljoin(api_base, "/v1/files/")
16
16
  api_base_finetune = urllib.parse.urljoin(api_base, "/v1/fine-tunes/")
17
+ api_base_instances = urllib.parse.urljoin(api_base, "instances/")
17
18
 
18
19
  default_text_model = "togethercomputer/RedPajama-INCITE-7B-Chat"
19
20
  default_image_model = "runwayml/stable-diffusion-v1-5"
@@ -34,6 +35,7 @@ __all__ = [
34
35
  "api_base_complete",
35
36
  "api_base_files",
36
37
  "api_base_finetune",
38
+ "api_base_instances",
37
39
  "default_text_model",
38
40
  "default_image_model",
39
41
  "get_logger",
together/cli/cli.py CHANGED
@@ -12,6 +12,13 @@ def main() -> None:
12
12
  prog="together",
13
13
  )
14
14
 
15
+ parser.add_argument(
16
+ "-V",
17
+ "--version",
18
+ action="version",
19
+ version="%(prog)s " + together.version,
20
+ )
21
+
15
22
  parser.add_argument(
16
23
  "--endpoint",
17
24
  "-e",
@@ -33,19 +33,19 @@ def add_parser(subparsers: argparse._SubParsersAction[argparse.ArgumentParser])
33
33
 
34
34
  subparser.add_argument(
35
35
  "--height",
36
- default=512,
36
+ default=256,
37
37
  type=int,
38
38
  help="Pixel height for generated image results",
39
39
  )
40
40
  subparser.add_argument(
41
41
  "--width",
42
- default=512,
42
+ default=256,
43
43
  type=int,
44
44
  help="Pixel width for generated image results",
45
45
  )
46
46
  subparser.add_argument(
47
47
  "--steps",
48
- default=50,
48
+ default=20,
49
49
  type=int,
50
50
  help="Number of steps",
51
51
  )
@@ -16,6 +16,9 @@ def add_parser(
16
16
 
17
17
  _add_list(child_parsers)
18
18
  _add_info(child_parsers)
19
+ _add_instances(child_parsers)
20
+ _add_start(child_parsers)
21
+ _add_stop(child_parsers)
19
22
 
20
23
 
21
24
  def _add_list(
@@ -50,6 +53,45 @@ def _add_info(
50
53
  subparser.set_defaults(func=_run_info)
51
54
 
52
55
 
56
+ def _add_instances(
57
+ parser: argparse._SubParsersAction[argparse.ArgumentParser],
58
+ ) -> None:
59
+ subparser = parser.add_parser("instances")
60
+ subparser.add_argument(
61
+ "--raw",
62
+ help="Raw list of instances",
63
+ default=False,
64
+ action="store_true",
65
+ )
66
+ subparser.set_defaults(func=_run_instances)
67
+
68
+
69
+ def _add_start(
70
+ parser: argparse._SubParsersAction[argparse.ArgumentParser],
71
+ ) -> None:
72
+ subparser = parser.add_parser("start")
73
+ subparser.add_argument(
74
+ "model",
75
+ metavar="MODEL",
76
+ help="Proper Model API string name",
77
+ type=str,
78
+ )
79
+ subparser.set_defaults(func=_run_start)
80
+
81
+
82
+ def _add_stop(
83
+ parser: argparse._SubParsersAction[argparse.ArgumentParser],
84
+ ) -> None:
85
+ subparser = parser.add_parser("stop")
86
+ subparser.add_argument(
87
+ "model",
88
+ metavar="MODEL",
89
+ help="Proper Model API string name",
90
+ type=str,
91
+ )
92
+ subparser.set_defaults(func=_run_stop)
93
+
94
+
53
95
  def _run_list(args: argparse.Namespace) -> None:
54
96
  models = Models()
55
97
  response = models.list()
@@ -87,3 +129,25 @@ def _run_info(args: argparse.Namespace) -> None:
87
129
  model_info = {key: i[key] for key in visible_keys if key in i}
88
130
  print(json.dumps(model_info, indent=4))
89
131
  break
132
+
133
+
134
+ def _run_instances(args: argparse.Namespace) -> None:
135
+ models = Models()
136
+ response = models.instances()
137
+ if args.raw:
138
+ print(json.dumps(response, indent=4))
139
+ else:
140
+ started_instances = [key for key in response.keys() if response[key] is True]
141
+ print(json.dumps(started_instances, indent=4))
142
+
143
+
144
+ def _run_start(args: argparse.Namespace) -> None:
145
+ models = Models()
146
+ response = models.start(args.model)
147
+ print(json.dumps(response, indent=4))
148
+
149
+
150
+ def _run_stop(args: argparse.Namespace) -> None:
151
+ models = Models()
152
+ response = models.stop(args.model)
153
+ print(json.dumps(response, indent=4))
together/complete.py CHANGED
@@ -1,5 +1,5 @@
1
1
  import json
2
- from typing import Any, Dict, Iterator, Optional
2
+ from typing import Any, Dict, Iterator, List, Optional
3
3
 
4
4
  import requests
5
5
  import sseclient # type: ignore
@@ -23,7 +23,7 @@ class Complete:
23
23
  prompt: str,
24
24
  model: Optional[str] = "",
25
25
  max_tokens: Optional[int] = 128,
26
- stop: Optional[str] = None,
26
+ stop: Optional[List[str]] = [],
27
27
  temperature: Optional[float] = 0.7,
28
28
  top_p: Optional[float] = 0.7,
29
29
  top_k: Optional[int] = 50,
together/image.py CHANGED
@@ -20,7 +20,7 @@ class Image:
20
20
  self,
21
21
  prompt: str,
22
22
  model: Optional[str] = "",
23
- steps: Optional[int] = 50,
23
+ steps: Optional[int] = 20,
24
24
  seed: Optional[int] = 42,
25
25
  results: Optional[int] = 1,
26
26
  height: Optional[int] = 256,
together/models.py CHANGED
@@ -1,5 +1,5 @@
1
1
  import urllib.parse
2
- from typing import Any, List
2
+ from typing import Any, Dict, List
3
3
 
4
4
  import requests
5
5
 
@@ -42,3 +42,87 @@ class Models:
42
42
  raise together.JSONError(e, http_status=response.status_code)
43
43
 
44
44
  return response_list
45
+
46
+ @classmethod
47
+ def instances(self) -> Dict[str, bool]:
48
+ headers = {
49
+ "Authorization": f"Bearer {together.api_key}",
50
+ "accept": "application/json",
51
+ }
52
+ try:
53
+ response = requests.get(
54
+ together.api_base_instances,
55
+ headers=headers,
56
+ )
57
+ response.raise_for_status()
58
+ except requests.exceptions.RequestException as e:
59
+ logger.critical(f"Response error raised: {e}")
60
+ raise together.ResponseError(e)
61
+
62
+ try:
63
+ response_dict = response.json()
64
+ except Exception as e:
65
+ logger.critical(
66
+ f"JSON Error raised: {e}\nResponse status code = {response.status_code}"
67
+ )
68
+ raise together.JSONError(e, http_status=response.status_code)
69
+
70
+ return dict(response_dict)
71
+
72
+ @classmethod
73
+ def start(self, model: str) -> Dict[str, str]:
74
+ model_url = urllib.parse.urljoin(
75
+ together.api_base_instances, f"start?model={model}"
76
+ )
77
+ headers = {
78
+ "Authorization": f"Bearer {together.api_key}",
79
+ "accept": "application/json",
80
+ }
81
+ try:
82
+ response = requests.post(
83
+ model_url,
84
+ headers=headers,
85
+ )
86
+ response.raise_for_status()
87
+ except requests.exceptions.RequestException as e:
88
+ logger.critical(f"Response error raised: {e}")
89
+ raise together.ResponseError(e)
90
+
91
+ try:
92
+ response_dict = response.json()
93
+ except Exception as e:
94
+ logger.critical(
95
+ f"JSON Error raised: {e}\nResponse status code = {response.status_code}"
96
+ )
97
+ raise together.JSONError(e, http_status=response.status_code)
98
+
99
+ return dict(response_dict)
100
+
101
+ @classmethod
102
+ def stop(self, model: str) -> Dict[str, str]:
103
+ model_url = urllib.parse.urljoin(
104
+ together.api_base_instances, f"stop?model={model}"
105
+ )
106
+ headers = {
107
+ "Authorization": f"Bearer {together.api_key}",
108
+ "accept": "application/json",
109
+ }
110
+ try:
111
+ response = requests.post(
112
+ model_url,
113
+ headers=headers,
114
+ )
115
+ response.raise_for_status()
116
+ except requests.exceptions.RequestException as e:
117
+ logger.critical(f"Response error raised: {e}")
118
+ raise together.ResponseError(e)
119
+
120
+ try:
121
+ response_dict = response.json()
122
+ except Exception as e:
123
+ logger.critical(
124
+ f"JSON Error raised: {e}\nResponse status code = {response.status_code}"
125
+ )
126
+ raise together.JSONError(e, http_status=response.status_code)
127
+
128
+ return dict(response_dict)
together/version.py CHANGED
@@ -1 +1 @@
1
- VERSION = "0.1.0"
1
+ VERSION = "0.1.2"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: together
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Python client for Together's Cloud Platform!
5
5
  Project-URL: Homepage, https://github.com/togethercomputer/together
6
6
  Project-URL: Bug Tracker, https://github.com/togethercomputer/together/issues
@@ -235,6 +235,8 @@ pip install --upgrade together
235
235
 
236
236
  # Usage
237
237
 
238
+ > 🚧 You will need to create a free account with [together.ai](https://api.together.xyz/) to obtain a Together API Key.
239
+
238
240
  The Python Library requires your Together API Key to be configured. This key can be found in your Account's settings on the Playground. Simply click on and navigate to Profile Button > Settings > API Keys.
239
241
 
240
242
  The API Key can be configured by either setting the `TOGETHER_API_KEY` environment variable, like this:
@@ -250,7 +252,26 @@ import together
250
252
  together.api_key = "xxxxx"
251
253
  ```
252
254
 
253
- > 🚧 You will need to start a model instance from the Playground before you can query it from the API
255
+ Once you've provided your API key, you can browse our list of available models:
256
+
257
+ ```python
258
+ import together
259
+
260
+ # set your API key
261
+ together.api_key = "xxxxx"
262
+
263
+ # list available models and descriptons
264
+ models = together.Models.list()
265
+
266
+ # print the first model's name
267
+ print(models[0]['name'])
268
+ ```
269
+
270
+ Let's start an instance of one of the models in the list above. You can also start an instance by clicking play on any model in the [models playground](https://api.together.xyz/playground).
271
+
272
+ ```python
273
+ together.Models.start("togethercomputer/RedPajama-INCITE-7B-Base")
274
+ ```
254
275
 
255
276
  Once you've started a model instance, you can start querying:
256
277
 
@@ -272,6 +293,18 @@ output = together.Complete.create("Space robots", model="togethercomputer/RedPaj
272
293
  print(output['output']['choices'][0]['text'])
273
294
  ```
274
295
 
296
+ Check which models have been started or stopped:
297
+
298
+ ```python
299
+ together.Models.instances()
300
+ ```
301
+
302
+ To stop your model instance:
303
+
304
+ ```python
305
+ together.Models.stop("togethercomputer/RedPajama-INCITE-7B-Base")
306
+ ```
307
+
275
308
  ## Chat
276
309
 
277
310
  The `chat` command is a CLI-based chat application that can be used for back-and-forth conversations with models in a pre-defined format.
@@ -313,9 +346,19 @@ together --help
313
346
  # list available models
314
347
  together models list
315
348
 
349
+ # start a model
350
+ together models start togethercomputer/RedPajama-INCITE-7B-Base
351
+
316
352
  # create completion
317
353
  together complete "Space robots" -m togethercomputer/RedPajama-INCITE-7B-Base
354
+
355
+ # check which models are running
356
+ together models instances
357
+
358
+ # stop a model
359
+ together models stop togethercomputer/RedPajama-INCITE-7B-Base
318
360
  ```
361
+
319
362
  ## Contributing
320
363
  1. Clone the repo and make your changes
321
364
  2. Run `pip install together['quality']`
@@ -1,25 +1,25 @@
1
- together/__init__.py,sha256=NrCGNA91lPRdBAbAPg9knlzzIZLqBHsWk9Xw99DVvZo,1105
2
- together/complete.py,sha256=dIYvjYLbhQzF1mtENdLWxqg9c6_8MqTWVT09A0YkSz8,4800
1
+ together/__init__.py,sha256=wtmG4WYGwdTi6kaQaBz9jSRBVgRbqVszNBkHvS5z7dU,1197
2
+ together/complete.py,sha256=0LmNUBpTFAE9yyVwPoNMsbZ3GasK7ytek0EpnGfCAow,4810
3
3
  together/error.py,sha256=uHSkcug_tp5gi0oqk1q1trqhhd5VwpegC1Ka0mvz2OM,2043
4
4
  together/files.py,sha256=nIU43_s2OmVYRAf9w-0146As3YXaNis2twvbH7Hfc7E,9081
5
5
  together/finetune.py,sha256=Pv58KXb6Wrt1ou2oAx_zfNywIOIgqG6dL6VRIT56W2I,10886
6
- together/image.py,sha256=Eu7ykL4Rov52j2OzrhU9bMKfeTX6teu58Fc-v8E1q4s,2167
7
- together/models.py,sha256=ZcXO7y6gm-2P584oeNpVZ7e3s-fdCHLxz7_yN7VQVNI,1212
8
- together/version.py,sha256=CpXi3jGlx23RvRyU7iytOMZrnspdWw4yofS8lpP1AJU,18
6
+ together/image.py,sha256=VrbU6aGQVtRktLHQPao8bUXL3bq1RXhOJxVBQzSp0bk,2167
7
+ together/models.py,sha256=PgruT8rtTelzIchbTvrF4ve-ASQvJELCZgXV37ke2XE,4029
8
+ together/version.py,sha256=3ITyQfKn-h4AMdaHk5rHJaliZbCnbLZ7O3QQnAJH8yI,18
9
9
  together/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- together/cli/cli.py,sha256=Qms7RsLBJa6vWmwxhjpWPZfB21FKUbMknIAgXezx_6Q,1531
10
+ together/cli/cli.py,sha256=PVhRFkXzQF7WYYjYv3YmNxRAX_aGNyVc46pASyNy9w0,1672
11
11
  together/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  together/commands/chat.py,sha256=W3xnVn3i7yoB10ksSe718e-U7rMT7d-fnOMlwNvCDmw,4098
13
13
  together/commands/complete.py,sha256=jLRnr9pWipmZNI4hLc88aHDovK_tqgpx6QOp2J7Bc2E,5107
14
14
  together/commands/files.py,sha256=QPnXjTTQl0wrI7EoeFLJQ5OV2407cz_1rfcGy22xFcI,3019
15
15
  together/commands/finetune.py,sha256=m3-ZYp5X0EB5T8C4vZzS2oc1oLko0mHi2Mk_kLh1hho,9224
16
- together/commands/image.py,sha256=hy0cNSzFiT2bRmFgKqXxtzP8tz-yACb4ltXlML9nTGw,3692
17
- together/commands/models.py,sha256=QtBuiE7INKmEM8Q0Pl_lg1O2JhlnlLEvigH6h67itFM,2184
16
+ together/commands/image.py,sha256=rzeztlgmqzFFt_2fTcM46tevukCcweuJLFbcA9xWLJA,3692
17
+ together/commands/models.py,sha256=pWE65njA04cYwcfh2IlPj5VyirFEYZFZXFHa1Jb4IP8,3884
18
18
  together/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  together/utils/conversation.py,sha256=m_rt0VBkpweHV0DXZwQmaXeGGfnUr96fHqdRjabfLBk,1859
20
20
  together/utils/utils.py,sha256=B2hEOa9RkR2ykviMnetVGmZ_581BmH4G41owgwLWRGg,1833
21
- together-0.1.1.dist-info/METADATA,sha256=yxTHpxykRl8okpfGXsm2KcDkLVLC4GQTUiDAV7JX1S0,17569
22
- together-0.1.1.dist-info/WHEEL,sha256=9QBuHhg6FNW7lppboF2vKVbCGTVzsFykgRQjjlajrhA,87
23
- together-0.1.1.dist-info/entry_points.txt,sha256=A899fxUpqEYrAWuo0FyXSfuJ2SgrJNnkI7aSnrnPx6c,51
24
- together-0.1.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
25
- together-0.1.1.dist-info/RECORD,,
21
+ together-0.1.2.dist-info/METADATA,sha256=8IX9flug-pItAvdXpB0qr8M7kO2fElXk46wy8NYXa_k,18574
22
+ together-0.1.2.dist-info/WHEEL,sha256=9QBuHhg6FNW7lppboF2vKVbCGTVzsFykgRQjjlajrhA,87
23
+ together-0.1.2.dist-info/entry_points.txt,sha256=A899fxUpqEYrAWuo0FyXSfuJ2SgrJNnkI7aSnrnPx6c,51
24
+ together-0.1.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
25
+ together-0.1.2.dist-info/RECORD,,