Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error handling for Ctrl+C/Exit/Error in devika.py and Bug fixes #475

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Apr 22, 2024

  1. "Improve error handling for Ctrl+C/Exit/Error in devika.py, JSON pars…

    …ing in Runner class, Terminal UI Error Outputs"
    
    Updates Agent State to inactive after error or before exit (Bug: Espically when Terminal runs a webapp, there is no way to terminate the process, terminating devika causes the agent to freeze in "active" state.
    
    Changes in devika.py
    
    A new import statement has been added: from contextlib import ExitStack. This suggests that the code is using the ExitStack context manager to manage resources, such as signal handlers.
    A new function handle_error has been added. This function appears to handle errors and Ctrl+C interruptions by setting an agent's state to inactive and completed. It also exits the program with a non-zero code to indicate an error.
    The handle_error function is registered as a signal handler for SIGINT (Ctrl+C) using the signal module and ExitStack.
    
    Changes in runner.py
    
    The validate_response and validate_rerunner_response methods have been modified to extract JSON data from the response string. The old implementation used strip() and replace() to remove unwanted characters, whereas the new implementation uses index() and rindex() to find the start and end of the JSON data.
    The JSON data is now extracted using slicing (response[start:end]) and loaded into a Python dictionary using json.loads().
    
    The subprocess module is now used with Popen instead of run. This change allows for more flexibility in handling the subprocess output.
    The universal_newlines=True parameter has been added to the Popen constructor. This allows the output to be captured as strings instead of bytes.
    The communicate() method is now used to capture the output of the subprocess, instead of stdout.decode('utf-8').
    Impact of changes
    
    The changes in devika.py appear to improve the handling of errors and Ctrl+C interruptions, making the program more robust.
    
    The changes in runner.py seem to improve the parsing of JSON data from responses and the handling of subprocess output. No more Invalid Json from Llama 3 due to text outside Json Blocks. (ex.  Here is the formatted Json Block { ... })
    
    The use of Popen instead of run allows for more flexibility in handling the output, and the universal_newlines=True parameter makes it easier to work with string output. This allows the user to view the Error in UI Terminal before devika starts prompting for fixes.
    hassamc committed Apr 22, 2024
    Configuration menu
    Copy the full SHA
    26c7351 View commit details
    Browse the repository at this point in the history