together 0.1.1__tar.gz → 0.1.2__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.
Files changed (28) hide show
  1. {together-0.1.1 → together-0.1.2}/PKG-INFO +45 -2
  2. {together-0.1.1 → together-0.1.2}/README.md +44 -1
  3. {together-0.1.1 → together-0.1.2}/pyproject.toml +1 -1
  4. {together-0.1.1 → together-0.1.2}/src/together/__init__.py +2 -0
  5. {together-0.1.1 → together-0.1.2}/src/together/cli/cli.py +7 -0
  6. {together-0.1.1 → together-0.1.2}/src/together/commands/image.py +3 -3
  7. {together-0.1.1 → together-0.1.2}/src/together/commands/models.py +64 -0
  8. {together-0.1.1 → together-0.1.2}/src/together/complete.py +2 -2
  9. {together-0.1.1 → together-0.1.2}/src/together/image.py +1 -1
  10. together-0.1.2/src/together/models.py +128 -0
  11. together-0.1.2/src/together/version.py +1 -0
  12. together-0.1.1/src/together/models.py +0 -44
  13. together-0.1.1/src/together/version.py +0 -1
  14. {together-0.1.1 → together-0.1.2}/.github/workflows/check_code_quality.yml +0 -0
  15. {together-0.1.1 → together-0.1.2}/.gitignore +0 -0
  16. {together-0.1.1 → together-0.1.2}/LICENSE +0 -0
  17. {together-0.1.1 → together-0.1.2}/src/together/cli/__init__.py +0 -0
  18. {together-0.1.1 → together-0.1.2}/src/together/commands/__init__.py +0 -0
  19. {together-0.1.1 → together-0.1.2}/src/together/commands/chat.py +0 -0
  20. {together-0.1.1 → together-0.1.2}/src/together/commands/complete.py +0 -0
  21. {together-0.1.1 → together-0.1.2}/src/together/commands/files.py +0 -0
  22. {together-0.1.1 → together-0.1.2}/src/together/commands/finetune.py +0 -0
  23. {together-0.1.1 → together-0.1.2}/src/together/error.py +0 -0
  24. {together-0.1.1 → together-0.1.2}/src/together/files.py +0 -0
  25. {together-0.1.1 → together-0.1.2}/src/together/finetune.py +0 -0
  26. {together-0.1.1 → together-0.1.2}/src/together/utils/__init__.py +0 -0
  27. {together-0.1.1 → together-0.1.2}/src/together/utils/conversation.py +0 -0
  28. {together-0.1.1 → together-0.1.2}/src/together/utils/utils.py +0 -0
@@ -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']`
@@ -10,6 +10,8 @@ pip install --upgrade together
10
10
 
11
11
  # Usage
12
12
 
