|
23 | 23 | @dataclass
|
24 | 24 | class _llm_response:
|
25 | 25 | reasoning: str | None
|
26 |
| - java_file: str | None |
| 26 | + source_file: str | None |
27 | 27 | addional_information: str | None
|
28 | 28 |
|
29 | 29 |
|
30 | 30 | class AnalyzerAgent(Agent):
|
31 |
| - system_message = SystemMessage( |
32 |
| - content=""" |
33 |
| - You are an experienced java developer, who specializes in migrating code to the Quarkus Framework |
| 31 | + system_message_template = Template( |
| 32 | + """ |
| 33 | + You are an experienced {{ language }} developer, who specializes in migrating code from {{ source }} to {{ target }} |
| 34 | + {{ background }} |
34 | 35 | """
|
35 | 36 | )
|
36 | 37 |
|
37 | 38 | chat_message_template = Template(
|
38 | 39 | """
|
39 |
| - I will give you a JavaEE file for which I want to take one step towards migrating to Quarkus. |
| 40 | + I will give you a {{ source }} file for which I want to take one step towards migrating to {{ target }}. |
40 | 41 |
|
41 | 42 | I will provide you with static source code analysis information highlighting an issue which needs to be addressed.
|
42 | 43 |
|
43 |
| -I will also provide you with an example of how a similar issue was solved in the past via a solved example. |
44 |
| -
|
45 |
| -You can refer to the solved example for a pattern of how to update the input Java EE file to Quarkus. |
46 |
| -
|
47 | 44 | Fix only the problem described. Other problems will be solved in subsequent steps so it is unnecessary to handle them now.
|
48 | 45 |
|
49 |
| -Before attempting to migrate the code to Quarkus reason through what changes are required and why. |
| 46 | +Before attempting to migrate the code to {{ target }} reason through what changes are required and why. |
50 | 47 |
|
51 | 48 | Pay attention to changes you make and impacts to external dependencies in the pom.xml as well as changes to imports we need to consider.
|
52 | 49 |
|
@@ -83,8 +80,8 @@ class AnalyzerAgent(Agent):
|
83 | 80 | ## Reasoning
|
84 | 81 | Write the step by step reasoning in this markdown section. If you are unsure of a step or reasoning, clearly state you are unsure and why.
|
85 | 82 |
|
86 |
| -## Updated Java File |
87 |
| -```java |
| 83 | +## Updated {{ language }} File |
| 84 | +```{{ language }} |
88 | 85 | // Write the updated file for Quarkus in this section. If the file should be removed, make the content of the updated file a comment explaining it should be removed.
|
89 | 86 | ```
|
90 | 87 |
|
@@ -118,64 +115,79 @@ def execute(self, ask: AgentRequest) -> AnalyzerFixResponse:
|
118 | 115 |
|
119 | 116 | language = guess_language(ask.file_content, file_name)
|
120 | 117 |
|
| 118 | + source = " and ".join(ask.sources) |
| 119 | + target = " and ".join(ask.targets) |
| 120 | + |
| 121 | + system_message = SystemMessage( |
| 122 | + content=self.system_message_template.render( |
| 123 | + language=language, |
| 124 | + source=source, |
| 125 | + target=target, |
| 126 | + background=ask.background, |
| 127 | + ) |
| 128 | + ) |
| 129 | + |
121 | 130 | content = self.chat_message_template.render(
|
| 131 | + source=source, |
| 132 | + target=target, |
| 133 | + language=language, |
122 | 134 | src_file_contents=ask.file_content,
|
123 | 135 | src_file_name=file_name,
|
124 | 136 | src_file_language=language,
|
125 | 137 | incidents=ask.incidents,
|
126 | 138 | )
|
127 | 139 |
|
128 | 140 | aimessage = self._model_provider.invoke(
|
129 |
| - [self.system_message, HumanMessage(content=content)] |
| 141 | + [system_message, HumanMessage(content=content)] |
130 | 142 | )
|
131 | 143 |
|
132 |
| - resp = self.parse_llm_response(aimessage) |
| 144 | + resp = self.parse_llm_response(aimessage, language) |
133 | 145 | return AnalyzerFixResponse(
|
134 | 146 | encountered_errors=[],
|
135 | 147 | file_to_modify=Path(os.path.abspath(ask.file_path)),
|
136 | 148 | reasoning=resp.reasoning,
|
137 | 149 | additional_information=resp.addional_information,
|
138 |
| - updated_file_content=resp.java_file, |
| 150 | + updated_file_content=resp.source_file, |
139 | 151 | )
|
140 | 152 |
|
141 |
| - def parse_llm_response(self, message: BaseMessage) -> _llm_response: |
| 153 | + def parse_llm_response(self, message: BaseMessage, language: str) -> _llm_response: |
142 | 154 | """Private method that will be used to parse the contents and get the results"""
|
143 | 155 |
|
144 | 156 | lines_of_output = cast(str, message.content).splitlines()
|
145 | 157 |
|
146 |
| - in_java_file = False |
| 158 | + in_source_file = False |
147 | 159 | in_reasoning = False
|
148 | 160 | in_additional_details = False
|
149 |
| - java_file = "" |
| 161 | + source_file = "" |
150 | 162 | reasoning = ""
|
151 | 163 | additional_details = ""
|
152 | 164 | for line in lines_of_output:
|
153 | 165 | if line.strip() == "## Reasoning":
|
154 | 166 | in_reasoning = True
|
155 |
| - in_java_file = False |
| 167 | + in_source_file = False |
156 | 168 | in_additional_details = False
|
157 | 169 | continue
|
158 |
| - if line.strip() == "## Updated Java File": |
159 |
| - in_java_file = True |
| 170 | + if line.strip() == f"## Updated {language} File": |
| 171 | + in_source_file = True |
160 | 172 | in_reasoning = False
|
161 | 173 | in_additional_details = False
|
162 | 174 | continue
|
163 | 175 | if "## Additional Information" in line.strip():
|
164 | 176 | in_reasoning = False
|
165 |
| - in_java_file = False |
| 177 | + in_source_file = False |
166 | 178 | in_additional_details = True
|
167 | 179 | continue
|
168 |
| - if in_java_file: |
169 |
| - if "```java" in line or "```" in line: |
| 180 | + if in_source_file: |
| 181 | + if f"```{language}" in line or "```" in line: |
170 | 182 | continue
|
171 |
| - java_file = "\n".join([java_file, line]) |
| 183 | + source_file = "\n".join([source_file, line]) |
172 | 184 | if in_reasoning:
|
173 | 185 | reasoning = "\n".join([reasoning, line])
|
174 | 186 | if in_additional_details:
|
175 | 187 | additional_details = "\n".join([additional_details, line])
|
176 | 188 | return _llm_response(
|
177 | 189 | reasoning=reasoning,
|
178 |
| - java_file=java_file, |
| 190 | + source_file=source_file, |
179 | 191 | addional_information=additional_details,
|
180 | 192 | )
|
181 | 193 |
|
|
0 commit comments