-
-
Notifications
You must be signed in to change notification settings - Fork 729
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: Refactor reasking logic #1071
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 d56bc5e in 27 seconds
More details
- Looked at
800
lines of code in3
files - Skipped
0
files when reviewing. - Skipped posting
10
drafted comments based on config settings.
1. instructor/reask.py:24
- Draft comment:
Unnecessary copying ofkwargs
. Consider modifyingkwargs
directly unless there's a specific reason to keep the original unchanged. This comment applies to other similar instances in this file. - Reason this comment was not posted:
Confidence changes required:50%
The code inreask.py
andretry.py
has several instances wherekwargs
is copied unnecessarily. This can lead to performance issues due to unnecessary memory usage.
2. instructor/reask.py:71
- Draft comment:
Unnecessary copying ofkwargs
. Consider modifyingkwargs
directly unless there's a specific reason to keep the original unchanged. This comment applies to other similar instances in this file. - Reason this comment was not posted:
Confidence changes required:50%
The code inreask.py
andretry.py
has several instances wherekwargs
is copied unnecessarily. This can lead to performance issues due to unnecessary memory usage.
3. instructor/reask.py:153
- Draft comment:
Unnecessary copying ofkwargs
. Consider modifyingkwargs
directly unless there's a specific reason to keep the original unchanged. This comment applies to other similar instances in this file. - Reason this comment was not posted:
Confidence changes required:50%
The code inreask.py
andretry.py
has several instances wherekwargs
is copied unnecessarily. This can lead to performance issues due to unnecessary memory usage.
4. instructor/reask.py:169
- Draft comment:
Unnecessary copying ofkwargs
. Consider modifyingkwargs
directly unless there's a specific reason to keep the original unchanged. This comment applies to other similar instances in this file. - Reason this comment was not posted:
Confidence changes required:50%
The code inreask.py
andretry.py
has several instances wherekwargs
is copied unnecessarily. This can lead to performance issues due to unnecessary memory usage.
5. instructor/reask.py:192
- Draft comment:
Unnecessary copying ofkwargs
. Consider modifyingkwargs
directly unless there's a specific reason to keep the original unchanged. This comment applies to other similar instances in this file. - Reason this comment was not posted:
Confidence changes required:50%
The code inreask.py
andretry.py
has several instances wherekwargs
is copied unnecessarily. This can lead to performance issues due to unnecessary memory usage.
6. instructor/reask.py:214
- Draft comment:
Unnecessary copying ofkwargs
. Consider modifyingkwargs
directly unless there's a specific reason to keep the original unchanged. This comment applies to other similar instances in this file. - Reason this comment was not posted:
Confidence changes required:50%
The code inreask.py
andretry.py
has several instances wherekwargs
is copied unnecessarily. This can lead to performance issues due to unnecessary memory usage.
7. instructor/reask.py:236
- Draft comment:
Unnecessary copying ofkwargs
. Consider modifyingkwargs
directly unless there's a specific reason to keep the original unchanged. This comment applies to other similar instances in this file. - Reason this comment was not posted:
Confidence changes required:50%
The code inreask.py
andretry.py
has several instances wherekwargs
is copied unnecessarily. This can lead to performance issues due to unnecessary memory usage.
8. instructor/reask.py:253
- Draft comment:
Unnecessary copying ofkwargs
. Consider modifyingkwargs
directly unless there's a specific reason to keep the original unchanged. This comment applies to other similar instances in this file. - Reason this comment was not posted:
Confidence changes required:50%
The code inreask.py
andretry.py
has several instances wherekwargs
is copied unnecessarily. This can lead to performance issues due to unnecessary memory usage.
9. instructor/reask.py:27
- Draft comment:
Assertions should always have an error message. Please provide a descriptive error message for this assertion.
assert isinstance(response, Message), "Response must be a valid Anthropic Message instance."
- Reason this comment was not posted:
Confidence changes required:80%
The code has multiple instances where assertions lack error messages. Assertions should always have a clear error message to aid in debugging.
10. instructor/reask.py:74
- Draft comment:
Assertions should always have an error message. Please provide a descriptive error message for this assertion.
assert isinstance(response, Message), "Response must be a valid Anthropic Message instance."
- Reason this comment was not posted:
Confidence changes required:80%
The code has multiple instances where assertions lack error messages. Assertions should always have a clear error message to aid in debugging.
Workflow ID: wflow_1PWK3csLQP2DGuCQ
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
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 15a5cb8 in 15 seconds
More details
- Looked at
60
lines of code in1
files - Skipped
0
files when reviewing. - Skipped posting
3
drafted comments based on config settings.
1. instructor/retry.py:99
- Draft comment:
Good use of Python 3.10+ syntax withtype[T_Model] | None
. Ensure this is consistent across the codebase. - Reason this comment was not posted:
Confidence changes required:20%
The change fromOptional[Type]
toType | None
is a good update for Python 3.10+ syntax, but it should be consistent across the file.
2. instructor/retry.py:178
- Draft comment:
Good use of Python 3.10+ syntax withtype[T_Model] | None
. Ensure this is consistent across the codebase. - Reason this comment was not posted:
Confidence changes required:20%
The change fromOptional[Type]
toType | None
is a good update for Python 3.10+ syntax, but it should be consistent across the file.
3. instructor/retry.py:97
- Draft comment:
Function namesretry_sync
andretry_async
should follow a consistent naming pattern, such asinitialize_retrying
andinitialize_usage
. Consider renaming them toinitialize_retry_sync
andinitialize_retry_async
. - Reason this comment was not posted:
Confidence changes required:80%
The function namesretry_sync
andretry_async
are not following a consistent naming pattern with other functions in the file, such asinitialize_retrying
andinitialize_usage
.
Workflow ID: wflow_MJAqbw421Q7boybS
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
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 1f3e3fe in 12 seconds
More details
- Looked at
15
lines of code in1
files - Skipped
0
files when reviewing. - Skipped posting
2
drafted comments based on config settings.
1. instructor/reask.py:88
- Draft comment:
Theattempt_number
parameter was moved to the end and given a default value. Ensure that this change does not affect any existing calls toreask_cohere_tools
that might have used positional arguments. - Reason this comment was not posted:
Confidence changes required:50%
Theattempt_number
parameter inreask_cohere_tools
is set to a default value of 1, which is a good practice for optional parameters. However, the placement of this parameter was changed, which might affect the function's usage if it was called with positional arguments.
2. instructor/reask.py:84
- Draft comment:
Function names should follow a consistent pattern. Consider renaming functions to maintain consistency, such asreask_<platform>_<type>
orreask_<platform>
. This applies to other functions in this file as well. - Reason this comment was not posted:
Confidence changes required:80%
The function names in this file are inconsistent. Some use the patternreask_<platform>_<type>
while others usereask_<platform>
. This inconsistency can lead to confusion.
Workflow ID: wflow_xr3WKTLZVoLC94HA
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
Deploying instructor-py with
|
Latest commit: |
28f7513
|
Status: | ✅ Deploy successful! |
Preview URL: | https://3e4407d0.instructor-py.pages.dev |
Branch Preview URL: | https://refactor-reask.instructor-py.pages.dev |
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 8f789a4 in 18 seconds
More details
- Looked at
68
lines of code in2
files - Skipped
0
files when reviewing. - Skipped posting
5
drafted comments based on config settings.
1. instructor/retry.py:102
- Draft comment:
The addition of thecontext
parameter is consistent with the refactoring goals. Ensure thatprocess_response
andprocess_response_async
handle this parameter correctly. - Reason this comment was not posted:
Confidence changes required:50%
The PR introduces a new parametercontext
in theretry_sync
andretry_async
functions, which is used in theprocess_response
andprocess_response_async
functions. This change aligns with the refactoring described in the PR description.
2. instructor/retry.py:155
- Draft comment:
Ensurehandle_reask_kwargs
is correctly handling the newcontext
parameter if applicable. This is crucial for the refactored reasking logic. - Reason this comment was not posted:
Confidence changes required:50%
Thehandle_reask_kwargs
function is used in bothretry_sync
andretry_async
functions. The refactoring seems to focus on improving exception handling and modularity, which is consistent with the use of this function.
3. instructor/retry.py:228
- Draft comment:
The addition of thecontext
parameter inretry_async
is consistent with the refactoring goals. Ensure thatprocess_response_async
handles this parameter correctly. - Reason this comment was not posted:
Confidence changes required:50%
Theretry_sync
andretry_async
functions have been refactored to include thecontext
parameter, which is used in theprocess_response
andprocess_response_async
functions. This aligns with the refactoring goals mentioned in the PR description.
4. instructor/retry.py:179
- Draft comment:
The error message in theInstructorRetryException
should be formatted for clarity. Consider using a consistent format for error messages throughout the codebase. - Reason this comment was not posted:
Confidence changes required:80%
The error messages in assertions should be formatted well for clarity and consistency.
5. instructor/retry.py:225
- Draft comment:
The error message in theInstructorRetryException
should be formatted for clarity. Consider using a consistent format for error messages throughout the codebase. - Reason this comment was not posted:
Confidence changes required:80%
The error messages in assertions should be formatted well for clarity and consistency.
Workflow ID: wflow_3WHaseC8h2heyY7f
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
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 d2c2f06 in 12 seconds
More details
- Looked at
10
lines of code in1
files - Skipped
0
files when reviewing. - Skipped posting
2
drafted comments based on config settings.
1. instructor/reask.py:288
- Draft comment:
Copyingkwargs
is unnecessary if not modified outside the function. Consider removingkwargs = kwargs.copy()
for performance improvement. This applies to other functions as well. - Reason this comment was not posted:
Confidence changes required:50%
The code has a consistent pattern of copying thekwargs
dictionary at the start of each function. This is unnecessary if thekwargs
are not modified in a way that affects the original dictionary outside the function. It can be removed to improve performance.
2. instructor/reask.py:288
- Draft comment:
Assertions should always have an error message that is formatted well. Ensure that all assertions in the codebase, including those in other functions, have descriptive error messages. - Reason this comment was not posted:
Confidence changes required:80%
The code has multiple instances of assertions without error messages.
Workflow ID: wflow_m6pkTtz2erkQZTdh
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
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 d8d521f in 21 seconds
More details
- Looked at
36
lines of code in2
files - Skipped
0
files when reviewing. - Skipped posting
4
drafted comments based on config settings.
1. instructor/reask.py:92
- Draft comment:
Consider usingkwargs.setdefault("chat_history", []).append(...)
to simplify the code and avoid unnecessary reassignment. - Reason this comment was not posted:
Confidence changes required:80%
The code inreask.py
andtemplating.py
has some issues that need to be addressed. Inreask.py
, thereask_cohere_tools
function has a potential issue with handlingchat_history
. Intemplating.py
, thehandle_templating
function has a logical error in handlingnew_kwargs
when it is a list.
2. instructor/templating.py:91
- Draft comment:
Return an empty dictionary instead ofNone
to maintain consistency in return type. - Reason this comment was not posted:
Confidence changes required:80%
Thehandle_templating
function intemplating.py
has a logical error whennew_kwargs
is a list. The function should return an empty dictionary instead ofNone
to maintain consistency in return type.
3. instructor/templating.py:83
- Draft comment:
Function names should follow a consistent naming pattern across the codebase. Consider using snake_case for all function names for consistency. - Reason this comment was not posted:
Confidence changes required:80%
The functionreask_cohere_tools
inreask.py
andhandle_templating
intemplating.py
have inconsistent naming conventions. The former uses snake_case while the latter uses camelCase. Consistent naming conventions should be followed across the codebase.
4. instructor/reask.py:91
- Draft comment:
Good refactoring to avoid repetition by usingget
andappend
methods forchat_history
. This adheres to the DRY principle. - Reason this comment was not posted:
Confidence changes required:0%
The code inreask_cohere_tools
was refactored to avoid repetition by usingget
andappend
methods. This change adheres to the DRY principle.
Workflow ID: wflow_HivP1NIYTqEGVJ7f
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
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.
❌ Changes requested. Incremental review on f7a6659 in 23 seconds
More details
- Looked at
60
lines of code in1
files - Skipped
0
files when reviewing. - Skipped posting
3
drafted comments based on config settings.
1. instructor/templating.py:104
- Draft comment:
Thehandle_templating
function should return a consistent type. Currently, it may returnNone
ifmessages
is not found, which can lead to unexpected behavior. Consider returningnew_kwargs
instead. - Reason this comment was not posted:
Confidence changes required:80%
Thehandle_templating
function should return a consistent type. Currently, it may returnNone
in some cases, which can lead to unexpected behavior.
2. instructor/templating.py:13
- Draft comment:
Theprocess_message
function returns different types based on conditions (e.g.,gm.Content
orNone
). Consider having a consistent return type or document the behavior clearly. - Reason this comment was not posted:
Confidence changes required:80%
The functionprocess_message
is returning different types based on conditions, which can be confusing. It should have a consistent return type or be documented if it intentionally returns different types.
3. instructor/templating.py:112
- Draft comment:
Theprocess_message
function is used here, but its return value is not consistently utilized across different usages. Ensure consistent handling of its return value or document the intended behavior. - Reason this comment was not posted:
Confidence changes required:80%
Theprocess_message
function is used in multiple places, and its return value is being used in some cases but not others. This inconsistency should be addressed or documented.
Workflow ID: wflow_7dlNMj6YYMRMWGWO
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.
@@ -48,7 +53,7 @@ def process_message(message: dict[str, Any], context: dict[str, Any]) -> None: | |||
apply_template(part, context) if isinstance(part, str) else part | |||
for part in message["parts"] | |||
] | |||
return | |||
return message |
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.
The function process_message
is expected to return None
, but it returns a value in some cases (e.g., for Gemini format). This inconsistency can lead to unexpected behavior. Consider standardizing the return type.
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 6f4f069 in 15 seconds
More details
- Looked at
27
lines of code in2
files - Skipped
0
files when reviewing. - Skipped posting
3
drafted comments based on config settings.
1. instructor/dsl/iterable.py:95
- Draft comment:
Avoid using# type:ignore
without a clear reason. Consider addressing the underlying type issue instead. - Reason this comment was not posted:
Confidence changes required:50%
The type:ignore comment is used to suppress type checking errors, but it should be used sparingly and with a clear reason. In this case, it seems to be used to ignore a potential type mismatch, but it's not clear why it's necessary.
2. instructor/dsl/partial.py:166
- Draft comment:
Avoid using# type:ignore
without a clear reason. Consider addressing the underlying type issue instead. - Reason this comment was not posted:
Confidence changes required:50%
The type:ignore comment is used to suppress type checking errors, but it should be used sparingly and with a clear reason. In this case, it seems to be used to ignore a potential type mismatch, but it's not clear why it's necessary.
3. instructor/dsl/iterable.py:93
- Draft comment:
Add a comment explaining why# type:ignore
is necessary here and inpartial.py
on line 166 to improve code clarity. - Reason this comment was not posted:
Confidence changes required:60%
The# type:ignore
comments are used without explanation, which can be confusing for future developers.
Workflow ID: wflow_P6ZhQft4WUHu24Tp
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
Vertex AI Tests
Gemini Tests
Cerebras Tests
Cohere Tests
|
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 28f7513 in 13 seconds
More details
- Looked at
40
lines of code in1
files - Skipped
0
files when reviewing. - Skipped posting
2
drafted comments based on config settings.
1. instructor/reask.py:278
- Draft comment:
Remove redundant comment for clarity. - Reason this comment was not posted:
Confidence changes required:10%
The comment on line 278 is redundant and can be removed for clarity.
2. instructor/reask.py:278
- Draft comment:
The comment can be more concise:
Mode.COHERE_JSON_SCHEMA: reask_cohere_tools, # Same function
- Reason this comment was not posted:
Confidence changes required:50%
The comment on line 278 is not concise and can be improved by removing unnecessary words.
Workflow ID: wflow_weNtQAQRc4Yfn0dC
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
Important
Refactor reasking and retry logic by introducing
reask.py
for mode-specific handling and updatingretry.py
for improved exception handling and modularity.reask.py
with functions likereask_anthropic_tools
,reask_cohere_tools
,reask_gemini_tools
for mode-specific reasking.handle_reask_kwargs()
to select appropriate reask function based on mode.retry_sync()
andretry_async()
inretry.py
to usehandle_reask_kwargs()
for exception handling.initialize_retrying()
andinitialize_usage()
to set up retrying and usage tracking.InstructorRetryException
inexceptions.py
to includecreate_kwargs
.patch.py
andtemplating.py
for logging and templating adjustments.iterable.py
andpartial.py
.This description was created by
for 28f7513. It will automatically update as commits are pushed.