|
10 | 10 | ChatCompletionSystemMessageParam, |
11 | 11 | ParsedChatCompletion, |
12 | 12 | ) |
13 | | -from pydantic import BaseModel |
14 | 13 | from rich import print as rprint |
15 | 14 |
|
| 15 | +from accelerant.chat_interface import ( |
| 16 | + ProjectAnalysis, |
| 17 | + OptimizationSuite, |
| 18 | +) |
| 19 | +from accelerant.lsp import ( |
| 20 | + request_document_diagnostics, |
| 21 | + syncexec, |
| 22 | +) |
| 23 | +from accelerant.patch import apply_simultaneous_suggestions |
16 | 24 | from accelerant.perf import PerfData |
17 | 25 | from accelerant.project import Project |
18 | 26 | from accelerant.tools import ( |
|
24 | 32 | from perfparser import LineLoc |
25 | 33 |
|
26 | 34 |
|
27 | | -class RegionAnalysis(BaseModel): |
28 | | - filename: str |
29 | | - line: int |
30 | | - performanceAnalysis: str |
31 | | - |
32 | | - |
33 | | -class ProjectAnalysis(BaseModel): |
34 | | - regions: List[RegionAnalysis] |
35 | | - |
36 | | - |
37 | | -class OptimizationSuggestion(BaseModel): |
38 | | - filename: str |
39 | | - startLine: int |
40 | | - endLine: int |
41 | | - newCode: str |
42 | | - |
43 | | - |
44 | | -class OptimizationSuite(BaseModel): |
45 | | - highLevelSummary: str |
46 | | - suggestions: List[OptimizationSuggestion] |
47 | | - |
48 | | - |
49 | 35 | def optimize_locations( |
50 | 36 | project: Project, locs: List[LineLoc], perf_data: Optional[PerfData], model_id: str |
51 | 37 | ) -> str: |
@@ -117,9 +103,22 @@ def optimize_locations( |
117 | 103 | ), |
118 | 104 | {"role": "user", "content": sugg_req_msg}, |
119 | 105 | ] |
120 | | - sugg_str, _ = run_chat( |
| 106 | + sugg_str, opt_suite = run_chat( |
121 | 107 | messages, client, model_id, tool_runner, response_format=OptimizationSuite |
122 | 108 | ) |
| 109 | + assert opt_suite |
| 110 | + apply_simultaneous_suggestions(opt_suite.suggestions, project) |
| 111 | + # TODO: collect diagnostics from all files, then feed them back to LLM |
| 112 | + # FIXME: how to get diagnostics from files that depend on these files |
| 113 | + # but weren't themselves changed? |
| 114 | + print( |
| 115 | + syncexec( |
| 116 | + project.lsp(), |
| 117 | + request_document_diagnostics( |
| 118 | + project.lsp().language_server, opt_suite.suggestions[0].filename |
| 119 | + ), |
| 120 | + ) |
| 121 | + ) |
123 | 122 | return sugg_str |
124 | 123 |
|
125 | 124 |
|
|
0 commit comments