diff --git a/api/core/app/apps/advanced_chat/generate_task_pipeline.py b/api/core/app/apps/advanced_chat/generate_task_pipeline.py index 639d1c98ec..b4ed123475 100644 --- a/api/core/app/apps/advanced_chat/generate_task_pipeline.py +++ b/api/core/app/apps/advanced_chat/generate_task_pipeline.py @@ -529,31 +529,40 @@ class AdvancedChatAppGenerateTaskPipeline(BasedGenerateTaskPipeline, WorkflowCyc text = '' if isinstance(value, str | int | float): text = str(value) - elif isinstance(value, dict): - # other types - text = json.dumps(value, ensure_ascii=False) elif isinstance(value, FileVar): # convert file to markdown text = value.to_markdown() + elif isinstance(value, dict): + # handle files + file_vars = self._fetch_files_from_variable_value(value) + if file_vars: + file_var = file_vars[0] + try: + file_var_obj = FileVar(**file_var) + + # convert file to markdown + text = file_var_obj.to_markdown() + except Exception as e: + logger.error(f'Error creating file var: {e}') + + if not text: + # other types + text = json.dumps(value, ensure_ascii=False) elif isinstance(value, list): - for item in value: - if isinstance(item, FileVar): - text += item.to_markdown() + ' ' + # handle files + file_vars = self._fetch_files_from_variable_value(value) + for file_var in file_vars: + try: + file_var_obj = FileVar(**file_var) + except Exception as e: + logger.error(f'Error creating file var: {e}') + continue + + # convert file to markdown + text = file_var_obj.to_markdown() + ' ' text = text.strip() - # # handle files - # file_vars = self._fetch_files_from_variable_value(value) - # for file_var in file_vars: - # try: - # file_var_obj = FileVar(**file_var) - # except Exception as e: - # logger.error(f'Error creating file var: {e}') - # continue - # - # # convert file to markdown - # text = file_var_obj.to_markdown() - if not text and value: # other types text = json.dumps(value, ensure_ascii=False) diff --git a/api/core/app/task_pipeline/workflow_cycle_manage.py b/api/core/app/task_pipeline/workflow_cycle_manage.py index 89da11b76c..fc8afa8c70 100644 --- a/api/core/app/task_pipeline/workflow_cycle_manage.py +++ b/api/core/app/task_pipeline/workflow_cycle_manage.py @@ -533,5 +533,7 @@ class WorkflowCycleManage: if isinstance(value, dict): if '__variant' in value and value['__variant'] == FileVar.__name__: return value + elif isinstance(value, FileVar): + return value.to_dict() return None