-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
refactor: refactored how tools are loaded, to enable loading external tools #313
Conversation
There was a problem hiding this 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 4ac38d0 in 1 minute and 1 seconds
More details
- Looked at
199
lines of code in3
files - Skipped
0
files when reviewing. - Skipped posting
3
drafted comments based on config settings.
1. gptme/tools/base.py:507
- Draft comment:
Uselogger
instead ofprint
for logging.
logger.info(f"Loaded tools {tools_new} from {path}")
- Reason this comment was not posted:
Confidence changes required:50%
Theload_from_file
function usesprint
for logging, which is not a best practice. It should use thelogger
for consistency and better control over logging levels.
2. gptme/tools/__init__.py:75
- Draft comment:
Redundant check fortool in loaded_tools
. This check is already performed after checking availability, so it can be removed here. - Reason this comment was not posted:
Confidence changes required:50%
Theinit_tools
function ingptme/tools/__init__.py
has a redundant check fortool in loaded_tools
. This check is performed twice, once before checking availability and once after. The first check can be removed.
3. gptme/tools/base.py:184
- Draft comment:
Theget_tool
method is not used in the provided code. Consider removing it if it's not used elsewhere in the codebase. - Reason this comment was not posted:
Confidence changes required:50%
Theget_tool
method inToolSpec
class is not used anywhere in the provided code. It might be unnecessary unless used elsewhere in the codebase.
Workflow ID: wflow_78BrJLpDAG7VQpCF
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## master #313 +/- ##
==========================================
- Coverage 73.75% 73.56% -0.19%
==========================================
Files 68 68
Lines 4949 4975 +26
==========================================
+ Hits 3650 3660 +10
- Misses 1299 1315 +16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
4ac38d0
to
7969910
Compare
There was a problem hiding this 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 7969910 in 33 seconds
More details
- Looked at
187
lines of code in3
files - Skipped
0
files when reviewing. - Skipped posting
3
drafted comments based on config settings.
1. gptme/tools/base.py:147
- Draft comment:
Using a global variable_tools
for tool registration can lead to potential issues in larger applications, such as unexpected side effects or difficulties in testing. Consider encapsulating this within a class or using a more controlled registry pattern. - Reason this comment was not posted:
Confidence changes required:50%
The use of a global variable for tool registration can lead to potential issues in larger applications, such as unexpected side effects or difficulties in testing. A more encapsulated approach would be beneficial.
2. gptme/tools/base.py:507
- Draft comment:
Uselogger
instead ofprint
for logging to maintain consistent logging practices. - Reason this comment was not posted:
Confidence changes required:50%
Theload_from_file
function usesprint
for logging, which is not ideal for production code. It should use thelogger
for consistent logging practices.
3. gptme/tools/base.py:503
- Draft comment:
Consider adding error handling for the dynamic import inload_from_file
to handle potential import errors gracefully. - Reason this comment was not posted:
Confidence changes required:50%
Theload_from_file
function should handle potential import errors gracefully, especially when dealing with dynamic imports from external files.
Workflow ID: wflow_X5r8xJlJ2mA7P9Tp
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
7969910
to
803c1a8
Compare
There was a problem hiding this 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 803c1a8 in 26 seconds
More details
- Looked at
228
lines of code in5
files - Skipped
0
files when reviewing. - Skipped posting
3
drafted comments based on config settings.
1. gptme/tools/base.py:507
- Draft comment:
Consider usinglogger.info
instead ofprint
for better logging practices.
logger.info(f"Loaded tools {tools_new} from {path}")
- Reason this comment was not posted:
Confidence changes required:50%
Theload_from_file
function inbase.py
usesprint
to output loaded tools, which is not ideal for production code. It should use logging instead.
2. gptme/tools/base.py:502
- Draft comment:
Consider removing the script directory fromsys.path
after importing to avoid potential import issues.
sys.path.remove(str(script_dir))
- Reason this comment was not posted:
Confidence changes required:50%
Theload_from_file
function inbase.py
appends the script directory tosys.path
without removing it later. This could lead to potential issues with module imports elsewhere in the application.
3. gptme/logmanager.py:258
- Draft comment:
Ensure that thelock
parameter is handled correctly to avoid potential issues in multi-threaded environments. Consider documenting the implications of settinglock=False
. - Reason this comment was not posted:
Confidence changes required:50%
Theload
method inLogManager
class inlogmanager.py
has a potential issue with thelock
parameter. The default value isTrue
, but it might be better to explicitly handle cases where locking is not desired, especially in multi-threaded environments.
Workflow ID: wflow_SBckJGMXXoILpJ2L
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
803c1a8
to
c75c4bb
Compare
There was a problem hiding this 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 c75c4bb in 31 seconds
More details
- Looked at
246
lines of code in5
files - Skipped
0
files when reviewing. - Skipped posting
4
drafted comments based on config settings.
1. gptme/tools/base.py:507
- Draft comment:
Consider usinglogger.info
instead ofprint
for logging loaded tools.
logger.info(f"Loaded tools {tools_new} from {path}")
- Reason this comment was not posted:
Confidence changes required:50%
The PR introduces a new methodload_from_file
inbase.py
to load tools from external Python files. However, the method usesprint
to output loaded tools, which is not ideal for production code. It would be better to use logging for such messages.
2. gptme/tools/base.py:508
- Draft comment:
Consider using a loop instead of a list comprehension with assignment for clarity.
new_tools = []
for tool_name in tools_new:
tool = ToolSpec.get_tool(tool_name)
if tool:
new_tools.append(tool)
return new_tools
- Reason this comment was not posted:
Confidence changes required:50%
Theload_from_file
function inbase.py
returns a list ofToolSpec
objects, but it uses a list comprehension with an assignment inside, which is not a common practice and can be confusing. It would be clearer to use a loop instead.
3. gptme/tools/__init__.py:79
- Draft comment:
Simplify the sorting of tools by using a key function directly.
sorted(ToolSpec.get_tools().values(), key=lambda tool: tool.name == "python")
- Reason this comment was not posted:
Confidence changes required:50%
Theinit_tools
function intools/__init__.py
uses a lambda function to sort tools, which can be simplified by using a key function directly. This improves readability.
4. gptme/logmanager.py:258
- Draft comment:
Ensure that thelock
parameter is handled correctly whenlock
isFalse
to avoid unexpected behavior if the lock file is already locked by another process. - Reason this comment was not posted:
Confidence changes required:50%
Theload
method inLogManager
class inlogmanager.py
has been updated to include alock
parameter. However, the method does not handle the case wherelock
isFalse
and the lock file is already locked by another process. This could lead to unexpected behavior.
Workflow ID: wflow_X4gIltXiekCqoqnb
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
Important
Refactor tool loading to support external tools with a dynamic registry and add functionality to load tools from external Python files.
ToolSpec.get_tools()
instead ofall_tools
list incli.py
andtools/__init__.py
.load_from_file()
inbase.py
to load tools from external Python files.get_tool()
andget_tools()
class methods inbase.py
for tool registry management.__post_init__()
to register tools in a global_tools
dictionary.init_tools()
intools/__init__.py
to useToolSpec.get_tools()
.python_tool
is initialized last by sorting tools ininit_tools()
.tool_append
from imports intools/__init__.py
.base.py
for clarity.lock
parameter toLogManager.load()
inlogmanager.py
.This description was created by
for c75c4bb. It will automatically update as commits are pushed.