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

Run failed: Failed to invoke tool: Object of type FileVar is not JSON serializable #9386

Closed
5 tasks done
hufangdong86 opened this issue Oct 16, 2024 · 9 comments · Fixed by #8818
Closed
5 tasks done
Assignees
Labels
🐞 bug Something isn't working

Comments

@hufangdong86
Copy link

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.8.3-0.9.2

Cloud or Self Hosted

Cloud, Self Hosted (Docker), Self Hosted (Source)

Steps to reproduce

image
image
image

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

Copy link

dosubot bot commented Oct 16, 2024

Hello, @hufangdong86! I'm here to assist you with any bugs, questions, or contributions. I can help you while waiting for a human maintainer.

To resolve the error "Object of type FileVar is not JSON serializable" in Dify version 0.8.3-0.9.2, you need to ensure that FileVar objects are converted to a JSON-serializable format before serialization. This can be done by modifying the _convert_tool_messages method to convert FileVar objects to dictionaries using a method like to_dict() before returning them. Here's an example of how you might adjust the code:

def _convert_tool_messages(self, messages: list[ToolInvokeMessage]) -> tuple[str, list[dict], list[dict]]:
    """
    Convert ToolInvokeMessages into tuple[plain_text, files, json]
    """
    # transform message and handle file storage
    messages = ToolFileMessageTransformer.transform_tool_invoke_messages(
        messages=messages,
        user_id=self.user_id,
        tenant_id=self.tenant_id,
        conversation_id=None,
    )
    # extract plain text and files
    files = self._extract_tool_response_binary(messages)
    plain_text = self._extract_tool_response_text(messages)
    json = self._extract_tool_response_json(messages)

    # Convert FileVar objects to dictionaries
    files_as_dicts = [file_var.to_dict() for file_var in files]

    return plain_text, files_as_dicts, json

This change ensures that the files list contains dictionaries instead of FileVar objects, making it JSON serializable [1].

To continue talking to Dosu, mention @dosu.

@dosubot dosubot bot added the 🐞 bug Something isn't working label Oct 16, 2024
@hufangdong86
Copy link
Author

Version 0.6.11 is normal, but it becomes abnormal from version 0.8.2 onwards.

@hufangdong86
Copy link
Author

@dosu

@hufangdong86
Copy link
Author

@dosu def _convert_tool_messages(self, messages: list[ToolInvokeMessage]) -> tuple[str, list[dict], list[dict]]:
"""
Convert ToolInvokeMessages into tuple[plain_text, files, json]
"""
# transform message and handle file storage
messages = ToolFileMessageTransformer.transform_tool_invoke_messages(
messages=messages,
user_id=self.user_id,
tenant_id=self.tenant_id,
conversation_id=None,
)
# extract plain text and files
files = self._extract_tool_response_binary(messages)
plain_text = self._extract_tool_response_text(messages)
json = self._extract_tool_response_json(messages)

# Convert FileVar objects to dictionaries
files_as_dicts = [file_var.to_dict() for file_var in files]

return plain_text, files_as_dicts, json

But the chart is not displayed.

image

@laipz8200
Copy link
Member

Hello! Could you provide the minimal DSL that can reproduce this issue?

Copy link

dosubot bot commented Oct 16, 2024

To address the issue where the chart is not displayed after making the FileVar objects JSON serializable, you should ensure that the data being passed to the chart node is correctly formatted and that the chart node is configured to handle the data properly.

Here are a few steps to troubleshoot and potentially resolve the issue:

  1. Verify Data Format: Ensure that the data being passed to the "Bar Chart" node is in the expected format. The chart node might require specific data structures or keys to render the chart correctly.

  2. Check Chart Configuration: Double-check the configuration of the "Bar Chart" node. Make sure that all required fields are filled out and that the data types match what the node expects.

  3. Inspect JSON Output: Since the chat interface displays JSON-like metadata, verify that the JSON output includes all necessary information for the chart. Ensure that the data arrays and labels are correctly structured.

  4. Review Node Connections: Ensure that the nodes are correctly connected in the workflow. The data output from one node should match the input requirements of the next node.

  5. Debugging: Add logging or print statements to check the data being passed between nodes. This can help identify if the data is being transformed or lost at any point in the workflow.

If these steps do not resolve the issue, there might be a change in how data is handled between versions 0.6.11 and 0.8.2 that affects chart rendering. Reviewing the release notes or change logs for these versions might provide additional insights into any changes that could impact chart display.

To continue talking to Dosu, mention @dosu.

@hufangdong86
Copy link
Author

llm.txt
charts.txt

charts is a workflow

@laipz8200

@hufangdong86
Copy link
Author

@laipz8200 Hello, have you located the issue?

@laipz8200
Copy link
Member

It will be fixed in v0.10.0. If you want, you can try v0.10.0-beta3 before we release it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants