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: implement gptme-util CLI for utilities #261

Merged
merged 13 commits into from
Nov 17, 2024
Merged

Conversation

ErikBjare
Copy link
Owner

@ErikBjare ErikBjare commented Nov 17, 2024

Fixes #260

  • Added tools list and info commands
  • Added language tag support
  • Reused existing code from commands.py
  • Added initial tests for utility CLI
  • Moved util.py to util/init.py for better organization

Built by Bob (#259)


Important

Introduces a new CLI for utility commands with language tag support and reorganizes utility code structure.

  • CLI Enhancements:
    • Added tools list and tools info commands in util/cli.py.
    • Added language tag support in tools_list().
  • Code Reuse:
    • Reused existing code from commands.py for tool-related functionalities.
  • Testing:
    • Added initial tests for CLI commands in test_util_cli.py.
  • Code Organization:
    • Moved util.py to util/__init__.py for better organization.

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

- Added tools list and info commands
- Added language tag support
- Reused existing code from commands.py
- Added initial tests for utility CLI
- Moved util.py to util/__init__.py for better organization
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. Reviewed everything up to 3a2573d in 48 seconds

More details
  • Looked at 246 lines of code in 4 files
  • Skipped 0 files when reviewing.
  • Skipped posting 6 drafted comments based on config settings.
1. gptme.toml:1
  • Draft comment:
    The addition of gptme/chat.py to the files list seems unrelated to the PR's purpose. Ensure this change is intentional and necessary.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The PR adds a new file gptme/chat.py to the files list in gptme.toml. This change is not explained in the PR description or related to the issue being fixed. It might be an oversight or unrelated change.
2. gptme/util/__init__.py:24
  • Draft comment:
    The import statement should be corrected to import from gptme.clipboard instead of ..clipboard.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The change in the import statement from '.clipboard' to '..clipboard' is due to the file being moved from 'gptme/util.py' to 'gptme/util/init.py'. The relative import '..clipboard' is correct because it refers to the clipboard module in the parent directory of the current package. The comment suggesting an absolute import is not necessary unless there is a specific reason to prefer absolute imports, which is not mentioned in the comment.
    I might be missing some context about the project's import style guidelines, which could prefer absolute imports. However, without explicit evidence or guidelines, the relative import seems correct given the file structure change.
    The comment does not provide any evidence or reasoning for preferring an absolute import, and the relative import appears correct given the file's new location.
    The comment should be deleted because the relative import '..clipboard' is correct given the file's new location, and there is no strong evidence to support the suggested change to an absolute import.
3. gptme/util/cli.py:28
  • Draft comment:
    Consider handling the case where get_user_conversations() returns an empty list to improve user experience.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The chats_list function in gptme/util/cli.py does not handle the case where get_user_conversations() returns an empty list. This could lead to a confusing user experience if no chats are available.
4. gptme/util/cli.py:81
  • Draft comment:
    Consider adding validation for the model parameter to ensure it is valid before calling tiktoken.encoding_for_model(model).
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The tokens_count function in gptme/util/cli.py uses tiktoken.encoding_for_model(model) without checking if the model is valid. This could lead to runtime errors if an invalid model is provided.
5. gptme/util/cli.py:135
  • Draft comment:
    Consider simplifying the multi-line f-string for printing tool information to improve readability.
  • Reason this comment was not posted:
    Confidence changes required: 30%
    The tools_list function in gptme/util/cli.py uses a multi-line f-string for printing tool information. This can be simplified to improve readability.
6. tests/test_util_cli.py:20
  • Draft comment:
    Consider adding assertions to verify the output of the chats_list command to ensure it behaves as expected.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The test for chats_list in tests/test_util_cli.py does not verify the output, which could lead to false positives if the command does not behave as expected.

Workflow ID: wflow_vUFfDJZhLEPkTArB


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.


@chats.command("ls")
@click.option("-n", "--limit", default=20, help="Maximum number of chats to show.")
def chats_list(limit: int):
Copy link
Contributor

Choose a reason for hiding this comment

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

The chats_list function duplicates the functionality of list_chats in gptme/tools/chats.py. Consider using or extending list_chats instead.

Copy link
Owner Author

Choose a reason for hiding this comment

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

This is good feedback

@codecov-commenter
Copy link

codecov-commenter commented Nov 17, 2024

Codecov Report

Attention: Patch coverage is 77.63158% with 34 lines in your changes missing coverage. Please review.

Project coverage is 72.45%. Comparing base (e4ce6c8) to head (7edb198).

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
gptme/util/cli.py 85.84% 15 Missing ⚠️
gptme/tools/chats.py 47.61% 11 Missing ⚠️
gptme/message.py 22.22% 7 Missing ⚠️
gptme/logmanager.py 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #261      +/-   ##
==========================================
+ Coverage   70.66%   72.45%   +1.78%     
==========================================
  Files          61       62       +1     
  Lines        3958     4055      +97     
==========================================
+ Hits         2797     2938     +141     
+ Misses       1161     1117      -44     
Flag Coverage Δ
anthropic/claude-3-haiku-20240307 71.46% <77.63%> (+0.80%) ⬆️
openai/gpt-4o-mini 71.36% <77.63%> (?)

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.

gptme.toml Outdated
@@ -1,2 +1,2 @@
files = ["README.md", "Makefile"]
files = ["README.md", "Makefile", "gptme/chat.py"]
Copy link
Owner Author

Choose a reason for hiding this comment

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

mistakenly committed

- Added empty list handling in chats_list
- Added model validation in tokens_count
- Added comprehensive test cases
- Skip context test until module is available
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 2af94f8 in 26 seconds

More details
  • Looked at 150 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. gptme/util/cli.py:82
  • Draft comment:
    The tokens_count function should return a non-zero exit code when no text is provided. This is a common practice for CLI tools to signal errors.
  • Reason this comment was not posted:
    Marked as duplicate.
2. tests/test_util_cli.py:82
  • Draft comment:
    The tokens_count function should return a non-zero exit code when no text is provided. This is a common practice for CLI tools to signal errors.
  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_hHX0Fk5mw1cXSd38


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.

tests/test_util_cli.py Outdated Show resolved Hide resolved
- Import _ModelDictMeta from models.py instead of duplicating definition
- Fixes code duplication identified by pylint
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 d73de53 in 9 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/llm_openai_models.py:1
  • Draft comment:
    Ensure that the module .models exists and contains _ModelDictMeta. This change could lead to an import error if .models is not correctly set up.
  • Reason this comment was not posted:
    Comment did not seem useful.

Workflow ID: wflow_sDmcfNNKrgPp3eZ9


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 f9e4aee in 18 seconds

More details
  • Looked at 75 lines of code in 3 files
  • Skipped 1 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. gptme/util/cli.py:28
  • Draft comment:
    The import statement for format_conversation is unnecessary here since it's already imported in list_conversations. Consider removing it.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The import statement for 'format_conversation' in 'cli.py' is unnecessary since it's already imported in 'list_conversations'.
2. gptme/util/cli.py:32
  • Draft comment:
    Consider using click.echo instead of print for consistent CLI output handling. This applies to other print statements in this file as well.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The print function is used in cli.py for output, which is not ideal for CLI applications. It's better to use click.echo for consistent output handling.

Workflow ID: wflow_JguIMLZhjgHNS8cG


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 cd8ef84 in 18 seconds

More details
  • Looked at 92 lines of code in 3 files
  • Skipped 1 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. gptme/logmanager.py:12
  • Draft comment:
    The import of Callable from collections.abc is unnecessary as it is already imported from typing. Consider removing it to avoid redundancy.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The import of 'Callable' from 'collections.abc' is unnecessary as it is already imported from 'typing'.
2. gptme/logmanager.py:379
  • Draft comment:
    The found boolean flag is unnecessary. You can check if conversations is empty instead of using found. This applies to the usage in cli.py as well.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The PR introduces a new function list_conversations which is used in cli.py. The function returns a tuple with a boolean flag found which is unnecessary since the list itself can be checked for emptiness.
3. gptme/util/cli.py:27
  • Draft comment:
    The logic for printing language tags in tools_list can be simplified. Instead of checking for specific line prefixes, consider using a more direct approach to extract and print the language tags.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The PR adds a new CLI command tools list with an option --langtags. The logic for printing language tags is a bit convoluted and can be simplified.
4. gptme/util/cli.py:29
  • Draft comment:
    The found flag returned by list_conversations is unnecessary. You can check if conversations is empty instead of using found.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The PR adds a new CLI command chats ls which uses list_conversations. The found flag is unnecessary and can be removed.

Workflow ID: wflow_zwsJ5pATPUagROLi


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 6cca401 in 10 seconds

More details
  • Looked at 17 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. gptme/llm_openai_models.py:4
  • Draft comment:
    Remove the unnecessary comment # fmt: skip as it doesn't add value here.
  • Reason this comment was not posted:
    Confidence changes required: 33%
    The use of TYPE_CHECKING and the import statement inside the if block is correct for avoiding circular imports during runtime. However, the comment about formatting is unnecessary and should be removed for cleaner code.

Workflow ID: wflow_3XOaanDeQ1QG1EB3


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

@ErikBjare ErikBjare changed the title feat(gptme-util): implement tools subcommands feat: implement gptme-util CLI with util subcommands Nov 17, 2024
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 ede4361 in 16 seconds

More details
  • Looked at 29 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. gptme/util/__init__.py:326
  • Draft comment:
    Consider moving the import statements for len_tokens and init_tools to the top of the file to improve readability and maintainability.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The imports are intentionally placed within the function, likely for a reason such as avoiding circular dependencies or reducing initial load time. The # fmt: skip and # noreorder comments suggest that the current placement is deliberate. The suggestion to move them for readability does not consider these factors and may not be appropriate.
    I might be missing the context of why the imports are placed there, but the presence of # fmt: skip and # noreorder strongly suggests intentional placement. The comment does not provide a compelling reason to change this.
    The presence of # fmt: skip and # noreorder is strong evidence that the current placement is intentional and necessary. The comment does not account for this, making it less valid.
    The comment should be deleted because the import placement is intentional, as indicated by # fmt: skip and # noreorder, and the suggestion does not consider this.

Workflow ID: wflow_iORmOwnk83yzDPmE


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 d92f291 in 8 seconds

More details
  • Looked at 26 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. docs/cli.rst:25
  • Draft comment:
    Add a title for the gptme-util command section to maintain consistency and improve readability.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The CLI reference section in the documentation is missing a title for the new gptme-util command. This could lead to confusion for users looking for information about the new CLI command.

Workflow ID: wflow_LLMCahDfF0gbuLJb


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

gptme.toml Outdated Show resolved Hide resolved
@ErikBjare ErikBjare changed the title feat: implement gptme-util CLI with util subcommands feat: implement gptme-util CLI for utilities Nov 17, 2024
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 66ea9f8 in 25 seconds

More details
  • Looked at 444 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. gptme/util/cli.py:147
  • Draft comment:
    Simplify the multi-line string for printing tool information.
            print(f"{status} {tool.name}\n   {tool.desc}")
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The tools_list function uses a multi-line string for printing tool information, which is unnecessary and can be simplified.
2. gptme/util/cli.py:150
  • Draft comment:
    Simplify the multi-line string for printing tool information.
            print(f"{status} {tool.name}\n   {tool.desc}")
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The tools_list function uses a multi-line string for printing tool information, which is unnecessary and can be simplified.

Workflow ID: wflow_vH04JsMMhaKNuHPH


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.


@context.command("generate")
@click.argument("path", type=click.Path(exists=True))
def context_generate(_path: str):
Copy link
Contributor

Choose a reason for hiding this comment

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

context_generate is a placeholder and does not perform any operations. Implement the function or remove it if not needed.

ErikBjare and others added 2 commits November 17, 2024 15:36
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
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 d060108 in 12 seconds

More details
  • Looked at 34 lines of code in 2 files
  • Skipped 1 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. pyproject.toml:62
  • Draft comment:
    The specific version constraint for pylint was removed and replaced with pylint = "*". Ensure this is intentional, as it may lead to using the latest version, which could introduce breaking changes.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The Makefile has a redundant line for pylint in the pyproject.toml file. The line pylint = "^3.3.1" was removed, but the new line pylint = "*" was added under [tool.poetry.group.dev.dependencies]. This change is correct as it moves pylint to the dev dependencies, but the removal of the specific version constraint should be noted.

Workflow ID: wflow_xWceDMrEGtpKXBJx


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 1aa576a in 21 seconds

More details
  • Looked at 114 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 drafted comments based on config settings.
1. gptme/util/cli.py:40
  • Draft comment:
    Consider renaming max_results to limit in the list_chats function to maintain consistency with the list_conversations function in gptme/logmanager.py.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The list_chats function in gptme/util/cli.py uses max_results as a parameter, but the list_conversations function in gptme/logmanager.py uses limit. This inconsistency can lead to confusion and potential bugs.
2. gptme/util/cli.py:35
  • Draft comment:
    Consider moving the model initialization outside the chats_list function to improve performance by avoiding repeated initialization.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The chats_list function in gptme/util/cli.py initializes the model for summarization inside the function, which is not ideal for performance. It should be initialized outside the function to avoid repeated initialization.
3. gptme/tools/chats.py:49
  • Draft comment:
    Ensure that the metadata parameter is explicitly passed to the conv.format() call to avoid unexpected behavior if the default value changes.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The list_chats function in gptme/tools/chats.py uses metadata=True in the conv.format() call, but the metadata parameter is not passed to the function. This can lead to unexpected behavior if the default value of metadata changes.

Workflow ID: wflow_5ysNG7JdMqQvsxFg


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 4ad31b2 in 25 seconds

More details
  • Looked at 128 lines of code in 3 files
  • Skipped 1 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. gptme/util/cli.py:170
  • Draft comment:
    Using sys.exit(1) directly can make testing and integration more difficult. Consider returning an exit code from the function and letting the CLI framework handle it.
  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_DFSZx0H1GjBUID7b


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/cli.py 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 7edb198 in 20 seconds

More details
  • Looked at 128 lines of code in 3 files
  • Skipped 1 files when reviewing.
  • Skipped posting 3 drafted comments based on config settings.
1. gptme/util/cli.py:92
  • Draft comment:
    Using sys.exit(1) is appropriate here to indicate an error state in a CLI application. Ensure this is consistent across similar functions.
  • Reason this comment was not posted:
    Confidence changes required: 10%
    The use of sys.exit(1) is appropriate for CLI applications to indicate an error, but it should be consistent across the codebase. The change from return to sys.exit(1) in tokens_count and tools_info functions is correct for indicating an error state.
2. gptme/util/cli.py:170
  • Draft comment:
    Using sys.exit(1) is appropriate here to indicate an error state in a CLI application. Ensure this is consistent across similar functions.
  • Reason this comment was not posted:
    Confidence changes required: 10%
    The use of sys.exit(1) is appropriate for CLI applications to indicate an error, but it should be consistent across the codebase. The change from return to sys.exit(1) in tokens_count and tools_info functions is correct for indicating an error state.
3. tests/test_util_cli.py:32
  • Draft comment:
    Ensure the exit code is exactly 1 for an invalid tool to indicate an error state.
    assert result.exit_code == 1  # returns 1 for not found tool
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The test for tools info command correctly checks for both valid and invalid tool names. However, the test for invalid tool should ensure that the exit code is exactly 1, which is the standard for indicating an error.

Workflow ID: wflow_acPqoz1UC1FUyrck


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

@ErikBjare ErikBjare merged commit 128676c into master Nov 17, 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.

Create gptme-util CLI command
2 participants