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

fix: Workflow non streaming dialogue cannot respond #2188

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

shaohuzhang1
Copy link
Contributor

fix: Workflow non streaming dialogue cannot respond

Copy link

f2c-ci-robot bot commented Feb 10, 2025

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/test-infra repository.

Copy link

f2c-ci-robot bot commented Feb 10, 2025

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

answer_text = '\n\n'.join(answer['content'] for answer in answer_text_list)
answer_text = '\n\n'.join(
'\n\n'.join([a.get('content') for a in answer]) for answer in
answer_text_list)
self.work_flow_post_handler.handler(self.params['chat_id'], self.params['chat_record_id'],
answer_text,
self)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The provided code has two primary issues that need attention:

  1. Double Join Operation:

    • The line answer_text = '\n\n'.join('\n\n'.join([a.get('content') for a in answer])) for answer in answer_text_list) contains unnecessary double joins.
  2. Handling of List of Lists:

    • Since each element in answer_text_list should be another list itself (i.e., [{'content': 'text'}, {'content': 'text'}]) and you want to join these lists with \n\n, it's simpler to directly flatten the entire list of lists before joining them together without nested joins.

Here’s an optimized version of the code addresses both issues:

@@ -335,7 +335,8 @@ def run_block(self, language='zh'):
     answer_tokens = sum([row.get('answer_tokens') for row in details.values() if
                          'answer_tokens' in row and row.get('answer_tokens') is not None])
     answer_text_list = self.get_answer_text_list()

    # Flatten the list of dictionaries within answer_text_list
    flat_answer_texts = [item.get('content') for sublist in answer_text_list for item in sublist]
    
    # Join all elements into a single string separated by \n\n
    answer_text = '\n\n'.join(flat_answer_texts)

    self.work_flow_post_handler.handler(self.params['chat_id'], self.params['chat_record_id'],
                                         answer_text,
                                         self)

With this change, we ensure that each entry from answer_text_list is processed separately without needing nested joins, resulting in more straightforward and efficient handling of multi-level data structures.

@shaohuzhang1 shaohuzhang1 merged commit cdb804b into main Feb 10, 2025
4 of 5 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@main@fix_workflow_chat branch February 10, 2025 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant