mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 03:32:23 +08:00
fix(file_upload): correct validation method and add unit tests (#10477)
Some checks failed
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Has been cancelled
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Has been cancelled
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Has been cancelled
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Has been cancelled
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Has been cancelled
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Some checks failed
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Has been cancelled
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Has been cancelled
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Has been cancelled
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Has been cancelled
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Has been cancelled
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
This commit is contained in:
parent
eb6c0b8027
commit
172c7eb270
|
@ -41,6 +41,6 @@ class FileUploadConfigManager:
|
|||
if not config.get("file_upload"):
|
||||
config["file_upload"] = {}
|
||||
else:
|
||||
FileExtraConfig.model_validate(config["file_upload"])
|
||||
FileUploadConfig.model_validate(config["file_upload"])
|
||||
|
||||
return config, ["file_upload"]
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
from core.app.app_config.features.file_upload.manager import FileUploadConfigManager
|
||||
from core.file.models import FileTransferMethod, FileUploadConfig, ImageConfig
|
||||
from core.model_runtime.entities.message_entities import ImagePromptMessageContent
|
||||
|
||||
|
||||
def test_convert_with_vision():
|
||||
config = {
|
||||
"file_upload": {
|
||||
"enabled": True,
|
||||
"number_limits": 5,
|
||||
"allowed_file_upload_methods": [FileTransferMethod.REMOTE_URL],
|
||||
"image": {"detail": "high"},
|
||||
}
|
||||
}
|
||||
result = FileUploadConfigManager.convert(config, is_vision=True)
|
||||
expected = FileUploadConfig(
|
||||
image_config=ImageConfig(
|
||||
number_limits=5,
|
||||
transfer_methods=[FileTransferMethod.REMOTE_URL],
|
||||
detail=ImagePromptMessageContent.DETAIL.HIGH,
|
||||
)
|
||||
)
|
||||
assert result == expected
|
||||
|
||||
|
||||
def test_convert_without_vision():
|
||||
config = {
|
||||
"file_upload": {
|
||||
"enabled": True,
|
||||
"number_limits": 5,
|
||||
"allowed_file_upload_methods": [FileTransferMethod.REMOTE_URL],
|
||||
}
|
||||
}
|
||||
result = FileUploadConfigManager.convert(config, is_vision=False)
|
||||
expected = FileUploadConfig(
|
||||
image_config=ImageConfig(number_limits=5, transfer_methods=[FileTransferMethod.REMOTE_URL])
|
||||
)
|
||||
assert result == expected
|
||||
|
||||
|
||||
def test_validate_and_set_defaults():
|
||||
config = {}
|
||||
result, keys = FileUploadConfigManager.validate_and_set_defaults(config)
|
||||
assert "file_upload" in result
|
||||
assert keys == ["file_upload"]
|
||||
|
||||
|
||||
def test_validate_and_set_defaults_with_existing_config():
|
||||
config = {
|
||||
"file_upload": {
|
||||
"enabled": True,
|
||||
"number_limits": 5,
|
||||
"allowed_file_upload_methods": [FileTransferMethod.REMOTE_URL],
|
||||
}
|
||||
}
|
||||
result, keys = FileUploadConfigManager.validate_and_set_defaults(config)
|
||||
assert "file_upload" in result
|
||||
assert keys == ["file_upload"]
|
||||
assert result["file_upload"]["enabled"] is True
|
||||
assert result["file_upload"]["number_limits"] == 5
|
||||
assert result["file_upload"]["allowed_file_upload_methods"] == [FileTransferMethod.REMOTE_URL]
|
Loading…
Reference in New Issue
Block a user