13
+ > 🚧 You will need to create a free account with [together.ai](https://api.together.xyz/) to obtain a Together API Key.
14
+
13
15
  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.
14
16
 
15
17
  The API Key can be configured by either setting the `TOGETHER_API_KEY` environment variable, like this:
@@ -25,7 +27,26 @@ import together
25
27
  together.api_key = "xxxxx"
26
28
  ```
27
29
 
28
- > 🚧 You will need to start a model instance from the Playground before you can query it from the API
30
+ Once you've provided your API key, you can browse our list of available models:
31
+
32
+ ```python
33
+ import together
34
+
35
+ # set your API key
36
+ together.api_key = "xxxxx"
37
+
38
+ # list available models and descriptons
39
+ models = together.Models.list()
40
+
41
+ # print the first model's name
42
+ print(models[0]['name'])
43
+ ```
44
+
45
+ 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).
46
+
47
+ ```python
48
+ together.Models.start("togethercomputer/RedPajama-INCITE-7B-Base")
49
+ ```
29
50
 
30
51
  Once you've started a model instance, you can start querying:
31
52
 
@@ -47,6 +68,18 @@ output = together.Complete.create("Space robots", model="togethercomputer/RedPaj
47
68
  print(output['output']['choices'][0]['text'])
48
69
  ```
49
70
 
71
+ Check which models have been started or stopped:
72
+
73
+ ```python
74
+ together.Models.instances()
75
+ ```
76
+
77
+ To stop your model instance:
78
+
79
+ ```python
80
+ together.Models.stop("togethercomputer/RedPajama-INCITE-7B-Base")
81
+ ```
82
+
50
83
  ## Chat
51
84
 
52
85
  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.
@@ -88,9 +121,19 @@ together --help
88
121
  # list available models
89
122
  together models list
90
123
 
124
+ # start a model
125
+ together models start togethercomputer/RedPajama-INCITE-7B-Base
126
+
91
127
  # create completion
92
128
  together complete "Space robots" -m togethercomputer/RedPajama-INCITE-7B-Base
129
+
130
+ # check which models are running
131
+ together models instances
132
+
133
+ # stop a model
134
+ together models stop togethercomputer/RedPajama-INCITE-7B-Base
93
135
  ```
136
+
94
137
  ## Contributing
95
138
  1. Clone the repo and make your changes
96
139
  2. Run `pip install together['quality']`
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "together"
7
- version = "0.1.1"
7
+ version = "0.1.2"
8
8
  authors = [
9
9
  { name="Together Computer", email="community@together.xyz" },
10
10
  ]
@@ -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",
@@ -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))
@@ -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,
@@ -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,
@@ -0,0 +1,128 @@
1
+ import urllib.parse
2
+ from typing import Any, Dict, List
3
+
4
+ import requests
5
+
6
+ import together
7
+ from together import get_logger, verify_api_key
8
+
9
+
10
+ logger = get_logger(str(__name__), log_level=together.log_level)
11
+
12
+
13
+ class Models:
14
+ def __init__(
15
+ self,
16
+ ) -> None:
17
+ verify_api_key(logger)
18
+
19
+ @classmethod
20
+ def list(self) -> List[Any]:
21
+ model_url = urllib.parse.urljoin(together.api_base, "models/info?=")
22
+ headers = {
23
+ "Authorization": f"Bearer {together.api_key}",
24
+ "User-Agent": together.user_agent,
25
+ }
26
+ try:
27
+ response = requests.get(
28
+ model_url,
29
+ headers=headers,
30
+ )
31
+ response.raise_for_status()
32
+ except requests.exceptions.RequestException as e:
33
+ logger.critical(f"Response error raised: {e}")
34
+ raise together.ResponseError(e)
35
+
36
+ try:
37
+ response_list = list(response.json())
38
+ except Exception as e:
39
+ logger.critical(
40
+ f"JSON Error raised: {e}\nResponse status code = {response.status_code}"
41
+ )
42
+ raise together.JSONError(e, http_status=response.status_code)
43
+
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)
@@ -0,0 +1 @@
1
+ VERSION = "0.1.2"
@@ -1,44 +0,0 @@
1
- import urllib.parse
2
- from typing import Any, List
3
-
4
- import requests
5
-
6
- import together
7
- from together import get_logger, verify_api_key
8
-
9
-
10
- logger = get_logger(str(__name__), log_level=together.log_level)
11
-
12
-
13
- class Models:
14
- def __init__(
15
- self,
16
- ) -> None:
17
- verify_api_key(logger)
18
-
19
- @classmethod
20
- def list(self) -> List[Any]:
21
- model_url = urllib.parse.urljoin(together.api_base, "models/info?=")
22
- headers = {
23
- "Authorization": f"Bearer {together.api_key}",
24
- "User-Agent": together.user_agent,
25
- }
26
- try:
27
- response = requests.get(
28
- model_url,
29
- headers=headers,
30
- )
31
- response.raise_for_status()
32
- except requests.exceptions.RequestException as e:
33
- logger.critical(f"Response error raised: {e}")
34
- raise together.ResponseError(e)
35
-
36
- try:
37
- response_list = list(response.json())
38
- except Exception as e:
39
- logger.critical(
40
- f"JSON Error raised: {e}\nResponse status code = {response.status_code}"
41
- )
42
- raise together.JSONError(e, http_status=response.status_code)
43
-
44
- return response_list
@@ -1 +0,0 @@
1
- VERSION = "0.1.0"
File without changes
File without changes
File without changes
File without changes