Skip to content

Commit 4787d02

Browse files
committed
Merge branch 'main' into docs
Update README
2 parents 96c623c + 55be7de commit 4787d02

File tree

6 files changed

+28
-24
lines changed

6 files changed

+28
-24
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
GITHUB_TOKEN: ${{ github.token }}
9191
run: >-
9292
gh release create
93-
'v0.2.7'
93+
'v0.2.8'
9494
--repo '${{ github.repository }}'
9595
--notes ""
9696
@@ -102,5 +102,5 @@ jobs:
102102
# sigstore-produced signatures and certificates.
103103
run: >-
104104
gh release upload
105-
'v0.2.7' dist/**
105+
'v0.2.8' dist/**
106106
--repo '${{ github.repository }}'

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ authors = [
1010
]
1111
description = "Documentation for `weco`, a CLI for using Weco AI's code optimizer."
1212
readme = "README.md"
13-
version = "0.2.7"
13+
version = "0.2.8"
1414
license = {text = "MIT"}
15-
requires-python = ">=3.12"
15+
requires-python = ">=3.8"
1616
dependencies = ["requests", "rich"]
1717
keywords = ["AI", "Code Optimization", "Code Generation"]
1818
classifiers = [

weco/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# DO NOT EDIT
2-
__pkg_version__ = "0.2.7"
2+
__pkg_version__ = "0.2.8"
33
__api_version__ = "v1"
44
__base_url__ = f"https://api.aide.weco.ai/{__api_version__}"

weco/api.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@
66

77

88
def handle_api_error(e: requests.exceptions.HTTPError, console: rich.console.Console) -> None:
9-
"""Extract and display error messages from API responses."""
10-
try:
11-
error_data = e.response.json()
12-
error_message = error_data.get("detail", str(e))
13-
console.print(f"[bold red]Server Error:[/] {error_message}")
14-
except Exception:
15-
# If we can't parse the JSON, just show the original error
16-
console.print(f"[bold red]Server Error:[/] {str(e)}")
9+
"""Extract and display error messages from API responses in a structured format."""
10+
error_message = str(e) # Default message
11+
console.print(f"[bold red]Error:[/] {error_message}")
1712
sys.exit(1)
1813

1914

weco/cli.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def main() -> None:
3636
parser = argparse.ArgumentParser(
3737
description="[bold cyan]Weco CLI[/]", formatter_class=argparse.RawDescriptionHelpFormatter
3838
)
39-
parser.add_argument("--source", type=str, required=True, help="Path to the Python source code (e.g. optimize.py)")
39+
parser.add_argument("--source", type=str, required=True, help="Path to the source code (e.g. optimize.py)")
4040
parser.add_argument(
4141
"--eval-command", type=str, required=True, help="Command to run for evaluation (e.g. 'python eval.py --arg1=val1')"
4242
)
@@ -88,7 +88,7 @@ def main() -> None:
8888
maximize=maximize, metric_name=metric_name, total_steps=steps, model=args.model, runs_dir=args.log_dir
8989
)
9090
plan_panel = PlanPanel()
91-
solution_panels = SolutionPanels(metric_name=metric_name)
91+
solution_panels = SolutionPanels(metric_name=metric_name, source_fp=source_fp)
9292
eval_output_panel = EvaluationOutputPanel()
9393
tree_panel = MetricTreePanel(maximize=maximize)
9494
layout = create_optimization_layout()
@@ -118,8 +118,8 @@ def main() -> None:
118118
runs_dir = pathlib.Path(args.log_dir) / session_id
119119
runs_dir.mkdir(parents=True, exist_ok=True)
120120

121-
# Save the original code (.runs/<session-id>/original.py)
122-
runs_copy_source_fp = runs_dir / "original.py"
121+
# Save the original code (.runs/<session-id>/original.<extension>)
122+
runs_copy_source_fp = runs_dir / f"original.{source_fp.suffix}"
123123
write_to_path(fp=runs_copy_source_fp, content=source_code)
124124

125125
# Write the code string to the source file path
@@ -200,8 +200,8 @@ def main() -> None:
200200
api_keys=api_keys,
201201
timeout=timeout,
202202
)
203-
# Save next solution (.runs/<session-id>/step_<step>.py)
204-
write_to_path(fp=runs_dir / f"step_{step}.py", content=eval_and_next_solution_response["code"])
203+
# Save next solution (.runs/<session-id>/step_<step>.<extension>)
204+
write_to_path(fp=runs_dir / f"step_{step}.{source_fp.suffix}", content=eval_and_next_solution_response["code"])
205205

206206
# Write the next solution to the source file
207207
write_to_path(fp=source_fp, content=eval_and_next_solution_response["code"])
@@ -351,8 +351,8 @@ def main() -> None:
351351
)
352352
best_solution_content = f"# Best solution from Weco with a score of {best_score_str}\n\n{best_solution_code}"
353353

354-
# Save best solution to .runs/<session-id>/best.py
355-
write_to_path(fp=runs_dir / "best.py", content=best_solution_content)
354+
# Save best solution to .runs/<session-id>/best.<extension>
355+
write_to_path(fp=runs_dir / f"best.{source_fp.suffix}", content=best_solution_content)
356356

357357
# write the best solution to the source file
358358
write_to_path(fp=source_fp, content=best_solution_content)

weco/panels.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from rich.syntax import Syntax
77
from typing import Dict, List, Optional, Union, Tuple
88
from .utils import format_number
9+
import pathlib
910

1011

1112
class SummaryPanel:
@@ -46,6 +47,8 @@ def get_display(self, final_message: Optional[str] = None) -> Panel:
4647
"""Create a summary panel with the relevant information."""
4748
layout = Layout(name="summary")
4849
summary_table = Table(show_header=False, box=None, padding=(0, 1))
50+
51+
summary_table.add_row("")
4952
# Goal
5053
if final_message is not None:
5154
summary_table.add_row(f"[bold cyan]Result:[/] {final_message}")
@@ -256,13 +259,19 @@ def get_display(self) -> Panel:
256259
class SolutionPanels:
257260
"""Displays the current and best solutions side by side."""
258261

259-
def __init__(self, metric_name: str):
262+
def __init__(self, metric_name: str, source_fp: pathlib.Path):
260263
# Current solution
261264
self.current_node = None
262265
# Best solution
263266
self.best_node = None
264267
# Metric name
265268
self.metric_name = metric_name.capitalize()
269+
# Determine the lexer for the source file
270+
self.lexer = self._determine_lexer(source_fp)
271+
272+
def _determine_lexer(self, source_fp: pathlib.Path) -> str:
273+
"""Determine the lexer for the source file."""
274+
return Syntax.from_path(source_fp).lexer
266275

267276
def update(self, current_node: Union[Node, None], best_node: Union[Node, None]):
268277
"""Update the current and best solutions."""
@@ -280,7 +289,7 @@ def get_display(self, current_step: int) -> Tuple[Panel, Panel]:
280289
# Current solution (without score)
281290
current_title = f"[bold]💡 Current Solution (Step {current_step})"
282291
current_panel = Panel(
283-
Syntax(str(current_code), "python", theme="monokai", line_numbers=True, word_wrap=False),
292+
Syntax(str(current_code), self.lexer, theme="monokai", line_numbers=True, word_wrap=False),
284293
title=current_title,
285294
border_style="yellow",
286295
expand=True,
@@ -290,7 +299,7 @@ def get_display(self, current_step: int) -> Tuple[Panel, Panel]:
290299
# Best solution
291300
best_title = f"[bold]🏆 Best Solution ([green]{self.metric_name}: {f'{best_score:.4f}' if best_score is not None else 'N/A'}[/])"
292301
best_panel = Panel(
293-
Syntax(str(best_code), "python", theme="monokai", line_numbers=True, word_wrap=False),
302+
Syntax(str(best_code), self.lexer, theme="monokai", line_numbers=True, word_wrap=False),
294303
title=best_title,
295304
border_style="green",
296305
expand=True,

0 commit comments

Comments
 (0)