更新金融配图生成规则

This commit is contained in:
maomomo
2026-06-28 22:40:10 +08:00
parent 86f4d6e744
commit 3895c9eb1d
18 changed files with 152 additions and 51 deletions
+74 -6
View File
@@ -88,6 +88,69 @@ def read_json(path: Path) -> Any:
return json.loads(read_text(path))
def strip_toml_comment(line: str) -> str:
quote = ""
escaped = False
for index, char in enumerate(line):
if escaped:
escaped = False
continue
if quote and char == "\\":
escaped = True
continue
if char in ("'", '"'):
if not quote:
quote = char
elif quote == char:
quote = ""
continue
if char == "#" and not quote:
return line[:index]
return line
def parse_toml_scalar(value: str) -> Any:
raw = strip_toml_comment(value).strip()
if len(raw) >= 2 and raw[0] == raw[-1] and raw[0] in ("'", '"'):
inner = raw[1:-1]
if raw[0] == '"':
return inner.replace(r"\"", '"').replace(r"\\", "\\")
return inner
if raw.lower() == "true":
return True
if raw.lower() == "false":
return False
return raw
def parse_basic_toml(text: str) -> Dict[str, Any]:
"""解析 Codex 配置需要的 TOML 子集,避免 Python 3.10 及以下缺少 tomllib。"""
data: Dict[str, Any] = {}
current: Dict[str, Any] = data
for raw_line in text.splitlines():
line = strip_toml_comment(raw_line).strip()
if not line:
continue
if line.startswith("[") and line.endswith("]"):
section = line.strip("[]").strip()
current = data
for part in section.split("."):
key = part.strip().strip("'\"")
if not key:
continue
child = current.get(key)
if not isinstance(child, dict):
child = {}
current[key] = child
current = child
continue
if "=" not in line:
continue
key, value = line.split("=", 1)
current[key.strip().strip("'\"")] = parse_toml_scalar(value)
return data
def load_prompt_file(path: Path) -> str:
text = read_text(path).strip()
stripped = text.lstrip()
@@ -110,14 +173,19 @@ def load_codex_config_base_url() -> Optional[str]:
config_path = Path.home() / ".codex" / "config.toml"
if not config_path.exists():
return None
text = read_text(config_path)
try:
import tomllib
data = tomllib.loads(text)
except ModuleNotFoundError:
return None
try:
data = tomllib.loads(read_text(config_path))
data = parse_basic_toml(text)
except Exception:
return None
data = parse_basic_toml(text)
try:
if not isinstance(data, dict):
data = parse_basic_toml(text)
except Exception:
data = parse_basic_toml(text)
provider_name = data.get("model_provider")
providers = data.get("model_providers")
@@ -210,8 +278,8 @@ def build_prompt(
f"核心文案:{core_text}",
f"画幅:{aspect_ratio}",
f"画面呈现:{style_prompt(style)}",
f"可见文字限制:画面只允许出现这些指定业务文案:{allowed_visible_text};不要添加副标题、风格标签、prompt 描述、说明文字、额外 slogan 或无关文字。",
"硬性要求:包含清晰可见的 MAOMOMO 标识;中文文字清楚可读;信息层级明确;港币金额统一使用 HKD 写法;不要伪造真实 App 截图;不要使用未经提供的银行、券商、支付机构或卡组织 Logo;没有明确素材或指令时,信用卡画无卡组织标识的通用卡,不要凭空加入 Mastercard、Visa、UnionPay 或其他支付网络;不要出现真实个人信息;猫咪不能承载第三方品牌 Logo。",
f"可见文字限制:画面只允许出现这些指定业务文案:{allowed_visible_text};如补充要求明确列出已核对的品牌或支付标识,可作为小型辅助标识出现;不要添加副标题、风格标签、prompt 描述、说明文字、额外 slogan 或无关文字。",
"硬性要求:包含清晰可见的 MAOMOMO 主标识;中文文字清楚可读;信息层级明确;港币金额统一使用 HKD 写法;不要伪造真实 App 截图;Mastercard、Visa、UnionPay、银行、支付宝等 Logo 或支付网络标识只有在官方材料、用户素材或补充要求明确核对正确时才可出现,并且只能作为辅助识别,不能抢占或替代 MAOMOMO 主标识位置;未确认时使用通用卡片或通用支付符号,不要凭空加入或替换卡组织;不要出现真实个人信息;猫咪不穿戴第三方 Logo。",
]
if extra.strip():
parts.append(f"补充要求:{extra.strip()}")