dify icon indicating copy to clipboard operation
dify copied to clipboard

The output results generated by the time tool contain escape characters \n, which leads to failure when writing to the knowledge base.

Open zswll2 opened this issue 1 year ago • 1 comments

Self Checks

  • [X] This is only for bug report, if you would like to ask a quesion, please head to Discussions.
  • [X] I have searched for existing issues search for existing issues, including closed ones.
  • [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [X] Pleas do not modify this template :) and fill in all the required fields.

Dify version

0.6.7

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Although custom time formats have been added in this version, there is still an error when importing the knowledge base using the API. I think this should be caused by \n. 微信截图_20240512162337

✔️ Expected Behavior

code 200

❌ Actual Behavior

code 400

zswll2 avatar May 12 '24 08:05 zswll2

The issue you're encountering with the "400 Bad Request" error when writing to the knowledge base via the API is likely due to the handling of newline characters (\n) in your JSON payload. When these characters are not properly escaped, they can disrupt the JSON formatting, leading to errors.

To address this, ensure that any newline characters in the strings of your JSON payload are properly escaped. This is crucial when constructing the prompt field or any other string fields in your JSON data. The json.dumps() method in Python automatically escapes these characters, so verify that the data being serialized does not contain unescaped newline characters or other special characters that could disrupt the JSON structure.

If automatic escaping does not resolve the issue, you may need to manually process the content of each message to ensure that all special characters are properly escaped before they are joined with \n. This step is important to prevent formatting issues that could lead to a "400 Bad Request" error.

Additionally, confirm that the API endpoint and the server are correctly configured to handle JSON payloads with escaped characters. If there are strict validation rules or incorrect handling of JSON escape sequences, it could result in errors.

Make sure also to follow the expected JSON payload structure as required by the API endpoint for writing to the knowledge base. Incorrect payload structure can also lead to errors.

If you continue to face issues, reviewing the server-side configurations and the specific validations that are applied to the API requests might be necessary. Ensure that your request adheres to the expected format and content as outlined in the documentation.

This approach should help you resolve the issue with the "400 Bad Request" error when attempting to write to the knowledge base using the API.

Details

Sources


About Dosu This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

dosubot[bot] avatar May 12 '24 08:05 dosubot[bot]