|
1 | | -import pathlib |
2 | | - |
3 | 1 | from fastmcp import FastMCP |
4 | 2 |
|
5 | | -from tests.scripts.end_to_end_test_utilities import CoverageExpectation, TestConfig, run_codeflash_command |
6 | | - |
7 | 3 | mcp = FastMCP( |
8 | 4 | name="codeflash", |
9 | 5 | instructions=""" |
|
14 | 10 |
|
15 | 11 |
|
16 | 12 | @mcp.tool |
17 | | -def optimize_code(file: str, function: str) -> bool: |
18 | | - config = TestConfig( |
19 | | - file_path=pathlib.Path(file), |
20 | | - function_name=function, |
21 | | - test_framework="pytest", |
22 | | - min_improvement_x=1.0, |
23 | | - coverage_expectations=[ |
24 | | - CoverageExpectation( |
25 | | - function_name=function, expected_coverage=100.0, expected_lines=[2, 3, 4, 5, 6, 7, 8, 9, 10] |
26 | | - ) |
27 | | - ], |
28 | | - ) |
29 | | - cwd = (pathlib.Path(__file__).parent / "code_to_optimize").resolve() # TODO remove it |
30 | | - return run_codeflash_command( |
31 | | - cwd, config, 100, ['print("codeflash stdout: Sorting list")', 'print(f"result: {arr}")'] |
32 | | - ) |
| 13 | +def optimize_code(file: str, function: str) -> dict[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 { |
| 28 | + "code": """def sorter(arr): |
| 29 | + print("codeflash stdout: Sorting list") |
| 30 | + arr.sort() |
| 31 | + print(f"result: {arr}") |
| 32 | + return arr |
| 33 | +""", |
| 34 | + "explanation": "A faster version of the code is using python's in-built timsort function", |
| 35 | + } |
33 | 36 |
|
34 | 37 |
|
35 | 38 | if __name__ == "__main__": |
36 | | - mcp.run(transport="http", port=8000) |
| 39 | + mcp.run(transport="stdio") |
0 commit comments