Skip to content

Commit 28244e6

Browse files
committed
fix: correct formatting for cline/kodu
Content comes wrapped into <task> or <environment_details>
1 parent f11e28d commit 28244e6

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/codegate/api/v1_processing.py

+19-10
Original file line numberDiff line numberDiff line change
@@ -180,25 +180,34 @@ async def _get_question_answer(row: GetPromptWithOutputsRow) -> Optional[Partial
180180

181181

182182
def parse_question_answer(input_text: str) -> str:
183-
# given a string, detect if we have a pattern of "Context: xxx \n\nQuery: xxx" and strip it
184-
pattern = r"^Context:.*?\n\n\s*Query:\s*(.*)$"
183+
# Remove the <environment_details>...</environment_details> pattern if present
184+
env_details_pattern = r"\n<environment_details>.*?</environment_details>"
185+
input_text = re.sub(env_details_pattern, "", input_text, flags=re.DOTALL).strip()
185186

186-
# Search using the regex pattern
187-
match = re.search(pattern, input_text, re.DOTALL)
187+
# Check for the <task>...</task> pattern first
188+
task_pattern = r"^<task>(.*?)</task>"
189+
task_match = re.search(task_pattern, input_text, re.DOTALL)
188190

189-
# If a match is found, return the captured group after "Query:"
190-
if match:
191-
return match.group(1)
192-
else:
193-
return input_text
191+
if task_match:
192+
return task_match.group(1).strip()
193+
194+
# If no <task>...</task>, check for "Context: xxx \n\nQuery: xxx"
195+
context_query_pattern = r"^Context:.*?\n\n\s*Query:\s*(.*)$"
196+
context_query_match = re.search(context_query_pattern, input_text, re.DOTALL)
197+
198+
if context_query_match:
199+
return context_query_match.group(1).strip()
200+
201+
# If no pattern matches, return the original input text
202+
return input_text
194203

195204

196205
def _clean_secrets_from_message(message: str) -> str:
197206
pattern = re.compile(r"REDACTED<(\$?[^>]+)>")
198207
return pattern.sub("REDACTED_SECRET", message)
199208

200209

201-
def _group_partial_messages(pq_list: List[PartialQuestions]) -> List[List[PartialQuestions]]:
210+
def _group_partial_messages(pq_list: List[PartialQuestions]) -> List[List[PartialQuestions]]: # noqa: C901
202211
"""
203212
A PartialQuestion is an object that contains several user messages provided from a
204213
chat conversation. Example:

0 commit comments

Comments
 (0)