mirror of
https://github.com/langgenius/dify.git
synced 2026-09-24 23:22:26 +08:00
chore: split trial models to a single API (#36796)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -16,11 +16,22 @@ from . import console_ns
|
||||
from .wraps import account_initialization_required, cloud_utm_record, setup_required, with_current_tenant_id
|
||||
|
||||
|
||||
class TrialModelsResponse(ResponseModel):
|
||||
trial_models: list[str]
|
||||
|
||||
|
||||
class AppDslVersionResponse(ResponseModel):
|
||||
app_dsl_version: str
|
||||
|
||||
|
||||
register_response_schema_models(console_ns, AppDslVersionResponse, FeatureModel, LimitationModel, SystemFeatureModel)
|
||||
register_response_schema_models(
|
||||
console_ns,
|
||||
AppDslVersionResponse,
|
||||
FeatureModel,
|
||||
LimitationModel,
|
||||
SystemFeatureModel,
|
||||
TrialModelsResponse,
|
||||
)
|
||||
|
||||
|
||||
@console_ns.route("/features")
|
||||
@@ -66,6 +77,26 @@ class FeatureVectorSpaceApi(Resource):
|
||||
return FeatureService.get_vector_space(current_tenant_id).model_dump()
|
||||
|
||||
|
||||
@console_ns.route("/trial-models")
|
||||
class TrialModelsApi(Resource):
|
||||
@console_ns.doc("get_trial_models")
|
||||
@console_ns.doc(description="Get hosted trial model provider configuration")
|
||||
@console_ns.response(
|
||||
200,
|
||||
"Success",
|
||||
console_ns.models[TrialModelsResponse.__name__],
|
||||
)
|
||||
@setup_required
|
||||
@login_required
|
||||
@account_initialization_required
|
||||
def get(self):
|
||||
"""Get hosted trial model provider configuration for model-provider pages."""
|
||||
return dump_response(
|
||||
TrialModelsResponse,
|
||||
{"trial_models": FeatureService.get_trial_models()},
|
||||
)
|
||||
|
||||
|
||||
@console_ns.route("/app-dsl-version")
|
||||
class AppDslVersionApi(Resource):
|
||||
@console_ns.doc("get_app_dsl_version")
|
||||
|
||||
@@ -8258,6 +8258,23 @@ Stop workflow task
|
||||
| ---- | ----------- |
|
||||
| 200 | Success |
|
||||
|
||||
### /trial-models
|
||||
|
||||
#### GET
|
||||
##### Summary
|
||||
|
||||
Get hosted trial model provider configuration for model-provider pages
|
||||
|
||||
##### Description
|
||||
|
||||
Get hosted trial model provider configuration
|
||||
|
||||
##### Responses
|
||||
|
||||
| Code | Description | Schema |
|
||||
| ---- | ----------- | ------ |
|
||||
| 200 | Success | [TrialModelsResponse](#trialmodelsresponse) |
|
||||
|
||||
### /website/crawl
|
||||
|
||||
#### POST
|
||||
@@ -15292,7 +15309,6 @@ Default configuration for form inputs.
|
||||
| plugin_manager | [PluginManagerModel](#pluginmanagermodel) | | Yes |
|
||||
| sso_enforced_for_signin | boolean | | Yes |
|
||||
| sso_enforced_for_signin_protocol | string | | Yes |
|
||||
| trial_models | [ string ] | | Yes |
|
||||
| webapp_auth | [WebAppAuthModel](#webappauthmodel) | | Yes |
|
||||
|
||||
#### Tag
|
||||
@@ -15519,6 +15535,12 @@ Tag type
|
||||
| tool_name | string | | No |
|
||||
| type | string | | No |
|
||||
|
||||
#### TrialModelsResponse
|
||||
|
||||
| Name | Type | Description | Required |
|
||||
| ---- | ---- | ----------- | -------- |
|
||||
| trial_models | [ string ] | | Yes |
|
||||
|
||||
#### TrialPipelineVariable
|
||||
|
||||
| Name | Type | Description | Required |
|
||||
|
||||
@@ -1342,7 +1342,6 @@ Returns Server-Sent Events stream.
|
||||
| plugin_manager | [PluginManagerModel](#pluginmanagermodel) | | Yes |
|
||||
| sso_enforced_for_signin | boolean | | Yes |
|
||||
| sso_enforced_for_signin_protocol | string | | Yes |
|
||||
| trial_models | [ string ] | | Yes |
|
||||
| webapp_auth | [WebAppAuthModel](#webappauthmodel) | | Yes |
|
||||
|
||||
#### TextToAudioPayload
|
||||
|
||||
@@ -177,7 +177,6 @@ class SystemFeatureModel(FeatureResponseModel):
|
||||
plugin_installation_permission: PluginInstallationPermissionModel = PluginInstallationPermissionModel()
|
||||
enable_change_email: bool = True
|
||||
plugin_manager: PluginManagerModel = PluginManagerModel()
|
||||
trial_models: list[str] = []
|
||||
enable_creators_platform: bool = False
|
||||
enable_trial_app: bool = False
|
||||
enable_explore_banner: bool = False
|
||||
@@ -278,7 +277,6 @@ class FeatureService:
|
||||
system_features.is_allow_register = dify_config.ALLOW_REGISTER
|
||||
system_features.is_allow_create_workspace = dify_config.ALLOW_CREATE_WORKSPACE
|
||||
system_features.is_email_setup = dify_config.MAIL_TYPE is not None and dify_config.MAIL_TYPE != ""
|
||||
system_features.trial_models = cls._fulfill_trial_models_from_env()
|
||||
system_features.enable_trial_app = dify_config.ENABLE_TRIAL_APP
|
||||
system_features.enable_explore_banner = dify_config.ENABLE_EXPLORE_BANNER
|
||||
|
||||
@@ -293,6 +291,11 @@ class FeatureService:
|
||||
)
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def get_trial_models(cls) -> list[str]:
|
||||
"""Return hosted trial provider ids without requiring the full system-features payload."""
|
||||
return cls._fulfill_trial_models_from_env()
|
||||
|
||||
@classmethod
|
||||
def _fulfill_params_from_env(cls, features: FeatureModel):
|
||||
features.can_replace_logo = dify_config.CAN_REPLACE_LOGO
|
||||
|
||||
@@ -46,6 +46,22 @@ class TestFeatureVectorSpaceApi:
|
||||
get_vector_space.assert_called_once_with("tenant_123")
|
||||
|
||||
|
||||
class TestTrialModelsApi:
|
||||
def test_get_trial_models_success(self, mocker: MockerFixture):
|
||||
from controllers.console.feature import TrialModelsApi
|
||||
|
||||
get_trial_models = mocker.patch("controllers.console.feature.FeatureService.get_trial_models")
|
||||
get_trial_models.return_value = ["langgenius/openai/openai"]
|
||||
|
||||
api = TrialModelsApi()
|
||||
|
||||
raw_get = unwrap(TrialModelsApi.get)
|
||||
result = raw_get(api)
|
||||
|
||||
assert result == {"trial_models": ["langgenius/openai/openai"]}
|
||||
get_trial_models.assert_called_once_with()
|
||||
|
||||
|
||||
class TestAppDslVersionApi:
|
||||
def test_get_app_dsl_version_success(self, mocker: MockerFixture):
|
||||
from controllers.console.feature import AppDslVersionApi
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import pytest
|
||||
|
||||
from enums.hosted_provider import HostedTrialProvider
|
||||
from services import feature_service as feature_service_module
|
||||
from services.feature_service import FeatureService
|
||||
|
||||
|
||||
def test_get_system_features_excludes_trial_models():
|
||||
result = FeatureService.get_system_features().model_dump()
|
||||
|
||||
assert "trial_models" not in result
|
||||
|
||||
|
||||
def test_get_trial_models_returns_providers_enabled_for_paid_and_trial(monkeypatch: pytest.MonkeyPatch):
|
||||
for provider in HostedTrialProvider:
|
||||
monkeypatch.setattr(
|
||||
feature_service_module.dify_config,
|
||||
f"HOSTED_{provider.config_key}_PAID_ENABLED",
|
||||
False,
|
||||
raising=False,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
feature_service_module.dify_config,
|
||||
f"HOSTED_{provider.config_key}_TRIAL_ENABLED",
|
||||
False,
|
||||
raising=False,
|
||||
)
|
||||
|
||||
monkeypatch.setattr(feature_service_module.dify_config, "HOSTED_OPENAI_PAID_ENABLED", True, raising=False)
|
||||
monkeypatch.setattr(feature_service_module.dify_config, "HOSTED_OPENAI_TRIAL_ENABLED", True, raising=False)
|
||||
monkeypatch.setattr(feature_service_module.dify_config, "HOSTED_ANTHROPIC_PAID_ENABLED", True, raising=False)
|
||||
monkeypatch.setattr(feature_service_module.dify_config, "HOSTED_ANTHROPIC_TRIAL_ENABLED", False, raising=False)
|
||||
monkeypatch.setattr(feature_service_module.dify_config, "HOSTED_GEMINI_PAID_ENABLED", False, raising=False)
|
||||
monkeypatch.setattr(feature_service_module.dify_config, "HOSTED_GEMINI_TRIAL_ENABLED", True, raising=False)
|
||||
|
||||
result = FeatureService.get_trial_models()
|
||||
|
||||
assert result == [HostedTrialProvider.OPENAI.value]
|
||||
Reference in New Issue
Block a user