sutro 0.1.24__tar.gz → 0.1.25__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.
Potentially problematic release.
This version of sutro might be problematic. Click here for more details.
- {sutro-0.1.24 → sutro-0.1.25}/PKG-INFO +1 -1
- {sutro-0.1.24 → sutro-0.1.25}/pyproject.toml +1 -1
- {sutro-0.1.24 → sutro-0.1.25}/sutro/sdk.py +37 -35
- {sutro-0.1.24 → sutro-0.1.25}/.gitignore +0 -0
- {sutro-0.1.24 → sutro-0.1.25}/LICENSE +0 -0
- {sutro-0.1.24 → sutro-0.1.25}/README.md +0 -0
- {sutro-0.1.24 → sutro-0.1.25}/sutro/__init__.py +0 -0
- {sutro-0.1.24 → sutro-0.1.25}/sutro/cli.py +0 -0
|
@@ -215,7 +215,7 @@ class Sutro:
|
|
|
215
215
|
json_schema: Dict[str, Any],
|
|
216
216
|
sampling_params: dict,
|
|
217
217
|
system_prompt: str,
|
|
218
|
-
|
|
218
|
+
cost_estimate: bool,
|
|
219
219
|
stay_attached: Optional[bool],
|
|
220
220
|
random_seed_per_input: bool,
|
|
221
221
|
truncate_rows: bool
|
|
@@ -232,7 +232,7 @@ class Sutro:
|
|
|
232
232
|
"job_priority": job_priority,
|
|
233
233
|
"json_schema": json_schema,
|
|
234
234
|
"system_prompt": system_prompt,
|
|
235
|
-
"
|
|
235
|
+
"cost_estimate": cost_estimate,
|
|
236
236
|
"sampling_params": sampling_params,
|
|
237
237
|
"random_seed_per_input": random_seed_per_input,
|
|
238
238
|
"truncate_rows": truncate_rows
|
|
@@ -245,7 +245,7 @@ class Sutro:
|
|
|
245
245
|
# Terminal size {self._terminal_width} is too small to display spinner with the given settings.
|
|
246
246
|
# https://github.com/pavdmyt/yaspin/blob/9c7430b499ab4611888ece39783a870e4a05fa45/yaspin/core.py#L568-L571
|
|
247
247
|
job_id = None
|
|
248
|
-
t = f"Creating {'[
|
|
248
|
+
t = f"Creating {'[cost estimate] ' if cost_estimate else ''}priority {job_priority} job"
|
|
249
249
|
spinner_text = to_colored_text(t)
|
|
250
250
|
try:
|
|
251
251
|
with yaspin(SPINNER, text=spinner_text, color=YASPIN_COLOR) as spinner:
|
|
@@ -262,12 +262,12 @@ class Sutro:
|
|
|
262
262
|
return None
|
|
263
263
|
else:
|
|
264
264
|
job_id = response_data["results"]
|
|
265
|
-
if
|
|
265
|
+
if cost_estimate:
|
|
266
266
|
spinner.write(
|
|
267
|
-
to_colored_text(f"Awaiting cost estimates with job ID: {job_id}. You can safely detach and retrieve the cost estimates later."
|
|
267
|
+
to_colored_text(f"Awaiting cost estimates with job ID: {job_id}. You can safely detach and retrieve the cost estimates later.")
|
|
268
268
|
)
|
|
269
269
|
spinner.stop()
|
|
270
|
-
self.await_job_completion(job_id, obtain_results=False)
|
|
270
|
+
self.await_job_completion(job_id, obtain_results=False, is_cost_estimate=True)
|
|
271
271
|
cost_estimate = self._get_job_cost_estimate(job_id)
|
|
272
272
|
spinner.write(
|
|
273
273
|
to_colored_text(f"✔ Cost estimates retrieved for job {job_id}: ${cost_estimate}", state="success")
|
|
@@ -532,20 +532,8 @@ class Sutro:
|
|
|
532
532
|
text=to_colored_text("Looking for job..."),
|
|
533
533
|
color=YASPIN_COLOR,
|
|
534
534
|
) as spinner:
|
|
535
|
-
#
|
|
536
|
-
|
|
537
|
-
# GET /jobs/{job_id}
|
|
538
|
-
jobs_response = s.get(
|
|
539
|
-
f"{self.base_url}/list-jobs",
|
|
540
|
-
headers=headers
|
|
541
|
-
)
|
|
542
|
-
jobs_response.raise_for_status()
|
|
543
|
-
|
|
544
|
-
# Find the specific job we want to attach to
|
|
545
|
-
job = next(
|
|
546
|
-
(job for job in jobs_response.json()["jobs"] if job["job_id"] == job_id),
|
|
547
|
-
None
|
|
548
|
-
)
|
|
535
|
+
# Fetch the specific job we want to attach to
|
|
536
|
+
job = self._fetch_job(job_id)
|
|
549
537
|
|
|
550
538
|
if not job:
|
|
551
539
|
spinner.write(to_colored_text(f"Job {job_id} not found", state="fail"))
|
|
@@ -726,7 +714,7 @@ class Sutro:
|
|
|
726
714
|
"""
|
|
727
715
|
Helper function to list jobs.
|
|
728
716
|
"""
|
|
729
|
-
endpoint = f"{self.base_url}/list-jobs"
|
|
717
|
+
endpoint = f"{self.base_url}/list-jobs˚"
|
|
730
718
|
headers = {
|
|
731
719
|
"Authorization": f"Key {self.api_key}",
|
|
732
720
|
"Content-Type": "application/json",
|
|
@@ -736,25 +724,38 @@ class Sutro:
|
|
|
736
724
|
return None
|
|
737
725
|
return response.json()["jobs"]
|
|
738
726
|
|
|
727
|
+
def _fetch_job(self, job_id):
|
|
728
|
+
"""
|
|
729
|
+
Helper function to fetch a single job.
|
|
730
|
+
"""
|
|
731
|
+
endpoint = f"{self.base_url}/jobs/{job_id}"
|
|
732
|
+
headers = {
|
|
733
|
+
"Authorization": f"Key {self.api_key}",
|
|
734
|
+
"Content-Type": "application/json",
|
|
735
|
+
}
|
|
736
|
+
response = requests.get(endpoint, headers=headers)
|
|
737
|
+
if response.status_code != 200:
|
|
738
|
+
return None
|
|
739
|
+
return response.json().get('job')
|
|
740
|
+
|
|
739
741
|
def _get_job_cost_estimate(self, job_id: str):
|
|
740
742
|
"""
|
|
741
743
|
Get the cost estimate for a job.
|
|
742
744
|
"""
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
return
|
|
745
|
+
job = self._fetch_job(job_id)
|
|
746
|
+
if not job:
|
|
747
|
+
return None
|
|
748
|
+
|
|
749
|
+
return job.get('cost_estimate')
|
|
748
750
|
|
|
749
751
|
def _get_failure_reason(self, job_id: str):
|
|
750
752
|
"""
|
|
751
753
|
Get the failure reason for a job.
|
|
752
754
|
"""
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
return None
|
|
755
|
+
job = self._fetch_job(job_id)
|
|
756
|
+
if not job:
|
|
757
|
+
return None
|
|
758
|
+
return job.get('failure_reason')
|
|
758
759
|
|
|
759
760
|
def _fetch_job_status(self, job_id: str):
|
|
760
761
|
"""
|
|
@@ -1239,7 +1240,7 @@ class Sutro:
|
|
|
1239
1240
|
return
|
|
1240
1241
|
return response.json()["quotas"]
|
|
1241
1242
|
|
|
1242
|
-
def await_job_completion(self, job_id: str, timeout: Optional[int] = 7200, obtain_results: bool = True) -> list | None:
|
|
1243
|
+
def await_job_completion(self, job_id: str, timeout: Optional[int] = 7200, obtain_results: bool = True, is_cost_estimate: bool=False) -> list | None:
|
|
1243
1244
|
"""
|
|
1244
1245
|
Waits for job completion to occur and then returns the results upon
|
|
1245
1246
|
a successful completion.
|
|
@@ -1260,8 +1261,9 @@ class Sutro:
|
|
|
1260
1261
|
with yaspin(
|
|
1261
1262
|
SPINNER, text=to_colored_text("Awaiting job completion"), color=YASPIN_COLOR
|
|
1262
1263
|
) as spinner:
|
|
1263
|
-
|
|
1264
|
-
|
|
1264
|
+
if not is_cost_estimate:
|
|
1265
|
+
clickable_link = make_clickable_link(f'https://app.sutro.sh/jobs/{job_id}')
|
|
1266
|
+
spinner.write(to_colored_text(f'Progress can also be monitored at: {clickable_link}'))
|
|
1265
1267
|
while (time.time() - start_time) < timeout:
|
|
1266
1268
|
try:
|
|
1267
1269
|
status = self._fetch_job_status(job_id)
|
|
@@ -1278,9 +1280,9 @@ class Sutro:
|
|
|
1278
1280
|
spinner.text = to_colored_text(f"Job status is {status} for {job_id}")
|
|
1279
1281
|
|
|
1280
1282
|
if status == JobStatus.SUCCEEDED:
|
|
1281
|
-
spinner.write(to_colored_text("Job completed! Retrieving results...", "success"))
|
|
1282
1283
|
spinner.stop() # Stop this spinner as `get_job_results` has its own spinner text
|
|
1283
1284
|
if obtain_results:
|
|
1285
|
+
spinner.write(to_colored_text("Job completed! Retrieving results...", "success"))
|
|
1284
1286
|
results = self.get_job_results(job_id)
|
|
1285
1287
|
break
|
|
1286
1288
|
if status == JobStatus.FAILED:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|