weco 0.2.22__py3-none-any.whl → 0.2.23__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 +22 -62
- {weco-0.2.22.dist-info → weco-0.2.23.dist-info}/METADATA +8 -10
- {weco-0.2.22.dist-info → weco-0.2.23.dist-info}/RECORD +7 -7
- {weco-0.2.22.dist-info → weco-0.2.23.dist-info}/WHEEL +0 -0
- {weco-0.2.22.dist-info → weco-0.2.23.dist-info}/entry_points.txt +0 -0
- {weco-0.2.22.dist-info → weco-0.2.23.dist-info}/licenses/LICENSE +0 -0
- {weco-0.2.22.dist-info → weco-0.2.23.dist-info}/top_level.txt +0 -0
weco/api.py
CHANGED
|
@@ -1,29 +1,11 @@
|
|
|
1
1
|
import sys
|
|
2
2
|
from typing import Dict, Any, Optional, Union, Tuple, List
|
|
3
|
-
|
|
4
3
|
import requests
|
|
5
|
-
from requests.adapters import HTTPAdapter
|
|
6
|
-
from urllib3.util.retry import Retry
|
|
7
4
|
from rich.console import Console
|
|
8
5
|
|
|
9
6
|
from weco import __pkg_version__, __base_url__
|
|
10
7
|
|
|
11
8
|
|
|
12
|
-
# --- Session Configuration ---
|
|
13
|
-
def _get_weco_session() -> requests.Session:
|
|
14
|
-
session = requests.Session()
|
|
15
|
-
retry_strategy = Retry(
|
|
16
|
-
total=3,
|
|
17
|
-
status_forcelist=[429, 500, 502, 503, 504], # Retry on these server errors and rate limiting
|
|
18
|
-
allowed_methods=["HEAD", "GET", "PUT", "POST", "DELETE", "OPTIONS"], # Case-insensitive
|
|
19
|
-
backoff_factor=1, # e.g., sleep for 0s, 2s, 4s between retries (factor * (2 ** ({number of total retries} - 1)))
|
|
20
|
-
)
|
|
21
|
-
adapter = HTTPAdapter(max_retries=retry_strategy)
|
|
22
|
-
session.mount("http://", adapter)
|
|
23
|
-
session.mount("https://", adapter)
|
|
24
|
-
return session
|
|
25
|
-
|
|
26
|
-
|
|
27
9
|
def handle_api_error(e: requests.exceptions.HTTPError, console: Console) -> None:
|
|
28
10
|
"""Extract and display error messages from API responses in a structured format."""
|
|
29
11
|
try:
|
|
@@ -53,8 +35,7 @@ def start_optimization_run(
|
|
|
53
35
|
"""Start the optimization run."""
|
|
54
36
|
with console.status("[bold green]Starting Optimization..."):
|
|
55
37
|
try:
|
|
56
|
-
|
|
57
|
-
response = session.post(
|
|
38
|
+
response = requests.post(
|
|
58
39
|
f"{__base_url__}/runs",
|
|
59
40
|
json={
|
|
60
41
|
"source_code": source_code,
|
|
@@ -76,8 +57,8 @@ def start_optimization_run(
|
|
|
76
57
|
except requests.exceptions.HTTPError as e:
|
|
77
58
|
handle_api_error(e, console)
|
|
78
59
|
sys.exit(1)
|
|
79
|
-
except
|
|
80
|
-
console.print(f"[bold red]
|
|
60
|
+
except Exception as e:
|
|
61
|
+
console.print(f"[bold red]Error starting run: {e}[/]")
|
|
81
62
|
sys.exit(1)
|
|
82
63
|
|
|
83
64
|
|
|
@@ -91,8 +72,7 @@ def evaluate_feedback_then_suggest_next_solution(
|
|
|
91
72
|
) -> Dict[str, Any]:
|
|
92
73
|
"""Evaluate the feedback and suggest the next solution."""
|
|
93
74
|
try:
|
|
94
|
-
|
|
95
|
-
response = session.post(
|
|
75
|
+
response = requests.post(
|
|
96
76
|
f"{__base_url__}/runs/{run_id}/suggest",
|
|
97
77
|
json={
|
|
98
78
|
"execution_output": execution_output,
|
|
@@ -108,8 +88,8 @@ def evaluate_feedback_then_suggest_next_solution(
|
|
|
108
88
|
# Allow caller to handle suggest errors, maybe retry or terminate
|
|
109
89
|
handle_api_error(e, Console()) # Use default console if none passed
|
|
110
90
|
raise # Re-raise the exception
|
|
111
|
-
except
|
|
112
|
-
print(f"
|
|
91
|
+
except Exception as e:
|
|
92
|
+
print(f"Error: {e}") # Use print as console might not be available
|
|
113
93
|
raise # Re-raise the exception
|
|
114
94
|
|
|
115
95
|
|
|
@@ -118,8 +98,7 @@ def get_optimization_run_status(
|
|
|
118
98
|
) -> Dict[str, Any]:
|
|
119
99
|
"""Get the current status of the optimization run."""
|
|
120
100
|
try:
|
|
121
|
-
|
|
122
|
-
response = session.get(
|
|
101
|
+
response = requests.get(
|
|
123
102
|
f"{__base_url__}/runs/{run_id}", params={"include_history": include_history}, headers=auth_headers, timeout=timeout
|
|
124
103
|
)
|
|
125
104
|
response.raise_for_status()
|
|
@@ -127,16 +106,15 @@ def get_optimization_run_status(
|
|
|
127
106
|
except requests.exceptions.HTTPError as e:
|
|
128
107
|
handle_api_error(e, Console()) # Use default console
|
|
129
108
|
raise # Re-raise
|
|
130
|
-
except
|
|
131
|
-
print(f"
|
|
109
|
+
except Exception as e:
|
|
110
|
+
print(f"Error getting run status: {e}")
|
|
132
111
|
raise # Re-raise
|
|
133
112
|
|
|
134
113
|
|
|
135
114
|
def send_heartbeat(run_id: str, auth_headers: dict = {}, timeout: Union[int, Tuple[int, int]] = 10) -> bool:
|
|
136
115
|
"""Send a heartbeat signal to the backend."""
|
|
137
116
|
try:
|
|
138
|
-
|
|
139
|
-
response = session.put(f"{__base_url__}/runs/{run_id}/heartbeat", headers=auth_headers, timeout=timeout)
|
|
117
|
+
response = requests.put(f"{__base_url__}/runs/{run_id}/heartbeat", headers=auth_headers, timeout=timeout)
|
|
140
118
|
response.raise_for_status()
|
|
141
119
|
return True
|
|
142
120
|
except requests.exceptions.HTTPError as e:
|
|
@@ -145,8 +123,8 @@ def send_heartbeat(run_id: str, auth_headers: dict = {}, timeout: Union[int, Tup
|
|
|
145
123
|
else:
|
|
146
124
|
print(f"Heartbeat failed for run {run_id}: HTTP {e.response.status_code}", file=sys.stderr)
|
|
147
125
|
return False
|
|
148
|
-
except
|
|
149
|
-
print(f"
|
|
126
|
+
except Exception as e:
|
|
127
|
+
print(f"Error sending heartbeat for run {run_id}: {e}", file=sys.stderr)
|
|
150
128
|
return False
|
|
151
129
|
|
|
152
130
|
|
|
@@ -160,8 +138,7 @@ def report_termination(
|
|
|
160
138
|
) -> bool:
|
|
161
139
|
"""Report the termination reason to the backend."""
|
|
162
140
|
try:
|
|
163
|
-
|
|
164
|
-
response = session.post(
|
|
141
|
+
response = requests.post(
|
|
165
142
|
f"{__base_url__}/runs/{run_id}/terminate",
|
|
166
143
|
json={"status_update": status_update, "termination_reason": reason, "termination_details": details},
|
|
167
144
|
headers=auth_headers,
|
|
@@ -169,7 +146,7 @@ def report_termination(
|
|
|
169
146
|
)
|
|
170
147
|
response.raise_for_status()
|
|
171
148
|
return True
|
|
172
|
-
except
|
|
149
|
+
except Exception as e:
|
|
173
150
|
print(f"Warning: Failed to report termination to backend for run {run_id}: {e}", file=sys.stderr)
|
|
174
151
|
return False
|
|
175
152
|
|
|
@@ -211,8 +188,7 @@ def get_optimization_suggestions_from_codebase(
|
|
|
211
188
|
"""Analyze codebase and get optimization suggestions using the model-agnostic backend API."""
|
|
212
189
|
try:
|
|
213
190
|
model, api_key_dict = _determine_model_and_api_key()
|
|
214
|
-
|
|
215
|
-
response = session.post(
|
|
191
|
+
response = requests.post(
|
|
216
192
|
f"{__base_url__}/onboard/analyze-codebase",
|
|
217
193
|
json={
|
|
218
194
|
"gitingest_summary": gitingest_summary,
|
|
@@ -231,11 +207,8 @@ def get_optimization_suggestions_from_codebase(
|
|
|
231
207
|
except requests.exceptions.HTTPError as e:
|
|
232
208
|
handle_api_error(e, console)
|
|
233
209
|
return None
|
|
234
|
-
except requests.exceptions.RequestException as e:
|
|
235
|
-
console.print(f"[bold red]Network Error getting optimization suggestions: {e}[/]")
|
|
236
|
-
return None
|
|
237
210
|
except Exception as e:
|
|
238
|
-
console.print(f"[bold red]Error
|
|
211
|
+
console.print(f"[bold red]Error: {e}[/]")
|
|
239
212
|
return None
|
|
240
213
|
|
|
241
214
|
|
|
@@ -250,8 +223,7 @@ def generate_evaluation_script_and_metrics(
|
|
|
250
223
|
"""Generate evaluation script and determine metrics using the model-agnostic backend API."""
|
|
251
224
|
try:
|
|
252
225
|
model, api_key_dict = _determine_model_and_api_key()
|
|
253
|
-
|
|
254
|
-
response = session.post(
|
|
226
|
+
response = requests.post(
|
|
255
227
|
f"{__base_url__}/onboard/generate-script",
|
|
256
228
|
json={
|
|
257
229
|
"target_file": target_file,
|
|
@@ -266,15 +238,11 @@ def generate_evaluation_script_and_metrics(
|
|
|
266
238
|
response.raise_for_status()
|
|
267
239
|
result = response.json()
|
|
268
240
|
return result.get("script_content"), result.get("metric_name"), result.get("goal"), result.get("reasoning")
|
|
269
|
-
|
|
270
241
|
except requests.exceptions.HTTPError as e:
|
|
271
242
|
handle_api_error(e, console)
|
|
272
243
|
return None, None, None, None
|
|
273
|
-
except requests.exceptions.RequestException as e:
|
|
274
|
-
console.print(f"[bold red]Network Error generating evaluation script: {e}[/]")
|
|
275
|
-
return None, None, None, None
|
|
276
244
|
except Exception as e:
|
|
277
|
-
console.print(f"[bold red]Error
|
|
245
|
+
console.print(f"[bold red]Error: {e}[/]")
|
|
278
246
|
return None, None, None, None
|
|
279
247
|
|
|
280
248
|
|
|
@@ -291,8 +259,7 @@ def analyze_evaluation_environment(
|
|
|
291
259
|
"""Analyze existing evaluation scripts and environment using the model-agnostic backend API."""
|
|
292
260
|
try:
|
|
293
261
|
model, api_key_dict = _determine_model_and_api_key()
|
|
294
|
-
|
|
295
|
-
response = session.post(
|
|
262
|
+
response = requests.post(
|
|
296
263
|
f"{__base_url__}/onboard/analyze-environment",
|
|
297
264
|
json={
|
|
298
265
|
"target_file": target_file,
|
|
@@ -312,11 +279,8 @@ def analyze_evaluation_environment(
|
|
|
312
279
|
except requests.exceptions.HTTPError as e:
|
|
313
280
|
handle_api_error(e, console)
|
|
314
281
|
return None
|
|
315
|
-
except requests.exceptions.RequestException as e:
|
|
316
|
-
console.print(f"[bold red]Network Error analyzing evaluation environment: {e}[/]")
|
|
317
|
-
return None
|
|
318
282
|
except Exception as e:
|
|
319
|
-
console.print(f"[bold red]Error
|
|
283
|
+
console.print(f"[bold red]Error: {e}[/]")
|
|
320
284
|
return None
|
|
321
285
|
|
|
322
286
|
|
|
@@ -331,8 +295,7 @@ def analyze_script_execution_requirements(
|
|
|
331
295
|
"""Analyze script to determine proper execution command using the model-agnostic backend API."""
|
|
332
296
|
try:
|
|
333
297
|
model, api_key_dict = _determine_model_and_api_key()
|
|
334
|
-
|
|
335
|
-
response = session.post(
|
|
298
|
+
response = requests.post(
|
|
336
299
|
f"{__base_url__}/onboard/analyze-script",
|
|
337
300
|
json={
|
|
338
301
|
"script_content": script_content,
|
|
@@ -351,9 +314,6 @@ def analyze_script_execution_requirements(
|
|
|
351
314
|
except requests.exceptions.HTTPError as e:
|
|
352
315
|
handle_api_error(e, console)
|
|
353
316
|
return f"python {script_path}"
|
|
354
|
-
except requests.exceptions.RequestException as e:
|
|
355
|
-
console.print(f"[bold red]Network Error analyzing script execution: {e}[/]")
|
|
356
|
-
return f"python {script_path}"
|
|
357
317
|
except Exception as e:
|
|
358
|
-
console.print(f"[bold red]Error
|
|
318
|
+
console.print(f"[bold red]Error: {e}[/]")
|
|
359
319
|
return f"python {script_path}"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: weco
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.23
|
|
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
|
|
@@ -30,10 +30,11 @@ Dynamic: license-file
|
|
|
30
30
|
</div>
|
|
31
31
|
|
|
32
32
|
[](https://www.python.org)
|
|
33
|
+
[](https://badge.fury.io/py/weco)
|
|
33
34
|
[](https://docs.weco.ai/)
|
|
34
|
-
[](https://colab.research.google.com/github/WecoAI/weco-cli/blob/main/examples/hello-kernel-world/colab_notebook_walkthrough.ipynb)
|
|
35
|
+
[](https://pepy.tech/projects/weco)
|
|
36
|
+
[](https://arxiv.org/abs/2502.13138)
|
|
37
|
+
[](https://colab.research.google.com/github/WecoAI/weco-cli/blob/main/examples/hello-kernel-world/colab_notebook_walkthrough.ipynb)
|
|
37
38
|
|
|
38
39
|
`pip install weco`
|
|
39
40
|
|
|
@@ -73,9 +74,9 @@ The `weco` CLI leverages a tree search approach guided by LLMs to iteratively ex
|
|
|
73
74
|
|
|
74
75
|
`weco` requires API keys for the LLMs it uses internally. You **must** provide these keys via environment variables:
|
|
75
76
|
|
|
76
|
-
- **OpenAI:** `export OPENAI_API_KEY="your_key_here"` (Create your API key [here](https://platform.openai.com/api-keys))
|
|
77
|
-
- **Anthropic:** `export ANTHROPIC_API_KEY="your_key_here"` (Create your API key [here](https://console.anthropic.com/settings/keys))
|
|
78
|
-
- **Google:** `export GEMINI_API_KEY="your_key_here"` (Google AI Studio has a free API usage quota. Create your API key [here](https://aistudio.google.com/apikey) to use `weco` for free.)
|
|
77
|
+
- **OpenAI:** `export OPENAI_API_KEY="your_key_here"` (Create your OpenAI API key [here](https://platform.openai.com/api-keys))
|
|
78
|
+
- **Anthropic:** `export ANTHROPIC_API_KEY="your_key_here"` (Create your Anthropic API key [here](https://console.anthropic.com/settings/keys))
|
|
79
|
+
- **Google:** `export GEMINI_API_KEY="your_key_here"` (Google AI Studio has a free API usage quota. Create your Gemini API key [here](https://aistudio.google.com/apikey) to use `weco` for free.)
|
|
79
80
|
|
|
80
81
|
---
|
|
81
82
|
|
|
@@ -252,20 +253,17 @@ Weco will parse this output to extract the numerical value (1.5 in this case) as
|
|
|
252
253
|
We welcome your contributions! To get started:
|
|
253
254
|
|
|
254
255
|
1. **Fork & Clone the Repository:**
|
|
255
|
-
|
|
256
256
|
```bash
|
|
257
257
|
git clone https://github.com/WecoAI/weco-cli.git
|
|
258
258
|
cd weco-cli
|
|
259
259
|
```
|
|
260
260
|
|
|
261
261
|
2. **Install Dependencies:**
|
|
262
|
-
|
|
263
262
|
```bash
|
|
264
263
|
pip install -e ".[dev]"
|
|
265
264
|
```
|
|
266
265
|
|
|
267
266
|
3. **Create a Feature Branch:**
|
|
268
|
-
|
|
269
267
|
```bash
|
|
270
268
|
git checkout -b feature/your-feature-name
|
|
271
269
|
```
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
weco/__init__.py,sha256=ClO0uT6GKOA0iSptvP0xbtdycf0VpoPTq37jHtvlhtw,303
|
|
2
|
-
weco/api.py,sha256=
|
|
2
|
+
weco/api.py,sha256=hqAyMHGQhJr8BZTUo0jznfO0ossGU3ehEZZehPu6Mu8,11838
|
|
3
3
|
weco/auth.py,sha256=6bDQv07sx7uxA9CrN3HqUdCHV6nqXO41PGCicquvB00,9919
|
|
4
4
|
weco/chatbot.py,sha256=H6d5yK9MB3pqpE7XVh_HAi1YAmxKy0v_xdozVSlKPCc,36959
|
|
5
5
|
weco/cli.py,sha256=Jy7kQEsNKdV7Wds9Z0DIWBeLpEVyssIiOBiQ4zCl3Lw,7862
|
|
6
6
|
weco/optimizer.py,sha256=z86-js_rvLMv3J8zCqvtc1xJC0EA0WqrN9_BlmX2RK4,23259
|
|
7
7
|
weco/panels.py,sha256=Cnro4Q65n7GGh0FBXuB_OGSxRVobd4k5lOuBViTQaaM,15591
|
|
8
8
|
weco/utils.py,sha256=5Pbhv_5wbTRv93Ws7aJfIOtcxeeqNrDRT3bV6YFOdgM,6032
|
|
9
|
-
weco-0.2.
|
|
10
|
-
weco-0.2.
|
|
11
|
-
weco-0.2.
|
|
12
|
-
weco-0.2.
|
|
13
|
-
weco-0.2.
|
|
14
|
-
weco-0.2.
|
|
9
|
+
weco-0.2.23.dist-info/licenses/LICENSE,sha256=p_GQqJBvuZgkLNboYKyH-5dhpTDlKs2wq2TVM55WrWE,1065
|
|
10
|
+
weco-0.2.23.dist-info/METADATA,sha256=E_u4w-WaRzBVYrlEzraepi0y7E1Cc1zHOhBu4Cp01TI,15445
|
|
11
|
+
weco-0.2.23.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
12
|
+
weco-0.2.23.dist-info/entry_points.txt,sha256=ixJ2uClALbCpBvnIR6BXMNck8SHAab8eVkM9pIUowcs,39
|
|
13
|
+
weco-0.2.23.dist-info/top_level.txt,sha256=F0N7v6e2zBSlsorFv-arAq2yDxQbzX3KVO8GxYhPUeE,5
|
|
14
|
+
weco-0.2.23.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|