feat: Add MAX_ITEMS_LENGTH constant and implement list truncation in ResultDataResponse (#5807)
* feat: add MAX_ITEMS_LENGTH constant and implement list truncation in ResultDataResponse - Introduced a new constant MAX_ITEMS_LENGTH set to 1000 in constants.py. - Updated ResultDataResponse in schemas.py to truncate lists exceeding MAX_ITEMS_LENGTH, appending a message indicating the number of truncated items. * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
25ca57f53f
commit
3b8578ca8c
2 changed files with 7 additions and 1 deletions
|
|
@ -17,7 +17,7 @@ from langflow.services.database.models.flow import FlowCreate, FlowRead
|
||||||
from langflow.services.database.models.user import UserRead
|
from langflow.services.database.models.user import UserRead
|
||||||
from langflow.services.settings.feature_flags import FeatureFlags
|
from langflow.services.settings.feature_flags import FeatureFlags
|
||||||
from langflow.services.tracing.schema import Log
|
from langflow.services.tracing.schema import Log
|
||||||
from langflow.utils.constants import MAX_TEXT_LENGTH
|
from langflow.utils.constants import MAX_ITEMS_LENGTH, MAX_TEXT_LENGTH
|
||||||
from langflow.utils.util_strings import truncate_long_strings
|
from langflow.utils.util_strings import truncate_long_strings
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -312,6 +312,11 @@ class ResultDataResponse(BaseModel):
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
return {k: ResultDataResponse._serialize_and_truncate(v, max_length=max_length) for k, v in obj.items()}
|
return {k: ResultDataResponse._serialize_and_truncate(v, max_length=max_length) for k, v in obj.items()}
|
||||||
if isinstance(obj, list | tuple):
|
if isinstance(obj, list | tuple):
|
||||||
|
# If list is too long, truncate it
|
||||||
|
if len(obj) > MAX_ITEMS_LENGTH:
|
||||||
|
truncated_list = list(obj)[:MAX_ITEMS_LENGTH]
|
||||||
|
truncated_list.append(f"... [truncated {len(obj) - MAX_ITEMS_LENGTH} items]")
|
||||||
|
obj = truncated_list
|
||||||
return [ResultDataResponse._serialize_and_truncate(item, max_length=max_length) for item in obj]
|
return [ResultDataResponse._serialize_and_truncate(item, max_length=max_length) for item in obj]
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -175,3 +175,4 @@ MESSAGE_SENDER_NAME_AI = "AI"
|
||||||
MESSAGE_SENDER_NAME_USER = "User"
|
MESSAGE_SENDER_NAME_USER = "User"
|
||||||
|
|
||||||
MAX_TEXT_LENGTH = 20000
|
MAX_TEXT_LENGTH = 20000
|
||||||
|
MAX_ITEMS_LENGTH = 1000
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue