sutro 0.1.36__py3-none-any.whl → 0.1.37__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.

Potentially problematic release.


This version of sutro might be problematic. Click here for more details.

sutro/sdk.py CHANGED
@@ -14,6 +14,7 @@ import time
14
14
  from pydantic import BaseModel
15
15
  import pyarrow.parquet as pq
16
16
  import shutil
17
+ import importlib.metadata
17
18
 
18
19
  JOB_NAME_CHAR_LIMIT = 45
19
20
  JOB_DESCRIPTION_CHAR_LIMIT = 512
@@ -85,7 +86,7 @@ ModelOptions = Literal[
85
86
 
86
87
 
87
88
  def to_colored_text(
88
- text: str, state: Optional[Literal["success", "fail"]] = None
89
+ text: str, state: Optional[Literal["success", "fail", "callout"]] = None
89
90
  ) -> str:
90
91
  """
91
92
  Apply color to text based on state.
@@ -103,6 +104,8 @@ def to_colored_text(
103
104
  return f"{Fore.GREEN}{text}{Style.RESET_ALL}"
104
105
  case "fail":
105
106
  return f"{Fore.RED}{text}{Style.RESET_ALL}"
107
+ case "callout":
108
+ return f"{Fore.MAGENTA}{text}{Style.RESET_ALL}"
106
109
  case _:
107
110
  # Default to blue for normal/processing states
108
111
  return f"{Fore.BLUE}{text}{Style.RESET_ALL}"
@@ -124,6 +127,34 @@ class Sutro:
124
127
  def __init__(self, api_key: str = None, base_url: str = "https://api.sutro.sh/"):
125
128
  self.api_key = api_key or self.check_for_api_key()
126
129
  self.base_url = base_url
130
+ self.check_version("sutro")
131
+
132
+ def check_version(self, package_name: str):
133
+ try:
134
+ # Local version
135
+ local_version = importlib.metadata.version(package_name)
136
+ except importlib.metadata.PackageNotFoundError:
137
+ print(f"{package_name} is not installed.")
138
+ return
139
+
140
+ try:
141
+ # Latest release from PyPI
142
+ resp = requests.get(f"https://pypi.org/pypi/{package_name}/json", timeout=2)
143
+ resp.raise_for_status()
144
+ latest_version = resp.json()["info"]["version"]
145
+
146
+ if local_version != latest_version:
147
+ msg = (f"⚠️ You are using {package_name} {local_version}, "
148
+ f"but the latest release is {latest_version}. "
149
+ f"Run `[uv] pip install -U {package_name}` to upgrade.")
150
+ print(to_colored_text(
151
+ msg,
152
+ state="callout"
153
+ )
154
+ )
155
+ except Exception as e:
156
+ # Fail silently or log, you don’t want this blocking usage
157
+ pass
127
158
 
128
159
  def check_for_api_key(self):
129
160
  """
@@ -489,7 +520,21 @@ class Sutro:
489
520
 
490
521
  results = job_results_response.json()["results"]["outputs"]
491
522
 
492
- spinner.write(
523
+ if isinstance(data, (pd.DataFrame, pl.DataFrame)):
524
+ if isinstance(data, pd.DataFrame):
525
+ data[output_column] = results
526
+ elif isinstance(data, pl.DataFrame):
527
+ data = data.with_columns(pl.Series(output_column, results))
528
+ print(data)
529
+ spinner.write(
530
+ to_colored_text(
531
+ f"✔ Displaying result preview. You can join the results on the original dataframe with `so.get_job_results('{job_id}', with_original_df=<original_df>)`",
532
+ state="success",
533
+ )
534
+ )
535
+ else:
536
+ print(results)
537
+ spinner.write(
493
538
  to_colored_text(
494
539
  f"✔ Job results received. You can re-obtain the results with `so.get_job_results('{job_id}')`",
495
540
  state="success",
@@ -497,14 +542,7 @@ class Sutro:
497
542
  )
498
543
  spinner.stop()
499
544
 
500
- if isinstance(data, (pd.DataFrame, pl.DataFrame)):
501
- if isinstance(data, pd.DataFrame):
502
- data[output_column] = results
503
- elif isinstance(data, pl.DataFrame):
504
- data = data.with_columns(pl.Series(output_column, results))
505
- return data
506
-
507
- return results
545
+ return job_id
508
546
  return None
509
547
  return None
510
548
 
@@ -523,7 +561,7 @@ class Sutro:
523
561
  dry_run: bool = False,
524
562
  stay_attached: Optional[bool] = None,
525
563
  random_seed_per_input: bool = False,
526
- truncate_rows: bool = False,
564
+ truncate_rows: bool = True,
527
565
  ):
528
566
  """
529
567
  Run inference on the provided data.
@@ -546,10 +584,10 @@ class Sutro:
546
584
  dry_run (bool, optional): If True, the method will return cost estimates instead of running inference. Defaults to False.
547
585
  stay_attached (bool, optional): If True, the method will stay attached to the job until it is complete. Defaults to True for prototyping jobs, False otherwise.
548
586
  random_seed_per_input (bool, optional): If True, the method will use a different random seed for each input. Defaults to False.
549
- truncate_rows (bool, optional): If True, any rows that have a token count exceeding the context window length of the selected model will be truncated to the max length that will fit within the context window. Defaults to False.
587
+ truncate_rows (bool, optional): If True, any rows that have a token count exceeding the context window length of the selected model will be truncated to the max length that will fit within the context window. Defaults to True.
550
588
 
551
589
  Returns:
552
- Union[List, pd.DataFrame, pl.DataFrame, str]: The results of the inference.
590
+ str: The ID of the inference job.
553
591
 
554
592
  """
555
593
  if isinstance(model, list) == False:
@@ -568,6 +606,8 @@ class Sutro:
568
606
  name_list = name
569
607
  elif isinstance(name, str):
570
608
  raise ValueError("Name must be a list if using a list of models.")
609
+ elif name is None:
610
+ name_list = [None] * len(model_list)
571
611
  else:
572
612
  if isinstance(name, list):
573
613
  raise ValueError("Name must be a string or None if using a single model.")
@@ -580,6 +620,8 @@ class Sutro:
580
620
  description_list = description
581
621
  elif isinstance(description, str):
582
622
  raise ValueError("Description must be a list if using a list of models.")
623
+ elif description is None:
624
+ description_list = [None] * len(model_list)
583
625
  else:
584
626
  if isinstance(name, list):
585
627
  raise ValueError("Description must be a string or None if using a single model.")
@@ -1051,9 +1093,9 @@ class Sutro:
1051
1093
  first_row = json.loads(
1052
1094
  results_df.head(1)[output_column][0]
1053
1095
  ) # checks if the first row can be json decoded
1096
+ results_df = results_df.map_columns(output_column, lambda s: s.str.json_decode())
1054
1097
  results_df = results_df.with_columns(
1055
1098
  pl.col(output_column)
1056
- .str.json_decode()
1057
1099
  .alias("output_column_json_decoded")
1058
1100
  )
1059
1101
  json_decoded_fields = first_row.keys()
@@ -1063,7 +1105,15 @@ class Sutro:
1063
1105
  .struct.field(field)
1064
1106
  .alias(field)
1065
1107
  )
1066
- # drop the output_column and the json decoded column
1108
+ if sorted(list(set(json_decoded_fields))) == ['content', 'reasoning_content']: # if it's a reasoning model, we need to unpack the content field
1109
+ content_keys = results_df.head(1)['content'][0].keys()
1110
+ for key in content_keys:
1111
+ results_df = results_df.with_columns(
1112
+ pl.col("content")
1113
+ .struct.field(key)
1114
+ .alias(key)
1115
+ )
1116
+ results_df = results_df.drop("content")
1067
1117
  results_df = results_df.drop(
1068
1118
  [output_column, "output_column_json_decoded"]
1069
1119
  )
@@ -1448,7 +1498,7 @@ class Sutro:
1448
1498
  timeout (Optional[int]): The max time in seconds the function should wait for job results for. Default is 7200 (2 hours).
1449
1499
 
1450
1500
  Returns:
1451
- list: The results of the job.
1501
+ pl.DataFrame: The results of the job in a polars DataFrame.
1452
1502
  """
1453
1503
  POLL_INTERVAL = 5
1454
1504
 
@@ -1,24 +1,23 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sutro
3
- Version: 0.1.36
3
+ Version: 0.1.37
4
4
  Summary: Sutro Python SDK
5
- Project-URL: Homepage, https://sutro.sh
6
- Project-URL: Documentation, https://docs.sutro.sh
7
5
  License-Expression: Apache-2.0
8
- License-File: LICENSE
6
+ Requires-Dist: numpy>=2.1.1,<3.0.0
7
+ Requires-Dist: requests>=2.32.3,<3.0.0
8
+ Requires-Dist: pandas>=2.2.3,<3.0.0
9
+ Requires-Dist: polars>=1.33.0,<=1.34.0
10
+ Requires-Dist: click>=8.1.7,<9.0.0
11
+ Requires-Dist: colorama>=0.4.4,<1.0.0
12
+ Requires-Dist: yaspin>=3.2.0,<4.0.0
13
+ Requires-Dist: tqdm>=4.67.1,<5.0.0
14
+ Requires-Dist: pydantic>=2.11.4,<3.0.0
15
+ Requires-Dist: pyarrow>=21.0.0,<22.0.0
16
+ Requires-Dist: ruff==0.13.1 ; extra == 'dev'
9
17
  Requires-Python: >=3.10
10
- Requires-Dist: click<9.0.0,>=8.1.7
11
- Requires-Dist: colorama<1.0.0,>=0.4.4
12
- Requires-Dist: numpy<3.0.0,>=2.1.1
13
- Requires-Dist: pandas<3.0.0,>=2.2.3
14
- Requires-Dist: polars<=1.8.2
15
- Requires-Dist: pyarrow<22.0.0,>=21.0.0
16
- Requires-Dist: pydantic<3.0.0,>=2.11.4
17
- Requires-Dist: requests<3.0.0,>=2.32.3
18
- Requires-Dist: tqdm<5.0.0,>=4.67.1
19
- Requires-Dist: yaspin<4.0.0,>=3.2.0
18
+ Project-URL: Documentation, https://docs.sutro.sh
19
+ Project-URL: Homepage, https://sutro.sh
20
20
  Provides-Extra: dev
21
- Requires-Dist: ruff==0.13.1; extra == 'dev'
22
21
  Description-Content-Type: text/markdown
23
22
 
24
23
  ![Sutro Logo](./assets/sutro-logo-dark.png)
@@ -0,0 +1,7 @@
1
+ sutro/__init__.py,sha256=yUiVwcZ8QamSqDdRHgzoANyTZ-x3cPzlt2Fs5OllR_w,402
2
+ sutro/cli.py,sha256=_FU8PwP4dMzXXg5ldxCXP3kaZvQtOKdA8Kzjc34xmQ0,13727
3
+ sutro/sdk.py,sha256=dysuW6jwtuMjVTdDH1zCoycWLvjzBZa_Mi6dSM_zWpY,63799
4
+ sutro-0.1.37.dist-info/WHEEL,sha256=X16MKk8bp2DRsAuyteHJ-9qOjzmnY0x1aj0P1ftqqWA,78
5
+ sutro-0.1.37.dist-info/entry_points.txt,sha256=s-dtPZ0AScjvR8S_ykhzXxtVcUjrRlxVxyJymI81A3E,41
6
+ sutro-0.1.37.dist-info/METADATA,sha256=pOSPs0yhCpKEhHZJIPIaL-wxSXYoUVBTLQNqN7WjO3E,6259
7
+ sutro-0.1.37.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.9.2
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -1,2 +1,3 @@
1
1
  [console_scripts]
2
2
  sutro = sutro.cli:cli
3
+
@@ -1,8 +0,0 @@
1
- sutro/__init__.py,sha256=yUiVwcZ8QamSqDdRHgzoANyTZ-x3cPzlt2Fs5OllR_w,402
2
- sutro/cli.py,sha256=_FU8PwP4dMzXXg5ldxCXP3kaZvQtOKdA8Kzjc34xmQ0,13727
3
- sutro/sdk.py,sha256=vFx0hQczAxefmi-ijlkCgOc8P_TxHgswwGbmMOJpY04,61440
4
- sutro-0.1.36.dist-info/METADATA,sha256=QlwM7oHJWpLGvyWdV1KxAfg4l8tuc41H29pnUdxu618,6270
5
- sutro-0.1.36.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
6
- sutro-0.1.36.dist-info/entry_points.txt,sha256=eXvr4dvMV4UmZgR0zmrY8KOmNpo64cJkhNDywiadRFM,40
7
- sutro-0.1.36.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
8
- sutro-0.1.36.dist-info/RECORD,,
@@ -1,4 +0,0 @@
1
- Wheel-Version: 1.0
2
- Generator: hatchling 1.27.0
3
- Root-Is-Purelib: true
4
- Tag: py3-none-any
@@ -1,201 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [yyyy] [name of copyright owner]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.