gptme icon indicating copy to clipboard operation
gptme copied to clipboard

refactor: attempt to refactor & simplify chat.py

Open ErikBjare opened this issue 8 months ago • 2 comments

Mostly vibecoding. Some things are broken but some good ideas here too.


[!IMPORTANT] Refactor chat.py for improved readability, introduce paths.py for path handling, and enhance interrupt handling in interrupt.py.

  • Refactor chat.py:
    • Split chat() into smaller functions: _init_chat(), _process_prompt(), _handle_non_interactive_exit(), etc.
    • Introduced _init_terminal(), _init_model(), _init_log_manager(), _init_tool_format(), _init_and_setup_workspace(), _print_log() for initialization tasks.
    • Added _prepare_message(), _is_executable_command(), _get_response_messages(), _process_response_messages() for message processing.
    • Improved interrupt handling with Interruptible context manager.
  • New paths.py module:
    • Added find_potential_paths(), is_url(), resolve_path(), read_text_file(), process_url() for path and URL handling.
  • Interrupt handling in interrupt.py:
    • Replaced interruptible with _interruptible_state.
    • Added Interruptible context manager for consistent interrupt handling.
  • Makefile:
    • Added clean-pyc target to remove .pyc files and __pycache__ directories.

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

ErikBjare avatar Feb 19 '25 20:02 ErikBjare

:x: 1 Tests Failed:

Tests completed Failed Passed Skipped
171 1 170 3
View the top 1 failed test(s) by shortest run time
tests.test_browser::test_search_ddg
Stack Traces | 6.62s run time
@pytest.mark.slow
    def test_search_ddg():
        results = search("test", "duckduckgo")
>       assert "1." in results, f"{results=}"
E       AssertionError: results='Error: something went wrong with the search.'
E       assert '1.' in 'Error: something went wrong with the search.'

tests/test_browser.py:14: AssertionError

To view more test analytics, go to the Test Analytics Dashboard 📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

codecov-commenter avatar Feb 19 '25 20:02 codecov-commenter

Looks like I created a bunch of conflicts in https://github.com/ErikBjare/gptme/pull/454

ErikBjare avatar Feb 28 '25 09:02 ErikBjare

This handles GitHub URLs specially which is something we want, but this has diverged significantly from master and would be difficult to resolve the conflicts.

Ellipsis has also highlighted some changes we made which might be good ideas. Splitting up the chat function which is one of the most complex in the codebase and has some quirks would be nice.

ErikBjare avatar Jun 04 '25 11:06 ErikBjare