feat:自动剥离大模型返回的markdown代码围栏
This commit is contained in:
@@ -30,6 +30,13 @@ class HTMLGenerateRequest(BaseModel):
|
||||
ge=1,
|
||||
description="Optional retention days for the file.",
|
||||
)
|
||||
preserve_markdown_fence: bool = Field(
|
||||
default=False,
|
||||
description=(
|
||||
"When true, keeps outer Markdown code fences instead of stripping them "
|
||||
"from the HTML payload."
|
||||
),
|
||||
)
|
||||
|
||||
@root_validator(pre=True)
|
||||
def normalize_aliases(cls, values: dict) -> dict:
|
||||
@@ -73,6 +80,17 @@ class HTMLGenerateRequest(BaseModel):
|
||||
normalized = value.strip()
|
||||
return normalized or None
|
||||
|
||||
@validator("preserve_markdown_fence", pre=True)
|
||||
def normalize_preserve_markdown_fence(cls, value: bool | str | None) -> bool:
|
||||
if isinstance(value, bool):
|
||||
return value
|
||||
if value is None:
|
||||
return False
|
||||
if isinstance(value, str):
|
||||
return value.strip().lower() in {"1", "true", "yes", "on"}
|
||||
|
||||
return bool(value)
|
||||
|
||||
@validator("ttl_days")
|
||||
def validate_ttl_days(cls, value: int | None) -> int | None:
|
||||
if value is None:
|
||||
|
||||
Reference in New Issue
Block a user