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

/document/create-by-file can not work for missing data_source_type field value #12272

Closed
5 tasks done
lyfuci opened this issue Jan 1, 2025 · 2 comments · Fixed by #12273
Closed
5 tasks done

/document/create-by-file can not work for missing data_source_type field value #12272

lyfuci opened this issue Jan 1, 2025 · 2 comments · Fixed by #12273
Labels
🐞 bug Something isn't working

Comments

@lyfuci
Copy link
Contributor

lyfuci commented Jan 1, 2025

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

14.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

just upload any support file using the /datasets/{dataset_id}/document/create-by-file api, you'll see it. response posted.

{
    "code": "invalid_param",
    "message": "1 validation error for KnowledgeConfig\ndata_source.info_list.data_source_type\n  Field required [type=missing, input_value={'file_info_list': {'file...1c-9381-966510ea8045']}}, input_type=dict]\n    For further information visit https://errors.pydantic.dev/2.9/v/missing",
    "status": 400
}

✔️ Expected Behavior

expect create-by-file api works

❌ Actual Behavior

any file upload get a HTTP 400 response .

{
    "code": "invalid_param",
    "message": "1 validation error for KnowledgeConfig\ndata_source.info_list.data_source_type\n  Field required [type=missing, input_value={'file_info_list': {'file...1c-9381-966510ea8045']}}, input_type=dict]\n    For further information visit https://errors.pydantic.dev/2.9/v/missing",
    "status": 400
}
Copy link

dosubot bot commented Jan 1, 2025

@lyfuci Hello there! I'm here to help you with any bugs, questions, or contributions while you wait for a human maintainer. Let's tackle this together!

The error message indicates that the data_source_type field is missing in the request payload for the /datasets/{dataset_id}/document/create-by-file API endpoint. This field is required for the KnowledgeConfig data model, and its absence is causing the validation error.

To resolve this issue, ensure that the data_source_type field is included in your request payload. The possible values for this field are notion, website, and upload_file [1]. Since you are using the create-by-file endpoint, you should set data_source_type to upload_file.

Here's an example of how you might structure your request:

curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/document/create-by-file' \
--header 'Authorization: Bearer {api_key}' \
--form 'data="{\"indexing_technique\":\"high_quality\",\"process_rule\":{\"rules\":{\"pre_processing_rules\":[{\"id\":\"remove_extra_spaces\",\"enabled\":true},{\"id\":\"remove_urls_emails\",\"enabled\":true}],\"segmentation\":{\"separator\":\"###\",\"max_tokens\":500}},\"mode\":\"custom\"},\"data_source_type\":\"upload_file\"}";type=text/plain' \
--form 'file=@"/path/to/file"'

Make sure to replace {dataset_id} and {api_key} with your actual dataset ID and API key, and adjust the file path as needed. This should help you avoid the validation error and successfully upload your file.

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 the 🐞 bug Something isn't working label Jan 1, 2025
@lyfuci
Copy link
Contributor Author

lyfuci commented Jan 1, 2025

I am sure my custom client works well at version 13.x

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
1 participant