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

When the workflow output panel (log details) is a text output type, the front-end page will not render correctly when the result outputs is an array object consisting of strings. #12682

Open
5 tasks done
weiwenyan-dev opened this issue Jan 13, 2025 · 4 comments · May be fixed by #12683

Comments

@weiwenyan-dev
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.14.2

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

  1. Build a patent OA reply agent on Dify;
  2. Upload a PDF file;
  3. The operation shows success;
  4. Click the log to view the result, but it cannot be rendered;
  5. The result is an object, and the value is an array, which is made up of strings.

✔️ Expected Behavior

According to text type, display data and format normally.

❌ Actual Behavior

The result page cannot be rendered.

Copy link

dosubot bot commented Jan 13, 2025

Hello @weiwenyan-dev! I'm here to assist you with any bugs, questions, or contributions you have for Dify. Let me know how I can help!

The issue you're experiencing with the front-end page not rendering correctly when the workflow output panel is a text output type and the result is an array of strings is due to the isTextOutput condition only checking for a single string. This condition does not account for arrays of strings, which prevents the rendering logic for text output from being triggered.

To fix this, you need to modify the isTextOutput condition to handle arrays of strings. You can update the condition to check if the output is an array and if all elements are strings, then join them into a single string for rendering. Here's how you can adjust the code:

const isTextOutput = useMemo(() => {
  if (!outputs || Object.keys(outputs).length !== 1) return false;
  const outputValue = outputs[Object.keys(outputs)[0]];
  return typeof outputValue === 'string' || 
         (Array.isArray(outputValue) && outputValue.every(item => typeof item === 'string'));
}, [outputs]);

And modify the rendering logic to handle arrays:

{isTextOutput && (
  <div className='px-4 py-2'>
    <Markdown content={Array.isArray(outputs[Object.keys(outputs)[0]]) 
      ? outputs[Object.keys(outputs)[0]].join('\n') 
      : outputs[Object.keys(outputs)[0]] || ''} />
  </div>
)}

This change ensures that arrays of strings are treated as text output and rendered correctly [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot dosubot bot added 🐞 bug Something isn't working labels Jan 13, 2025
@crazywoola
Copy link
Member

LLM supports text or file only, if you want to render arrays please use template node to transform it.

@crazywoola crazywoola removed the 🐞 bug Something isn't working label Jan 13, 2025
@weiwenyan-dev weiwenyan-dev linked a pull request Jan 13, 2025 that will close this issue
5 tasks
@weiwenyan-dev
Copy link
Author

LLM supports text or file only, if you want to render arrays please use template node to transform it.

What do you mean I found out about it myself and figured out how to fix it by submitting an issue first and then submitting the merge request

@crazywoola
Copy link
Member

LLM supports text or file only, if you want to render arrays please use template node to transform it.

What do you mean I found out about it myself and figured out how to fix it by submitting an issue first and then submitting the merge request

@crazywoola crazywoola reopened this Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants