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

File field _extra_config can not be initialized on constructor #10179

Closed
5 tasks done
zhuqingchao opened this issue Nov 1, 2024 · 1 comment · Fixed by #10679
Closed
5 tasks done

File field _extra_config can not be initialized on constructor #10179

zhuqingchao opened this issue Nov 1, 2024 · 1 comment · Fixed by #10679
Assignees
Labels
🐞 bug Something isn't working

Comments

@zhuqingchao
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.10.2

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

image
the _extra_config field can not be rightly initialized with pydantic.
so some extra_config like the image detail will lose in the file_factory.py. below here:
image

add a constructor for File class may solve this problem
image

def __init__(self, **data):
        super().__init__(**data)
        self._extra_config = data.get("_extra_config")

✔️ Expected Behavior

rightly initialized

❌ Actual Behavior

_extra_config is missing

@dosubot dosubot bot added the 🐞 bug Something isn't working label Nov 1, 2024
Copy link

dosubot bot commented Nov 1, 2024

To ensure the _extra_config field in the File class is correctly initialized using Pydantic, you can use Field(default_factory=...) to provide a default value. This approach ensures that _extra_config is initialized with a default FileExtraConfig instance if no value is provided during the creation of a File object. Here's how you can modify the File class:

class File(BaseModel):
    dify_model_identity: str = FILE_MODEL_IDENTITY

    id: Optional[str] = None  # message file id
    tenant_id: str
    type: FileType
    transfer_method: FileTransferMethod
    remote_url: Optional[str] = None  # remote url
    related_id: Optional[str] = None
    filename: Optional[str] = None
    extension: Optional[str] = Field(default=None, description="File extension, should contains dot")
    mime_type: Optional[str] = None
    size: int = -1
    _extra_config: FileExtraConfig | None = Field(default_factory=FileExtraConfig)

    # rest of the class remains unchanged

This change should resolve the issue of _extra_config not being initialized properly [1].

To continue talking to Dosu, mention @dosu.

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
2 participants