Skip to content

Commit

Permalink
Fixed No content and Debug mode BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
haseeb-heaven committed Jan 2, 2025
1 parent 4240865 commit 26b01fb
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 32 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ Here are the available commands:
-`/upgrade` - Upgrade the interpreter.
- 📁 `/prompt` - Switch the prompt mode _File or Input_ modes.
- 💻 `/shell` - Access the shell.
- 🐞 `/debug` - Toggle Debug mode for debugging.


## ⚙️ **Settings**
You can customize the settings of the current model from the `.config` file. It contains all the necessary parameters such as `temperature`, `max_tokens`, and more.
Expand Down Expand Up @@ -333,6 +335,7 @@ If you're interested in contributing to **Code-Interpreter**, we'd love to have
- Fixed issues with logging to both **files and console** simultaneously.
- **Dependency Management**:
- Resolved pip package installation issues for smoother and more reliable setup.
- **v2.2.1** - Fixed **No Content/Response from LLM** Bug, Fixed _Debug Mode_ with **Logs**.

---

Expand Down
6 changes: 3 additions & 3 deletions interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from libs.utility_manager import UtilityManager

# The main version of the interpreter.
INTERPRETER_VERSION = "2.2.0"
INTERPRETER_VERSION = "2.2.1"


def main():
Expand Down Expand Up @@ -78,5 +78,5 @@ def main():
4. Run the interpreter again.")

else:
display_markdown_message(f"An error occurred: {exception}")
traceback.print_exc()
display_markdown_message(f"An error occurred interpreter main: {exception}")
traceback.print_exc()
7 changes: 6 additions & 1 deletion libs/code_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,18 @@ def save_code(self, filename='output/code_generated.py', code=None):
self.logger.error(f"Error occurred while saving code to file: {exception}")
raise Exception(f"Error occurred while saving code to file: {exception}")

def extract_code(self, code:str, start_sep='```', end_sep='```',skip_first_line=False,code_mode=False):
def extract_code(self, code: str, start_sep='```', end_sep='```', skip_first_line=False, code_mode=False):
"""
Extracts the code from the provided string.
If the string contains the start and end separators, it extracts the code between them.
Otherwise, it returns the original string.
"""
try:
if code is None:
self.logger.error("No content were generated by the LLM.")
display_markdown_message("Error: **No content were generated by the LLM.**")
return None

has_newline = False
if start_sep in code and end_sep in code:
start = code.find(start_sep) + len(start_sep)
Expand Down
46 changes: 22 additions & 24 deletions libs/interpreter_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,7 @@ def interpreter_main(self, version):
display_code(f"OS: '{os_name}', Language: '{self.INTERPRETER_LANGUAGE}', Mode: '{self.INTERPRETER_MODE}', Prompt: '{input_prompt_mode}', Model: '{self.INTERPRETER_MODEL}'")

# Display the welcome message.
display_markdown_message("Welcome to the **Interpreter**, I'm here to **assist** you with your everyday tasks. "
"\nEnter your task and I'll do my best to help you out.")
display_markdown_message("Welcome to **Interpreter**, I'm here to **assist** you with your everyday tasks. ")

# Main System and Assistant loop.
running = True
Expand All @@ -524,7 +523,7 @@ def interpreter_main(self, version):
if not prompt_file_name:
prompt_file_name = 'prompt.txt'

prompt_file_path = os.path.join(os.getcwd(),'system',prompt_file_name)
prompt_file_path = os.path.join(os.getcwd(), 'system', prompt_file_name)

# check if the file exists.
if not os.path.exists(prompt_file_path):
Expand Down Expand Up @@ -626,14 +625,11 @@ def interpreter_main(self, version):

# LOG - Command section.
elif task.lower() == '/debug':

# Toggle the log level to Debug/Silent.
logger_mode = Logger.get_current_level()
logger_mode = logger_mode.lower()
print("Logger mode: {}".format(logger_mode))

if logger_mode == 'error':
Logger.set_level_to_info()
if logger_mode.lower() == 'debug':
Logger.set_level_to_error()
display_markdown_message("**Debug** mode **disabled**")
else:
Logger.set_level_to_debug()
Expand Down Expand Up @@ -779,22 +775,23 @@ def interpreter_main(self, version):
code_snippet = self.code_interpreter.extract_code(generated_output, start_sep, end_sep, skip_first_line, self.CODE_MODE)

# Display the extracted code.
self.logger.info(f"Extracted code: {code_snippet[:50]}")
if code_snippet:
self.logger.info(f"Extracted code: {code_snippet[:50]}")

if self.DISPLAY_CODE:
display_code(code_snippet)
self.logger.info("Code extracted successfully.")

# Execute the code if the user has selected.
code_output, code_error = self.execute_code(code_snippet, os_name)
if self.DISPLAY_CODE:
display_code(code_snippet)
self.logger.info("Code extracted successfully.")

if code_output:
self.logger.info(f"{self.INTERPRETER_LANGUAGE} code executed successfully.")
display_code(code_output)
self.logger.info(f"Output: {code_output[:100]}")
elif code_error:
self.logger.info(f"{self.INTERPRETER_LANGUAGE} code executed with error.")
display_markdown_message(f"Error: {code_error}")
# Execute the code if the user has selected.
code_output, code_error = self.execute_code(code_snippet, os_name)

if code_output:
self.logger.info(f"{self.INTERPRETER_LANGUAGE} code executed successfully.")
display_code(code_output)
self.logger.info(f"Output: {code_output[:100]}")
elif code_error:
self.logger.info(f"{self.INTERPRETER_LANGUAGE} code executed with error.")
display_markdown_message(f"Error: {code_error}")
continue

# MODE - Command section.
Expand Down Expand Up @@ -976,7 +973,8 @@ def interpreter_main(self, version):
code_snippet = self.code_interpreter.extract_code(generated_output, start_sep, end_sep, skip_first_line,self.CODE_MODE)

# Display the extracted code.
self.logger.info(f"Extracted code: {code_snippet[:50]}")
if code_snippet:
self.logger.info(f"Extracted code: {code_snippet[:50]}")

if self.DISPLAY_CODE:
display_code(code_snippet)
Expand Down Expand Up @@ -1056,5 +1054,5 @@ def interpreter_main(self, version):
self.history_manager.save_history_json(task, self.INTERPRETER_MODE, os_name, self.INTERPRETER_LANGUAGE, prompt, code_snippet,code_output, self.INTERPRETER_MODEL)

except Exception as exception:
self.logger.error(f"An error occurred: {str(exception)}")
self.logger.error(f"An error occurred in interpreter_lib: {str(exception)}")
raise
11 changes: 7 additions & 4 deletions libs/markdown_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ def display_markdown_message(message):
print("")


def display_code(code: list, language: str = "python"):
def display_code(code: str, language: str = "python"):
try:
if code is None:
return

syntax = Syntax(code, language, theme="monokai", line_numbers=True)
rich_print(syntax,end="",flush=True)
rich_print(syntax, end="", flush=True)
except Exception as exception:
print(f"An error occurred: {exception}")
print(f"An error occurred in display code: {exception}")


class CustomFormatter(TerminalFormatter):
def format(self, tokensource, outfile):
Expand Down

0 comments on commit 26b01fb

Please sign in to comment.