Fix: py interpreter problems, Feat : more pretty output
This commit is contained in:
+22
-3
@@ -6,24 +6,43 @@ from sources.agent import Agent
|
||||
class CoderAgent(Agent):
|
||||
def __init__(self, model, name, prompt_path, provider):
|
||||
super().__init__(model, name, prompt_path, provider)
|
||||
self.set_system_prompt(prompt_path)
|
||||
self._tools = {
|
||||
"bash": BashInterpreter(),
|
||||
"python": PyInterpreter()
|
||||
}
|
||||
|
||||
def remove_blocks(self, text: str) -> str:
|
||||
"""
|
||||
Remove all code/query blocks within a tag from the answer text.
|
||||
"""
|
||||
tag = f'```'
|
||||
lines = text.split('\n')
|
||||
post_lines = []
|
||||
in_block = False
|
||||
for line in lines:
|
||||
if tag in line and not in_block:
|
||||
in_block = True
|
||||
continue
|
||||
if not in_block:
|
||||
post_lines.append(line)
|
||||
if tag in line:
|
||||
in_block = False
|
||||
return "\n".join(post_lines)
|
||||
|
||||
def answer(self, prompt, speech_module) -> str:
|
||||
answer = ""
|
||||
attempt = 0
|
||||
max_attempts = 3
|
||||
self.add_to_history('user', prompt)
|
||||
self._history.push('user', prompt)
|
||||
|
||||
while attempt < max_attempts:
|
||||
pretty_print("Thinking...", color="status")
|
||||
self.wait_message(speech_module)
|
||||
answer, reasoning = self.llm_request(self.history)
|
||||
answer, reasoning = self.llm_request()
|
||||
exec_success, feedback = self.execute_modules(answer)
|
||||
pretty_print(feedback, color="failure" if "failure" in feedback.lower() else "success")
|
||||
answer = self.remove_blocks(answer)
|
||||
pretty_print(answer, color="output")
|
||||
if exec_success:
|
||||
break
|
||||
attempt += 1
|
||||
|
||||
Reference in New Issue
Block a user