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

feat: migrate readline to prompt_toolkit, with many features and fixes #244

Merged
merged 11 commits into from
Dec 15, 2024

Conversation

ErikBjare
Copy link
Owner

@ErikBjare ErikBjare commented Nov 1, 2024

Fixes #243


Important

Migrates input handling from readline to prompt_toolkit, enhancing completion, history, and multi-line input features, and fixes existing issues.

  • Behavior:
    • Migrates input handling from readline to prompt_toolkit in chat.py and cli.py.
    • Implements fish-style completion and file path highlighting in prompt_input() in chat.py.
    • Adds multi-line input support and pasting functionality.
    • Fixes prompt coloring and history functionality.
    • Addresses issue Confirmation prompt sometimes disappears #334 by switching to prompt_toolkit.
  • Features:
    • Adds GptmeCompleter in prompt.py for command, path, and LLM suggestions.
    • Introduces create_prompt_session() and get_input() in prompt.py for session management and input retrieval.
    • Adds get_pt_history_file() in dirs.py for managing prompt_toolkit history files.
  • Misc:
    • Removes readline.py and related imports.
    • Updates PROMPT_USER in constants.py to remove non-printable character markers.
    • Minor changes in ask_execute.py to use create_prompt_session() for user prompts.

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

@codecov-commenter
Copy link

codecov-commenter commented Nov 1, 2024

Codecov Report

Attention: Patch coverage is 64.51613% with 77 lines in your changes missing coverage. Please review.

Project coverage is 72.01%. Comparing base (d598ff3) to head (c46bc28).
Report is 2 commits behind head on master.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
gptme/util/prompt.py 64.17% 72 Missing ⚠️
gptme/message.py 33.33% 4 Missing ⚠️
gptme/util/ask_execute.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #244      +/-   ##
==========================================
- Coverage   72.77%   72.01%   -0.77%     
==========================================
  Files          67       67              
  Lines        4951     5138     +187     
==========================================
+ Hits         3603     3700      +97     
- Misses       1348     1438      +90     
Flag Coverage Δ
anthropic/claude-3-haiku-20240307 70.22% <64.51%> (-0.52%) ⬇️
openai/gpt-4o-mini 68.91% <64.51%> (-0.67%) ⬇️

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.

- Add better path completion with syntax highlighting
- Add command completion
- Add LLM suggestions support
- Improve history handling
- Remove readline dependency
@ErikBjare ErikBjare marked this pull request as ready for review December 15, 2024 12:18
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 b36e785 in 50 seconds

More details
  • Looked at 501 lines of code in 8 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. gptme/chat.py:278
  • Draft comment:
    LLM suggestions are not implemented yet as enabled is set to False. This is a planned feature according to the PR description.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The get_suggestions function is currently not implemented, as indicated by the enabled flag being set to False. This means LLM suggestions are not functional yet, which is a planned feature according to the PR description.
2. gptme/dirs.py:13
  • Draft comment:
    get_readline_history_file is unused and can be removed after migrating to prompt_toolkit.
  • Reason this comment was not posted:
    Comment was not on a valid diff hunk.

Workflow ID: wflow_nqBXPEs5HizUO3Qi


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 d70449e in 9 seconds

More details
  • Looked at 37 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 drafted comments based on config settings.

Workflow ID: wflow_ZuwclAysSAGSKdT7


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 026123c in 49 seconds

More details
  • Looked at 630 lines of code in 7 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. gptme/chat.py:272
  • Draft comment:
    The get_suggestions function is removed, but its functionality is not replaced or refactored elsewhere. This might lead to missing LLM suggestions, which is a feature mentioned in the PR description.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The comment is speculative because it assumes the removal of get_suggestions is problematic without evidence from the code changes. The rules state to avoid speculative comments and to only comment if there is a definite issue. Since the diff does not show any evidence that the removal causes a problem, the comment should likely be removed.
    I might be missing the context of the PR description, which could provide more information about the necessity of the get_suggestions feature. However, the rules specify to focus on the code changes and not external context.
    Even if the PR description mentions the feature, the code changes themselves do not show evidence of an issue caused by the removal, so the comment remains speculative.
    The comment should be deleted because it is speculative and lacks strong evidence from the code changes that the removal of get_suggestions is an issue.
2. gptme/message.py:20
  • Draft comment:
    The rich_to_str function is moved to gptme/util/prompt.py, but the import statement here is not updated. This will lead to an import error.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
3. gptme/util/ask_execute.py:18
  • Draft comment:
    The create_prompt_session function is removed, but its usage here is not updated to use get_prompt_session. This will lead to a function not found error.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
