chore/ 删除无用文件
This commit is contained in:
@@ -82,7 +82,9 @@ def split_narrative_to_sections(narrative: str) -> list[dict[str, Any]]:
|
||||
content = narrative[start:end]
|
||||
if isinstance(content, str):
|
||||
content = content.strip()
|
||||
sections.append({"content": content or "", "placeholder_info": placeholder_info})
|
||||
sections.append(
|
||||
{"content": content or "", "placeholder_info": placeholder_info}
|
||||
)
|
||||
return sections
|
||||
|
||||
|
||||
|
||||
@@ -42,7 +42,9 @@ class MemoirImagePromptService:
|
||||
description: str,
|
||||
context_excerpt: str,
|
||||
) -> dict[str, str]:
|
||||
style = self.CATEGORY_STYLE_MAP.get(chapter_category, self.settings.default_style)
|
||||
style = self.CATEGORY_STYLE_MAP.get(
|
||||
chapter_category, self.settings.default_style
|
||||
)
|
||||
prompt_context = f"{chapter_category}: {chapter_title}"
|
||||
|
||||
llm_input = {
|
||||
@@ -69,7 +71,9 @@ class MemoirImagePromptService:
|
||||
raw_response = response.content
|
||||
parsed = json.loads(extract_json_payload(raw_response))
|
||||
return {
|
||||
"prompt": _ensure_style_in_prompt(parsed["prompt"], parsed.get("style", style)),
|
||||
"prompt": _ensure_style_in_prompt(
|
||||
parsed["prompt"], parsed.get("style", style)
|
||||
),
|
||||
"style": parsed.get("style", style),
|
||||
"size": parsed.get("size", self.settings.default_size),
|
||||
"prompt_context": prompt_context,
|
||||
@@ -104,7 +108,9 @@ class MemoirImagePromptService:
|
||||
context_excerpt: str,
|
||||
) -> dict[str, str]:
|
||||
"""生成章节封面图的 image-generation prompt。"""
|
||||
style = self.CATEGORY_STYLE_MAP.get(chapter_category, self.settings.default_style)
|
||||
style = self.CATEGORY_STYLE_MAP.get(
|
||||
chapter_category, self.settings.default_style
|
||||
)
|
||||
prompt_context = f"{chapter_category}: {chapter_title}"
|
||||
|
||||
llm_input = {
|
||||
@@ -189,14 +195,18 @@ class MemoirImagePromptService:
|
||||
context_excerpt: str,
|
||||
style: str,
|
||||
) -> str:
|
||||
subject = self.CATEGORY_FALLBACK_SUBJECT_MAP.get(chapter_category, "memoir scene")
|
||||
subject = self.CATEGORY_FALLBACK_SUBJECT_MAP.get(
|
||||
chapter_category, "memoir scene"
|
||||
)
|
||||
if _contains_cjk(description) or _contains_cjk(context_excerpt):
|
||||
return (
|
||||
f"A {style} illustration of a {subject}, emotionally resonant, cinematic composition, "
|
||||
"authentic everyday details, natural lighting, expressive environment, no text overlay."
|
||||
)
|
||||
|
||||
details = ". ".join(part.strip() for part in (description, context_excerpt) if part.strip())
|
||||
details = ". ".join(
|
||||
part.strip() for part in (description, context_excerpt) if part.strip()
|
||||
)
|
||||
if not details:
|
||||
details = "A personal life story scene with authentic emotional detail"
|
||||
return (
|
||||
|
||||
@@ -3,6 +3,7 @@ LiblibImageProvider 已迁至 app.adapters.image_gen.liblib_provider;
|
||||
此处仅 re-export,以便 memoir 与 tasks 的既有引用不中断。
|
||||
Feature 应通过 port ImageGenerator + get_image_generator() 使用图生能力。
|
||||
"""
|
||||
|
||||
from app.adapters.image_gen.liblib_provider import LiblibImageProvider # noqa: F401
|
||||
|
||||
__all__ = ["LiblibImageProvider"]
|
||||
|
||||
@@ -13,7 +13,9 @@ VALID_IMAGE_STATUSES = {
|
||||
IMAGE_STATUS_FAILED,
|
||||
}
|
||||
|
||||
_PLACEHOLDER_DESCRIPTION_RE = re.compile(r"\{\{\{\{IMAGE:(.*?)\}\}\}\}|\{\{IMAGE:(.*?)\}\}")
|
||||
_PLACEHOLDER_DESCRIPTION_RE = re.compile(
|
||||
r"\{\{\{\{IMAGE:(.*?)\}\}\}\}|\{\{IMAGE:(.*?)\}\}"
|
||||
)
|
||||
|
||||
|
||||
def normalize_image_asset(asset: dict[str, Any] | None) -> dict[str, Any] | None:
|
||||
@@ -21,9 +23,9 @@ def normalize_image_asset(asset: dict[str, Any] | None) -> dict[str, Any] | None
|
||||
return None
|
||||
|
||||
placeholder = _as_non_empty_string(asset.get("placeholder"))
|
||||
description = _as_non_empty_string(asset.get("description")) or _extract_description_from_placeholder(
|
||||
placeholder
|
||||
)
|
||||
description = _as_non_empty_string(
|
||||
asset.get("description")
|
||||
) or _extract_description_from_placeholder(placeholder)
|
||||
if not placeholder or not description:
|
||||
return None
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
MemoirImage 模型与 API 用 dict 的互转(与 schema.normalize_image_asset 字段一致)。
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
|
||||
@@ -55,7 +55,9 @@ class MemoirImageSettings:
|
||||
base_max = max(self.max_per_chapter, 0)
|
||||
effective_cap = max(self.max_images_cap, base_max)
|
||||
safe_length = max(content_length, 0)
|
||||
extra = safe_length // self.chars_per_extra_image if self.chars_per_extra_image > 0 else 0
|
||||
extra = (
|
||||
safe_length // self.chars_per_extra_image
|
||||
if self.chars_per_extra_image > 0
|
||||
else 0
|
||||
)
|
||||
return min(base_max + extra, effective_cap)
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,9 @@ def normalize_cos_base_url(base_url: str, bucket: str, region: str) -> str:
|
||||
return candidate
|
||||
|
||||
|
||||
def normalize_cos_url(url: str | None, bucket: str, region: str, base_url: str | None = None) -> str | None:
|
||||
def normalize_cos_url(
|
||||
url: str | None, bucket: str, region: str, base_url: str | None = None
|
||||
) -> str | None:
|
||||
if not url:
|
||||
return url
|
||||
|
||||
@@ -43,7 +45,11 @@ def normalize_cos_url(url: str | None, bucket: str, region: str, base_url: str |
|
||||
return url
|
||||
|
||||
normalized_parsed = urlparse(normalized_base)
|
||||
return urlunparse(parsed._replace(scheme=normalized_parsed.scheme, netloc=normalized_parsed.netloc))
|
||||
return urlunparse(
|
||||
parsed._replace(
|
||||
scheme=normalized_parsed.scheme, netloc=normalized_parsed.netloc
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def resolve_image_storage_key(image: dict | None) -> str | None:
|
||||
|
||||
Reference in New Issue
Block a user