-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: The workflow includes a form collection node. After the normal Q&A on the demonstration page is completed, refreshing the page will display the output of the nodes before the form collection node #3081
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,8 @@ def save_context(self, details, workflow_manage): | |
| self.context['start_time'] = details.get('start_time') | ||
| self.context['form_data'] = form_data | ||
| self.context['is_submit'] = details.get('is_submit') | ||
| self.answer_text = details.get('result') | ||
| if self.node_params.get('is_result', False): | ||
| self.answer_text = details.get('result') | ||
| if form_data is not None: | ||
| for key in form_data: | ||
| self.context[key] = form_data[key] | ||
|
|
@@ -70,7 +71,7 @@ def get_answer_list(self) -> List[Answer] | None: | |
| "chat_record_id": self.flow_params_serializer.data.get("chat_record_id"), | ||
| 'form_data': self.context.get('form_data', {}), | ||
| "is_submit": self.context.get("is_submit", False)} | ||
| form = f'<form_rander>{json.dumps(form_setting,ensure_ascii=False)}</form_rander>' | ||
| form = f'<form_rander>{json.dumps(form_setting, ensure_ascii=False)}</form_rander>' | ||
| context = self.workflow_manage.get_workflow_content() | ||
| form_content_format = self.workflow_manage.reset_prompt(form_content_format) | ||
| prompt_template = PromptTemplate.from_template(form_content_format, template_format='jinja2') | ||
|
|
@@ -85,7 +86,7 @@ def get_details(self, index: int, **kwargs): | |
| "chat_record_id": self.flow_params_serializer.data.get("chat_record_id"), | ||
| 'form_data': self.context.get('form_data', {}), | ||
| "is_submit": self.context.get("is_submit", False)} | ||
| form = f'<form_rander>{json.dumps(form_setting,ensure_ascii=False)}</form_rander>' | ||
| form = f'<form_rander>{json.dumps(form_setting, ensure_ascii=False)}</form_rander>' | ||
| context = self.workflow_manage.get_workflow_content() | ||
| form_content_format = self.workflow_manage.reset_prompt(form_content_format) | ||
| prompt_template = PromptTemplate.from_template(form_content_format, template_format='jinja2') | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided Python code has some minor improvements and corrections. Here are the main points to address:
Here's the optimized code snippet: def save_context(self, details, workflow_manage):
# Add more context items here.
self.context['start_time'] = details.get('start_time')
self.context['form_data'] = details.get('form_data')
self.context['is_submit'] = details.get('is_submit')
if self.node_params.get('is_result', False):
self.answer_text = details.get('result')
def get_answer_list(self) -> List[Answer] | None:
if not self.flow_params_serializer or not self.flow_params_serializer.data:
return [] # Check flow_params_serializer before accessing its fields
form_setting = {
"chat_record_id": self.flow_params_serializer.data.get("chat_record_id"),
"form_data": self.context.get('form_data', {}),
"is_submit": self.context.get("is_submit", False)
}
form_rander = f'<form_rander>{json.dumps(form_setting, ensure_ascii=False)}</form_rander>'
context = self.workflow_manage.get_workflow_content()
form_content_format = self.workflow_manage.reset_prompt(form_content_format)
prompt_template = PromptTemplate.from_template(
form_content_format,
template_format='jinja2'
)
# Return list of answers here using the prompt_template and context.
def get_details(self, index: int, **kwargs):
# Similarly optimize this method to avoid duplication of logic in creating 'form' variable.These changes should help make the code cleaner and potentially more efficient, while ensuring consistency across function definitions and eliminating redundancy. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,15 +16,17 @@ class BaseImageGenerateNode(IImageGenerateNode): | |
| def save_context(self, details, workflow_manage): | ||
| self.context['answer'] = details.get('answer') | ||
| self.context['question'] = details.get('question') | ||
| self.answer_text = details.get('answer') | ||
| if self.node_params.get('is_result', False): | ||
| self.answer_text = details.get('answer') | ||
|
|
||
| def execute(self, model_id, prompt, negative_prompt, dialogue_number, dialogue_type, history_chat_record, chat_id, | ||
| model_params_setting, | ||
| chat_record_id, | ||
| **kwargs) -> NodeResult: | ||
| print(model_params_setting) | ||
| application = self.workflow_manage.work_flow_post_handler.chat_info.application | ||
| tti_model = get_model_instance_by_model_user_id(model_id, self.flow_params_serializer.data.get('user_id'), **model_params_setting) | ||
| tti_model = get_model_instance_by_model_user_id(model_id, self.flow_params_serializer.data.get('user_id'), | ||
| **model_params_setting) | ||
| history_message = self.get_history_message(history_chat_record, dialogue_number) | ||
| self.context['history_message'] = history_message | ||
| question = self.generate_prompt_question(prompt) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code snippet has several improvements that can be made for clarity, efficiency, and better readability: Improvements Summary:
Here is the revised version of the code with these changes applied: @@ -16,18 +15,23 @@
class BaseImageGenerateNode(IImageGenerateNode):
def save_context(self, details, workflow_manage):
self.context['answer'] = details.get('answer', None)
self.context['question'] = details.get('question', None)
+ answer_to_save = details.get('answer')
+ if not isinstance(answer_to_save, basestring):
+ answer_to_save = ''
+ if self.node_params.get('is_result', False):
+ self.answer_text = answer_to_save
def execute(
self,
model_id: int,
prompt: Union[str],
negative_prompt: Optional[Union[str]],
dialogue_number: int,
dialogue_type: str,
history_chat_record: List[str],
chat_id: str,
model_params_setting: Dict[Any, Any] = {},
chat_record_id: Optional[int] = None,
**kwargs
) -> NodeResult:
application = self.workflow_manage.work_flow_post_handler.chat_info.application
tti_model = get_model_instance_by_model_user_id(model_id, self.flow_params_serializer.data.get('user_id'), **model_params_setting)
history_message = self.get_history_message(history_chat_record, dialogue_number)
self.context['history_message'] = history_message
question = self.generate_prompt_question(prompt)
# Print statement should ideally have no side effects unless necessary.
print(f"Model Parameters Setting: {model_params_setting}")These modifications make the code cleaner and more understandable. Adjustments like converting variables to strings where appropriate help maintain type safety without causing runtime exceptions. Printing statements related to input data ( |
||
|
|
||
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.
Code Review
Docstring Improvements: The docstrings could be more detailed, especially explaining what each function is intended to do.
Variable Naming Consistency: Use descriptive variable names instead of
node_variable,workflow_variable, etc., which can make the code easier to understand.Function Annotations: Add annotations to functions to clarify their parameters and return types (where applicable).
Asynchronous Functions: Ensure that all asynchronous operations are properly awaited or returned in coroutines for better readability.
Here’s the modified version with some improvements:
Key Changes:
AsyncGeneratorfor yielding chunks from MCP server responses.mcp_response_generator.These changes should improve the readability and maintainability of the provided code.