weco 0.2.24__py3-none-any.whl → 0.2.26__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.
weco/api.py CHANGED
@@ -14,8 +14,6 @@ def handle_api_error(e: requests.exceptions.HTTPError, console: Console) -> None
14
14
  except (ValueError, KeyError): # Handle cases where response is not JSON or detail key is missing
15
15
  detail = f"HTTP {e.response.status_code} Error: {e.response.text}"
16
16
  console.print(f"[bold red]{detail}[/]")
17
- # Avoid exiting here, let the caller decide if the error is fatal
18
- # sys.exit(1)
19
17
 
20
18
 
21
19
  def start_optimization_run(
@@ -32,7 +30,7 @@ def start_optimization_run(
32
30
  api_keys: Dict[str, Any] = {},
33
31
  auth_headers: dict = {},
34
32
  timeout: Union[int, Tuple[int, int]] = DEFAULT_API_TIMEOUT,
35
- ) -> Dict[str, Any]:
33
+ ) -> Optional[Dict[str, Any]]:
36
34
  """Start the optimization run."""
37
35
  with console.status("[bold green]Starting Optimization..."):
38
36
  try:
@@ -61,12 +59,12 @@ def start_optimization_run(
61
59
  if result.get("code") is None:
62
60
  result["code"] = ""
63
61
  return result
64
- except Exception as e:
62
+ except requests.exceptions.HTTPError as e:
65
63
  handle_api_error(e, console)
66
- sys.exit(1)
64
+ return None
67
65
  except Exception as e:
68
66
  console.print(f"[bold red]Error starting run: {e}[/]")
69
- sys.exit(1)
67
+ return None
70
68
 
71
69
 
72
70
  def evaluate_feedback_then_suggest_next_solution(
@@ -101,11 +99,11 @@ def evaluate_feedback_then_suggest_next_solution(
101
99
  return result
102
100
  except requests.exceptions.HTTPError as e:
103
101
  # Allow caller to handle suggest errors, maybe retry or terminate
104
- handle_api_error(e, console) # Use default console if none passed
105
- raise # Re-raise the exception
102
+ handle_api_error(e, console)
103
+ raise
106
104
  except Exception as e:
107
- print(f"Error: {e}") # Use print as console might not be available
108
- raise # Re-raise the exception
105
+ console.print(f"[bold red]Error: {e}[/]")
106
+ raise
109
107
 
110
108
 
111
109
  def get_optimization_run_status(
@@ -137,11 +135,11 @@ def get_optimization_run_status(
137
135
  result["nodes"][i]["code"] = ""
138
136
  return result
139
137
  except requests.exceptions.HTTPError as e:
140
- handle_api_error(e, console) # Use default console
141
- raise # Re-raise
138
+ handle_api_error(e, console)
139
+ raise
142
140
  except Exception as e:
143
- print(f"Error getting run status: {e}")
144
- raise # Re-raise
141
+ console.print(f"[bold red]Error getting run status: {e}[/]")
142
+ raise
145
143
 
146
144
 
147
145
  def send_heartbeat(run_id: str, auth_headers: dict = {}, timeout: Union[int, Tuple[int, int]] = (10, 10)) -> bool:
@@ -152,7 +150,7 @@ def send_heartbeat(run_id: str, auth_headers: dict = {}, timeout: Union[int, Tup
152
150
  return True
153
151
  except requests.exceptions.HTTPError as e:
154
152
  if e.response.status_code == 409:
155
- print("Polling ignore: Run {run_id} is not running.", file=sys.stderr)
153
+ print(f"Polling ignore: Run {run_id} is not running.", file=sys.stderr)
156
154
  else:
157
155
  print(f"Polling failed for run {run_id}: HTTP {e.response.status_code}", file=sys.stderr)
158
156
  return False
@@ -221,7 +219,6 @@ def get_optimization_suggestions_from_codebase(
221
219
  """Analyze codebase and get optimization suggestions using the model-agnostic backend API."""
222
220
  model, api_key_dict = _determine_model_and_api_key()
223
221
  try:
224
- model, api_key_dict = _determine_model_and_api_key()
225
222
  response = requests.post(
226
223
  f"{__base_url__}/onboard/analyze-codebase",
227
224
  json={
@@ -238,7 +235,7 @@ def get_optimization_suggestions_from_codebase(
238
235
  result = response.json()
239
236
  return [option for option in result.get("options", [])]
240
237
 
241
- except Exception as e:
238
+ except requests.exceptions.HTTPError as e:
242
239
  handle_api_error(e, console)
243
240
  return None
244
241
  except Exception as e:
@@ -257,7 +254,6 @@ def generate_evaluation_script_and_metrics(
257
254
  """Generate evaluation script and determine metrics using the model-agnostic backend API."""
258
255
  model, api_key_dict = _determine_model_and_api_key()
259
256
  try:
260
- model, api_key_dict = _determine_model_and_api_key()
261
257
  response = requests.post(
262
258
  f"{__base_url__}/onboard/generate-script",
263
259
  json={
@@ -294,7 +290,6 @@ def analyze_evaluation_environment(
294
290
  """Analyze existing evaluation scripts and environment using the model-agnostic backend API."""
295
291
  model, api_key_dict = _determine_model_and_api_key()
296
292
  try:
297
- model, api_key_dict = _determine_model_and_api_key()
298
293
  response = requests.post(
299
294
  f"{__base_url__}/onboard/analyze-environment",
300
295
  json={
@@ -312,7 +307,7 @@ def analyze_evaluation_environment(
312
307
  response.raise_for_status()
313
308
  return response.json()
314
309
 
315
- except Exception as e:
310
+ except requests.exceptions.HTTPError as e:
316
311
  handle_api_error(e, console)
317
312
  return None
318
313
  except Exception as e:
@@ -331,7 +326,6 @@ def analyze_script_execution_requirements(
331
326
  """Analyze script to determine proper execution command using the model-agnostic backend API."""
332
327
  model, api_key_dict = _determine_model_and_api_key()
333
328
  try:
334
- model, api_key_dict = _determine_model_and_api_key()
335
329
  response = requests.post(
336
330
  f"{__base_url__}/onboard/analyze-script",
337
331
  json={
@@ -348,7 +342,7 @@ def analyze_script_execution_requirements(
348
342
  result = response.json()
349
343
  return result.get("command", f"python {script_path}")
350
344
 
351
- except Exception as e:
345
+ except requests.exceptions.HTTPError as e:
352
346
  handle_api_error(e, console)
353
347
  return f"python {script_path}"
354
348
  except Exception as e:
weco/chatbot.py CHANGED
@@ -2,6 +2,7 @@ import pathlib
2
2
  import shlex
3
3
  import argparse
4
4
  from typing import List, Optional, Dict, Any, Tuple
5
+ import sys
5
6
 
6
7
  from rich.console import Console
7
8
  from rich.prompt import Prompt
@@ -682,9 +683,9 @@ class Chatbot:
682
683
 
683
684
  # Import and execute the actual optimization function
684
685
  # (Import here to avoid circular imports)
685
- from .optimizer import execute_optimization as actual_execute_optimization
686
+ from .optimizer import execute_optimization as execute_optimization_run
686
687
 
687
- success = actual_execute_optimization(
688
+ success = execute_optimization_run(
688
689
  source=target_file,
689
690
  eval_command=eval_config["eval_command"],
690
691
  metric=eval_config["metric_name"],
@@ -702,6 +703,9 @@ class Chatbot:
702
703
  else:
703
704
  self.console.print("\n[bold yellow]⚠️ Optimization ended early or encountered issues.[/]")
704
705
 
706
+ exit_code = 0 if success else 1
707
+ sys.exit(exit_code)
708
+
705
709
  def show_and_copy_command(self, command: str) -> None:
706
710
  """Show the command and copy it to clipboard."""
707
711
  import subprocess
weco/cli.py CHANGED
@@ -71,7 +71,7 @@ def configure_run_parser(run_parser: argparse.ArgumentParser) -> None:
71
71
 
72
72
  def execute_run_command(args: argparse.Namespace) -> None:
73
73
  """Execute the 'weco run' command with all its logic."""
74
- from .optimizer import execute_optimization # Moved import inside
74
+ from .optimizer import execute_optimization
75
75
 
76
76
  success = execute_optimization(
77
77
  source=args.source,
weco/optimizer.py CHANGED
@@ -183,6 +183,10 @@ def execute_optimization(
183
183
  auth_headers=auth_headers,
184
184
  timeout=api_timeout,
185
185
  )
186
+ # Indicate the endpoint failed to return a response and the optimization was unsuccessful
187
+ if run_response is None:
188
+ return False
189
+
186
190
  run_id = run_response["run_id"]
187
191
  run_name = run_response["run_name"]
188
192
  current_run_id_for_heartbeat = run_id
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: weco
3
- Version: 0.2.24
3
+ Version: 0.2.26
4
4
  Summary: Documentation for `weco`, a CLI for using Weco AI's code optimizer.
5
5
  Author-email: Weco AI Team <contact@weco.ai>
6
6
  License: MIT
@@ -268,6 +268,7 @@ Weco supports the following LLM models:
268
268
  - `gpt-4o-mini`
269
269
 
270
270
  ### Anthropic Models
271
+ - `claude-opus-4-1`
271
272
  - `claude-opus-4-0`
272
273
  - `claude-sonnet-4-0`
273
274
  - `claude-3-7-sonnet-latest`
@@ -0,0 +1,15 @@
1
+ weco/__init__.py,sha256=ClO0uT6GKOA0iSptvP0xbtdycf0VpoPTq37jHtvlhtw,303
2
+ weco/api.py,sha256=sz97FI0cMm4ku6bMnXsY9Jqgu-lUNELpF6L6vqIaSDE,12997
3
+ weco/auth.py,sha256=KMSAsN1V5wx7KUsYL1cEOOiG29Pqf4Exb3EPW4mAWC0,10003
4
+ weco/chatbot.py,sha256=EkzKd5Q_IlcobBbY3gsbgN0jxbJMfP5eYtzxQaNQ3fg,37747
5
+ weco/cli.py,sha256=jasJpAwibp2rfZflE1LebyQz1dh55Y32G6qDINw4B_U,8161
6
+ weco/constants.py,sha256=vfQGDf9_kzlN9BzEFvMsd0EeXOsRyzpvSWyxOJgRauE,168
7
+ weco/optimizer.py,sha256=iFI1h2HlKFYMiIxVoTFS5aulUIuNjMbsOQw3MGfXIwI,23819
8
+ weco/panels.py,sha256=jwAV_uoa0ZI9vjyey-hSY3rx4pfNNkZvPzqt-iz-RXo,16808
9
+ weco/utils.py,sha256=HecbOqD5rBuVhUkLixVrTWBMJ-ZMAhK-889N-lCk3dQ,7335
10
+ weco-0.2.26.dist-info/licenses/LICENSE,sha256=p_GQqJBvuZgkLNboYKyH-5dhpTDlKs2wq2TVM55WrWE,1065
11
+ weco-0.2.26.dist-info/METADATA,sha256=liTaJZxAI_4Xe21aZ-1YKUzHEvtn1vzyu0liTayEb98,16089
12
+ weco-0.2.26.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
+ weco-0.2.26.dist-info/entry_points.txt,sha256=ixJ2uClALbCpBvnIR6BXMNck8SHAab8eVkM9pIUowcs,39
14
+ weco-0.2.26.dist-info/top_level.txt,sha256=F0N7v6e2zBSlsorFv-arAq2yDxQbzX3KVO8GxYhPUeE,5
15
+ weco-0.2.26.dist-info/RECORD,,
@@ -1,15 +0,0 @@
1
- weco/__init__.py,sha256=ClO0uT6GKOA0iSptvP0xbtdycf0VpoPTq37jHtvlhtw,303
2
- weco/api.py,sha256=sdRgSvbjStGr5Bywkp4Pkuo9jgtGp95tNzsVXrXmH00,13380
3
- weco/auth.py,sha256=KMSAsN1V5wx7KUsYL1cEOOiG29Pqf4Exb3EPW4mAWC0,10003
4
- weco/chatbot.py,sha256=MSG3yybZ0fHTpwW3If9TpOWOAE4EqrcUWpe3q16AjZE,37673
5
- weco/cli.py,sha256=75JdYpUf0qdJW5pjycZoHUKA2n2MYj33qYM9WQwLT2s,8184
6
- weco/constants.py,sha256=vfQGDf9_kzlN9BzEFvMsd0EeXOsRyzpvSWyxOJgRauE,168
7
- weco/optimizer.py,sha256=E5Jii0rTdI9pxkstaM7ipjF4viX5XnSy5w71gdps4Ws,23662
8
- weco/panels.py,sha256=jwAV_uoa0ZI9vjyey-hSY3rx4pfNNkZvPzqt-iz-RXo,16808
9
- weco/utils.py,sha256=HecbOqD5rBuVhUkLixVrTWBMJ-ZMAhK-889N-lCk3dQ,7335
10
- weco-0.2.24.dist-info/licenses/LICENSE,sha256=p_GQqJBvuZgkLNboYKyH-5dhpTDlKs2wq2TVM55WrWE,1065
11
- weco-0.2.24.dist-info/METADATA,sha256=yFq-NPCUsh59B4Pj9IlYjDo53Kzjya5Rk_9-QmheGLM,16069
12
- weco-0.2.24.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
- weco-0.2.24.dist-info/entry_points.txt,sha256=ixJ2uClALbCpBvnIR6BXMNck8SHAab8eVkM9pIUowcs,39
14
- weco-0.2.24.dist-info/top_level.txt,sha256=F0N7v6e2zBSlsorFv-arAq2yDxQbzX3KVO8GxYhPUeE,5
15
- weco-0.2.24.dist-info/RECORD,,
File without changes