4. gptme/util/ask_execute.py:108
  • Draft comment:
    The create_prompt_session function is removed, but its usage here is not updated to use get_prompt_session. This will lead to a function not found error.
  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_XI52u9A0oIaH4AGY


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 51c2c62 in 1 minute and 28 seconds

More details
  • Looked at 630 lines of code in 7 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. gptme/chat.py:272
  • Draft comment:
    The get_suggestions function is removed, but its functionality is not replaced or refactored elsewhere. This could lead to missing functionality if it was used elsewhere in the codebase.
  • Reason this comment was not posted:
    Comment did not seem useful.
2. gptme/message.py:19
  • Draft comment:
    The rich_to_str function is moved from gptme/util/__init__.py to gptme/util/prompt.py, but the import in gptme/message.py is not updated. This will cause an import error.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
3. gptme/util/ask_execute.py:18
  • Draft comment:
    The create_prompt_session function is renamed to get_prompt_session, but the import in gptme/util/ask_execute.py is not updated. This will cause an import error.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
4. gptme/util/prompt.py:387
  • Draft comment:
    The get_suggestions function is removed, but its functionality is not replaced or refactored elsewhere. This could lead to missing functionality if it was used elsewhere in the codebase.
  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_DcPpFv6Qp7a72idl


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.

❌ Changes requested. Incremental review on fc0ec3f in 30 seconds

More details
  • Looked at 32 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 drafted comments based on config settings.

Workflow ID: wflow_CaQFNkiLqMQ2ijCA


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

gptme/util/prompt.py Outdated Show resolved Hide resolved
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 e2f11e5 in 27 seconds

More details
  • Looked at 220 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. gptme/util/prompt.py:144
  • Draft comment:
                    logger.debug(f"File exists in current directory: {path_str}")
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The comment suggests a change that directly contradicts the code change made in the diff. The author likely had a reason for changing the log level from debug to warning, possibly to highlight the importance of the log message. Without strong evidence that this change is incorrect, the comment should be removed.
    I might be missing the context of why the log level was changed, but the comment does not provide any justification for reverting it. The author might have intended to make the log message more prominent.
    The lack of justification in the comment for reverting the log level change suggests that it is not a strong comment. The author likely had a reason for the change, and without evidence to the contrary, the comment should be removed.
    Remove the comment as it suggests reverting a deliberate code change without justification.

Workflow ID: wflow_Rg54OmUlSw7wMMrw


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 d4ae5dc in 14 seconds

More details
  • Looked at 13 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. gptme/util/prompt.py:399
  • Draft comment:
    The condition was corrected to check if the parent directory does not exist before creating it. This is a necessary fix to ensure the directory is created when it doesn't exist.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The condition in the get_prompt_session function was incorrectly checking if the parent directory exists before creating it. The fix in the PR correctly changes the condition to check if the parent directory does not exist before creating it.

Workflow ID: wflow_yN337Q87YXWA3Kla


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 f9b4fb6 in 14 seconds

More details
  • Looked at 12 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. tests/test_prompt.py:117
  • Draft comment:
    Consider automating the check_cwd() call to ensure the current working directory is always validated. The current comment is not actionable.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The comment suggests automating the check_cwd() call, which is a good idea for ensuring the current working directory is always checked. However, the comment itself is not actionable and should be removed or replaced with a more specific implementation note.

Workflow ID: wflow_kSfQhhQmhikom59i


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 77f9978 in 13 seconds

More details
  • Looked at 24 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. gptme/prompts.py:247
  • Draft comment:
    The change from datetime.utcnow() to datetime.now(timezone.utc) is a good practice for timezone-aware datetime objects. This ensures that the datetime object is aware of its timezone, which can prevent potential bugs related to naive datetime objects.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The change from datetime.utcnow() to datetime.now(timezone.utc) is correct and aligns with best practices for timezone-aware datetime objects.

Workflow ID: wflow_P1wU6w0o8LdxNDKy


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 c46bc28 in 12 seconds

More details
  • Looked at 15 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 drafted comments based on config settings.

Workflow ID: wflow_Zh89Gv9mX5bQeOqN


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

@ErikBjare ErikBjare changed the title feat: migrate from readline to prompt_toolkit, with new features planned feat: migrate readline to prompt_toolkit, with many features and fixes Dec 15, 2024
@ErikBjare ErikBjare merged commit 61ca0a2 into master Dec 15, 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.

Adopt prompt_toolkit
2 participants