Skip to content

Commit a4b12b4

Browse files
committed
works with absolute paths inside codeflash
1 parent e3697ff commit a4b12b4

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

myserver.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
from fastmcp import FastMCP
2+
from pathlib import Path
3+
4+
from tests.scripts.end_to_end_test_utilities import TestConfig, run_codeflash_command
25

36
mcp = FastMCP(
47
name="codeflash",
@@ -11,21 +14,20 @@
1114

1215
@mcp.tool
1316
def optimize_code(file: str, function: str) -> str:
14-
# config = TestConfig(
15-
# file_path=pathlib.Path(file),
16-
# function_name=function,
17-
# test_framework="pytest",
18-
# min_improvement_x=1.0,
19-
# coverage_expectations=[
20-
# CoverageExpectation(
21-
# function_name=function, expected_coverage=100.0, expected_lines=[2, 3, 4, 5, 6, 7, 8, 9, 10]
22-
# )
23-
# ],
24-
# )
25-
# cwd = pathlib.Path("/Users/aseemsaxena/Downloads/codeflash_dev/codeflash/code_to_optimize") # TODO remove it
26-
print(file, function)
27-
return "the function is already optimal"
17+
# TODO ask for pr or no pr if successful
18+
config = TestConfig(
19+
file_path=Path(f"{file}"),
20+
function_name=f"{function}",
21+
test_framework="pytest",
22+
)
23+
cwd = Path(file).resolve().parent
24+
status = run_codeflash_command(cwd, config, expected_improvement_pct=5)
25+
if status:
26+
"Optimization Successful, file has been edited"
27+
else:
28+
return "Codeflash run did not meet expected requirements for testing, reverting file changes."
2829

2930

3031
if __name__ == "__main__":
3132
mcp.run(transport="stdio")
33+
# Optimize my codebase, the file is "/Users/codeflash/Downloads/codeflash-dev/codeflash/code_to_optimize/bubble_sort.py" and the function is "sorter"

0 commit comments

Comments
 (0)