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

fix: stream and capture ipython output #357

Merged
merged 3 commits into from
Dec 20, 2024

Conversation

ErikBjare
Copy link
Owner

@ErikBjare ErikBjare commented Dec 20, 2024

Was needed to make the browser tool able to update the user on progress via logging/console messages. (noticed when fixing #358)


Important

Enhance IPython output handling in gptme/tools/python.py by replacing InteractiveShellEmbed with InteractiveShell and adding real-time output streaming.

  • IPython Handling:
    • Replace InteractiveShellEmbed with InteractiveShell for IPython instance.
    • Modify _get_ipython() to use InteractiveShell.
  • Output Streaming:
    • Add TeeIO class to manage output streaming and filter IPython result prompts.
    • Introduce capture_and_display() context manager to capture and display stdout and stderr in real-time.
  • Function Updates:
    • Update execute_python() to use capture_and_display() for real-time output capture and display.

This description was created by Ellipsis for 5f90e04. It will automatically update as commits are pushed.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Reviewed everything up to 5dd00ed in 1 minute and 9 seconds

More details
  • Looked at 73 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 drafted comments based on config settings.
1. gptme/tools/python.py:92
  • Draft comment:
    Consider using a thread-safe alternative to io.StringIO for TeeIO to avoid potential issues with multi-threaded code execution.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The TeeIO class is designed to capture and display output in real-time, but it inherits from io.StringIO, which is not thread-safe. This could lead to issues if the code execution involves multi-threading.
2. gptme/tools/python.py:102
  • Draft comment:
    Replacing sys.stdout and sys.stderr can interfere with other parts of the program. Consider using a more isolated approach to capture output.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The capture_and_display function replaces sys.stdout and sys.stderr with TeeIO instances. This could interfere with other parts of the program that rely on standard output and error streams.
3. gptme/tools/python.py:135
  • Draft comment:
    Ensure result.error_in_exec is not None before accessing its __traceback__ attribute to avoid potential AttributeError.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The execute_python function uses result.error_in_exec to check for execution errors, but it doesn't handle the case where result.error_in_exec might be None. This could lead to an AttributeError if result.error_in_exec is None.

Workflow ID: wflow_E5A9uUkFgeMUftu9


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@codecov-commenter
Copy link

codecov-commenter commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 97.67442% with 1 line in your changes missing coverage. Please review.

Project coverage is 71.23%. Comparing base (99912f3) to head (5f90e04).
Report is 3 commits behind head on master.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
gptme/tools/python.py 97.67% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #357      +/-   ##
==========================================
+ Coverage   71.07%   71.23%   +0.16%     
==========================================
  Files          68       68              
  Lines        5241     5271      +30     
==========================================
+ Hits         3725     3755      +30     
  Misses       1516     1516              
Flag Coverage Δ
anthropic/claude-3-haiku-20240307 69.47% <97.67%> (+0.15%) ⬆️
openai/gpt-4o-mini 68.05% <88.37%> (+0.35%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Incremental review on c6d96a7 in 36 seconds

More details
  • Looked at 115 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 drafted comments based on config settings.
1. gptme/tools/python.py:105
  • Draft comment:
    The import statement for ExecutionResult is unnecessary as it is not used in the function. Consider removing it to clean up the code.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The import statement for ExecutionResult is not used in the function, which is unnecessary and should be removed.
2. gptme/tools/python.py:66
  • Draft comment:
    The TeeIO class is defined twice in the code. Please remove the redundant definition to avoid confusion and maintain code clarity.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
3. gptme/tools/python.py:86
  • Draft comment:
    The capture_and_display function is defined twice in the code. Please remove the redundant definition to avoid confusion and maintain code clarity.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.

Workflow ID: wflow_GylMwy83YbWl0WdA


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Incremental review on 5f90e04 in 15 seconds

More details
  • Looked at 19 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. gptme/tools/python.py:153
  • Draft comment:
    Good use of checking if tb: before accessing tb.tb_lineno to prevent potential AttributeError. This change makes the code more robust.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The code correctly handles the traceback by checking if tb is not None before accessing tb.tb_lineno. This prevents potential AttributeError if tb is None. The change from the previous version ensures that the code is more robust.

Workflow ID: wflow_29pxl52ZzakhLaEY


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@ErikBjare ErikBjare merged commit ef424be into master Dec 20, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants