mirror of
https://github.com/langgenius/dify.git
synced 2026-10-04 13:47:55 +08:00
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
30 lines
983 B
Python
30 lines
983 B
Python
"""Validation for effective user prompts produced by Agenton runs.
|
|
|
|
Validation happens after safe compositor construction and run entry so runtime
|
|
execution uses the same transformed prompts as the actual pydantic-ai input.
|
|
Blank string fragments do not count as meaningful input; non-string
|
|
``UserContent`` is treated as intentional content because rich media/message
|
|
parts do not have a universal whitespace representation.
|
|
"""
|
|
|
|
from collections.abc import Sequence
|
|
|
|
from pydantic_ai.messages import UserContent
|
|
|
|
|
|
EMPTY_USER_PROMPTS_ERROR = "run.user_prompts must not be empty"
|
|
|
|
|
|
def has_non_blank_user_prompt(user_prompts: Sequence[UserContent]) -> bool:
|
|
"""Return whether composed user prompts contain meaningful input."""
|
|
for prompt in user_prompts:
|
|
if isinstance(prompt, str):
|
|
if prompt.strip():
|
|
return True
|
|
else:
|
|
return True
|
|
return False
|
|
|
|
|
|
__all__ = ["EMPTY_USER_PROMPTS_ERROR", "has_non_blank_user_prompt"]
|