-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: Reason content #4368
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: Reason content #4368
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
| if os.path.exists(code_path): | ||
| os.remove(code_path) | ||
| return { | ||
| 'step_type': 'chat_step', |
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 provided Python function execute_block has a minor issue with string concatenation. Instead of using an OR operator (or) which could lead to unexpected results when handling empty strings, it should be combined more straightforwardly. Here's the revised version:
def execute_block(self, message_list: List[BaseMessage],
chat_result):
# Existing logic...
if 'reasoning_content' in chat_result.response_metadata:
reasoning_content = chat_result.response_metadata.get('reasoning_content', '')
else:
reasoning_content = reasoning_result.get('reasoning_content') + reasoning_result_end.get(
'reasoning_content')
# Revised line
output_string = ("{}{}{}".format(*[
item or ""
for item in [
reasoning_result.get('content'),
reasoning_result_end.get('content'),
" " if any(item) else "", # Add space only if either part is not empty
reasoning_content
]
]))
post_response_handler.handler(chat_id, chat_record_id, paragraph_list, problem_text,
content, manage, self, padding_problem_text,
reasoning_content=output_string)In this revision, I used tuple unpacking within f-string formatting. This method ensures that all values are evaluated and concatenated correctly without unnecessary checks for emptiness. The spaces are added conditionally based on whether either the main content or reasoning content is present.
| reasoning_content = (reasoning_result.get('reasoning_content') or '') + (reasoning_result_end.get('reasoning_content') or '') | ||
| _write_context(node_variable, workflow_variable, node, workflow, content, reasoning_content) | ||
|
|
||
|
|
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 provided Python function is mostly correct but contains two minor issues:
-
The line
content = reasoning_result.get('content') + reasoning_result_end.get('content')can be simplified using logical OR (or) to avoid multiple conditions. -
Similarly, the line where both
reasoning_contentand its fallbacks are concatenated should also useor.
Here's an optimized version of the code with these corrections:
def write_context(node_variable: Dict, workflow_variable: Dict, node: INode,
workflow: WorkflowData, response):
# Sum reasoning content from responses or their empty strings
reasoning_content = (response.reasoning_content or '') \
+ (response.response_metadata.get('reasoning_content', '') or '')
content = reasoninig_result.get('content') + reasoning_resultEnd.get('content')
_write_context(node_variable, workflow_variable, node, workflow, content, reasoning_content)These changes ensure that if either response.reasoning_content or the one specified in metadata is None, it will default to an empty string before concatenation. This avoids potential runtime errors when attempting non-string values.
fix: Reason content