diff --git a/prompts/base/coder_agent.txt b/prompts/base/coder_agent.txt index 13dd55b..5323190 100644 --- a/prompts/base/coder_agent.txt +++ b/prompts/base/coder_agent.txt @@ -47,7 +47,6 @@ Some rules: - Be efficient, no need to explain your code, unless asked. - You do not ever need to use bash to execute code. - Do not ever tell user how to run it. user know it. -- In python do not use if __name__ == "__main__" - If using gui, make sure echap or exit button close the program - No lazyness, write and rewrite full code every time - If query is unclear say REQUEST_CLARIFICATION \ No newline at end of file diff --git a/prompts/jarvis/coder_agent.txt b/prompts/jarvis/coder_agent.txt index c862261..9b71990 100644 --- a/prompts/jarvis/coder_agent.txt +++ b/prompts/jarvis/coder_agent.txt @@ -46,7 +46,6 @@ Some rules: - Be efficient, no need to explain your code, unless asked. - You do not ever need to use bash to execute code. - Do not ever tell user how to run it. user know it. -- In python do not use if __name__ == "__main__" - If using gui, make sure echap close the program - No lazyness, write and rewrite full code every time - If query is unclear say REQUEST_CLARIFICATION diff --git a/sources/llm_provider.py b/sources/llm_provider.py index a79e66d..bfc54fc 100644 --- a/sources/llm_provider.py +++ b/sources/llm_provider.py @@ -34,7 +34,7 @@ class Provider: } self.logger = Logger("provider.log") self.api_key = None - self.unsafe_providers = ["openai", "deepseek", "dsk_deepseek"] + self.unsafe_providers = ["openai", "deepseek", "dsk_deepseek", "together"] if self.provider_name not in self.available_providers: raise ValueError(f"Unknown provider: {provider_name}") if self.provider_name in self.unsafe_providers: diff --git a/sources/tools/PyInterpreter.py b/sources/tools/PyInterpreter.py index 5d8ec86..350e590 100644 --- a/sources/tools/PyInterpreter.py +++ b/sources/tools/PyInterpreter.py @@ -33,16 +33,24 @@ class PyInterpreter(Tools): '__name__': '__main__' } code = '\n\n'.join(codes) + self.logger.info(f"Executing code:\n{code}") try: try: buffer = exec(code, global_vars) + self.logger.info(f"Code executed successfully.\noutput:{buffer}") print(buffer) if buffer is not None: output = buffer + '\n' + except SystemExit: + self.logger.info("SystemExit caught, code execution stopped.") + output = stdout_buffer.getvalue() + return f"[SystemExit caught] Output before exit:\n{output}" except Exception as e: + self.logger.error(f"Code execution failed: {str(e)}") return "code execution failed:" + str(e) output = stdout_buffer.getvalue() finally: + self.logger.info("Code execution finished.") sys.stdout = sys.__stdout__ return output @@ -75,7 +83,9 @@ class PyInterpreter(Tools): ] combined_pattern = "|".join(error_patterns) if re.search(combined_pattern, feedback, re.IGNORECASE): + self.logger.error(f"Execution failure detected: {feedback}") return True + self.logger.info("No execution success detected.") return False if __name__ == "__main__": diff --git a/sources/tools/tools.py b/sources/tools/tools.py index 27a2069..090ae7d 100644 --- a/sources/tools/tools.py +++ b/sources/tools/tools.py @@ -21,6 +21,7 @@ import sys import os import configparser from abc import abstractmethod +from sources.logger import Logger sys.path.append('..') @@ -33,6 +34,7 @@ class Tools(): self.api_key = None self.client = None self.messages = [] + self.logger = Logger("tools.log") self.config = configparser.ConfigParser() self.work_dir = self.create_work_dir() self.excutable_blocks_found = False @@ -118,10 +120,12 @@ class Tools(): """ if save_path is None: return + self.logger.info(f"Saving blocks to {save_path}") save_path_dir = os.path.dirname(save_path) save_path_file = os.path.basename(save_path) directory = os.path.join(self.work_dir, save_path_dir) if directory and not os.path.exists(directory): + self.logger.info(f"Creating directory {directory}") os.makedirs(directory) for block in blocks: with open(os.path.join(directory, save_path_file), 'w') as f: @@ -199,6 +203,7 @@ class Tools(): self.excutable_blocks_found = True code_blocks.append(content) start_index = end_pos + len(end_tag) + self.logger.info(f"Found {len(code_blocks)} blocks to execute") return code_blocks, save_path if __name__ == "__main__":