diff --git a/api/core/memory/token_buffer_memory.py b/api/core/memory/token_buffer_memory.py index f1f8ab3a3b9116..4d44ac38183fb0 100644 --- a/api/core/memory/token_buffer_memory.py +++ b/api/core/memory/token_buffer_memory.py @@ -47,11 +47,14 @@ def get_history_prompt_messages(self, max_token_limit: int = 2000, files, message.app_model_config ) - prompt_message_contents = [TextPromptMessageContent(data=message.query)] - for file_obj in file_objs: - prompt_message_contents.append(file_obj.prompt_message_content) - - prompt_messages.append(UserPromptMessage(content=prompt_message_contents)) + if not file_objs: + prompt_messages.append(UserPromptMessage(content=message.query)) + else: + prompt_message_contents = [TextPromptMessageContent(data=message.query)] + for file_obj in file_objs: + prompt_message_contents.append(file_obj.prompt_message_content) + + prompt_messages.append(UserPromptMessage(content=prompt_message_contents)) else: prompt_messages.append(UserPromptMessage(content=message.query))