fix(dify): support Workflow response format in DifyTranslator#1128
Open
octo-patch wants to merge 2 commits into
Open
fix(dify): support Workflow response format in DifyTranslator#1128octo-patch wants to merge 2 commits into
octo-patch wants to merge 2 commits into
Conversation
When PyMuPDF's subset_fonts() raises a ValueError (e.g. due to a bad font width table value in some PDFs), the translation would crash after completing all the actual translation work. Wrap each subset_fonts call in a try-except so the output PDF is still written even if font subsetting fails. The output will be slightly larger in this case. Fixes PDFMathTranslate#975
Dify has three application types with different response formats:
- Workflow: {"data": {"outputs": {"answer": "..."}}}
- Agent/Chatflow: {"answer": "..."}
The previous code only read the top-level "answer" field, which
returned an empty string for Workflow apps (fixes PDFMathTranslate#895).
This change also corrects the swapped lang_in/lang_out parameter names
in DifyTranslator and AnythingLLMTranslator __init__ signatures. The
previous naming was confusing (the first positional arg was named
lang_out) even though the behaviour was correct due to a double reversal.
Co-Authored-By: Octopus <liyuan851277048@icloud.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #895
Problem
Dify has three application types with different API response formats:
{"data": {"outputs": {"answer": "..."}}}{"answer": "..."}The previous
DifyTranslator.do_translate()only read the top-level"answer"field, which worked for Agent/Chatflow apps but returned an empty string (no translation) for Workflow apps.Additionally, the
__init__signatures ofDifyTranslatorandAnythingLLMTranslatorhad theirlang_in/lang_outparameter names swapped relative to every other translator class. The behaviour was accidentally correct (both the naming and thesuper().__init__()call were reversed, cancelling each other out), but the confusing naming is a maintenance hazard.Solution
DifyTranslator.do_translate(): Try the Workflow response path (data.outputs.answer) first; fall back to the Agent/Chatflow path (answer) if not present. This makes both app types work transparently with the same translator.DifyTranslator.__init__andAnythingLLMTranslator.__init__to use the standardlang_in, lang_outorder, matching all other translator classes.Testing
Manually traced the response parsing for both Workflow and Agent/Chatflow response shapes. No existing tests were affected (the parameter reordering is a pure rename with identical runtime behaviour).