refactor(api): update /config endpoint to use ConfigResponse.from_settings (#8674)
* refactor: update config response handling and import structure - Moved EventManager import to the correct module path. - Refactored get_config endpoint to utilize ConfigResponse.from_settings for improved clarity and maintainability. - Updated ConfigResponse to include a class method for instantiating from Settings, enhancing the encapsulation of configuration logic. * 📝 Add docstrings to `improve-docs-and-configsetup` (#8677) Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
e64e328257
commit
b17871bf44
2 changed files with 45 additions and 25 deletions
|
|
@ -49,13 +49,12 @@ from langflow.services.database.models.flow.model import Flow, FlowRead
|
||||||
from langflow.services.database.models.flow.utils import get_all_webhook_components_in_flow
|
from langflow.services.database.models.flow.utils import get_all_webhook_components_in_flow
|
||||||
from langflow.services.database.models.user.model import User, UserRead
|
from langflow.services.database.models.user.model import User, UserRead
|
||||||
from langflow.services.deps import get_session_service, get_settings_service, get_telemetry_service
|
from langflow.services.deps import get_session_service, get_settings_service, get_telemetry_service
|
||||||
from langflow.services.settings.feature_flags import FEATURE_FLAGS
|
|
||||||
from langflow.services.telemetry.schema import RunPayload
|
from langflow.services.telemetry.schema import RunPayload
|
||||||
from langflow.utils.compression import compress_response
|
from langflow.utils.compression import compress_response
|
||||||
from langflow.utils.version import get_version_info
|
from langflow.utils.version import get_version_info
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from langflow.services.event_manager import EventManager
|
from langflow.events.event_manager import EventManager
|
||||||
from langflow.services.settings.service import SettingsService
|
from langflow.services.settings.service import SettingsService
|
||||||
|
|
||||||
router = APIRouter(tags=["Base"])
|
router = APIRouter(tags=["Base"])
|
||||||
|
|
@ -681,22 +680,13 @@ async def custom_component_update(
|
||||||
code_request: UpdateCustomComponentRequest,
|
code_request: UpdateCustomComponentRequest,
|
||||||
user: CurrentActiveUser,
|
user: CurrentActiveUser,
|
||||||
):
|
):
|
||||||
"""Update a custom component with the provided code request.
|
"""Update an existing custom component with new code and configuration.
|
||||||
|
|
||||||
This endpoint generates the CustomComponentFrontendNode normally but then runs the `update_build_config` method
|
Processes the provided code and template updates, applies parameter changes (including those loaded from the database), updates the component's build configuration, and validates outputs. Returns the updated component node as a JSON-serializable dictionary.
|
||||||
on the latest version of the template.
|
|
||||||
This ensures that every time it runs, it has the latest version of the template.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
code_request (CustomComponentRequest): The code request containing the updated code for the custom component.
|
|
||||||
user (User, optional): The user making the request. Defaults to the current active user.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
dict: The updated custom component node.
|
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
HTTPException: If there's an error building or updating the component
|
HTTPException: If an error occurs during component building or updating.
|
||||||
SerializationError: If there's an error serializing the component to JSON
|
SerializationError: If serialization of the updated component node fails.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
component = Component(_code=code_request.code)
|
component = Component(_code=code_request.code)
|
||||||
|
|
@ -752,14 +742,19 @@ async def custom_component_update(
|
||||||
raise SerializationError.from_exception(exc, data=component_node) from exc
|
raise SerializationError.from_exception(exc, data=component_node) from exc
|
||||||
|
|
||||||
|
|
||||||
@router.get("/config", response_model=ConfigResponse)
|
@router.get("/config")
|
||||||
async def get_config():
|
async def get_config() -> ConfigResponse:
|
||||||
|
"""Retrieve the current application configuration settings.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
ConfigResponse: The configuration settings of the application.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
HTTPException: If an error occurs while retrieving the configuration.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
settings_service: SettingsService = get_settings_service()
|
settings_service: SettingsService = get_settings_service()
|
||||||
|
return ConfigResponse.from_settings(settings_service.settings)
|
||||||
|
|
||||||
return {
|
|
||||||
"feature_flags": FEATURE_FLAGS,
|
|
||||||
**settings_service.settings.model_dump(),
|
|
||||||
}
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise HTTPException(status_code=500, detail=str(exc)) from exc
|
raise HTTPException(status_code=500, detail=str(exc)) from exc
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,13 @@ from langflow.graph.schema import RunOutputs
|
||||||
from langflow.schema.dotdict import dotdict
|
from langflow.schema.dotdict import dotdict
|
||||||
from langflow.schema.graph import Tweaks
|
from langflow.schema.graph import Tweaks
|
||||||
from langflow.schema.schema import InputType, OutputType, OutputValue
|
from langflow.schema.schema import InputType, OutputType, OutputValue
|
||||||
from langflow.serialization import constants as serialization_constants
|
|
||||||
from langflow.serialization.serialization import get_max_items_length, get_max_text_length, serialize
|
from langflow.serialization.serialization import get_max_items_length, get_max_text_length, serialize
|
||||||
from langflow.services.database.models.api_key.model import ApiKeyRead
|
from langflow.services.database.models.api_key.model import ApiKeyRead
|
||||||
from langflow.services.database.models.base import orjson_dumps
|
from langflow.services.database.models.base import orjson_dumps
|
||||||
from langflow.services.database.models.flow.model import FlowCreate, FlowRead
|
from langflow.services.database.models.flow.model import FlowCreate, FlowRead
|
||||||
from langflow.services.database.models.user.model import UserRead
|
from langflow.services.database.models.user.model import UserRead
|
||||||
from langflow.services.settings.feature_flags import FeatureFlags
|
from langflow.services.settings.base import Settings
|
||||||
|
from langflow.services.settings.feature_flags import FEATURE_FLAGS, FeatureFlags
|
||||||
from langflow.services.tracing.schema import Log
|
from langflow.services.tracing.schema import Log
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -395,8 +395,8 @@ class FlowDataRequest(BaseModel):
|
||||||
|
|
||||||
class ConfigResponse(BaseModel):
|
class ConfigResponse(BaseModel):
|
||||||
feature_flags: FeatureFlags
|
feature_flags: FeatureFlags
|
||||||
serialization_max_items_length: int = serialization_constants.MAX_ITEMS_LENGTH
|
serialization_max_items_length: int
|
||||||
serialization_max_text_length: int = serialization_constants.MAX_TEXT_LENGTH
|
serialization_max_text_length: int
|
||||||
frontend_timeout: int
|
frontend_timeout: int
|
||||||
auto_saving: bool
|
auto_saving: bool
|
||||||
auto_saving_interval: int
|
auto_saving_interval: int
|
||||||
|
|
@ -407,6 +407,31 @@ class ConfigResponse(BaseModel):
|
||||||
public_flow_expiration: int
|
public_flow_expiration: int
|
||||||
event_delivery: Literal["polling", "streaming", "direct"]
|
event_delivery: Literal["polling", "streaming", "direct"]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_settings(cls, settings: Settings) -> "ConfigResponse":
|
||||||
|
"""Create a ConfigResponse instance using values from a Settings object and global feature flags.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
settings (Settings): The Settings object containing configuration values.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
ConfigResponse: An instance populated with configuration and feature flag values.
|
||||||
|
"""
|
||||||
|
return cls(
|
||||||
|
feature_flags=FEATURE_FLAGS,
|
||||||
|
serialization_max_items_length=settings.max_items_length,
|
||||||
|
serialization_max_text_length=settings.max_text_length,
|
||||||
|
frontend_timeout=settings.frontend_timeout,
|
||||||
|
auto_saving=settings.auto_saving,
|
||||||
|
auto_saving_interval=settings.auto_saving_interval,
|
||||||
|
health_check_max_retries=settings.health_check_max_retries,
|
||||||
|
max_file_size_upload=settings.max_file_size_upload,
|
||||||
|
webhook_polling_interval=settings.webhook_polling_interval,
|
||||||
|
public_flow_cleanup_interval=settings.public_flow_cleanup_interval,
|
||||||
|
public_flow_expiration=settings.public_flow_expiration,
|
||||||
|
event_delivery=settings.event_delivery,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class CancelFlowResponse(BaseModel):
|
class CancelFlowResponse(BaseModel):
|
||||||
"""Response model for flow build cancellation."""
|
"""Response model for flow build cancellation."""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue