feat: support old title placeholder in title prompts
This commit is contained in:
@@ -127,11 +127,7 @@ def gen_title(
|
||||
payload = _chat_payload(
|
||||
model,
|
||||
[
|
||||
{"role": "system", "content": str(title_prompt or "").strip()},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "旧标题:\n%s\n\n请只返回新标题,不要解释。" % str(old_title or ""),
|
||||
},
|
||||
{"role": "user", "content": _compose_title_prompt(title_prompt, old_title)},
|
||||
],
|
||||
)
|
||||
attempts = _attempt_count(ai_cfg, retry)
|
||||
@@ -840,7 +836,7 @@ def _gen_title_cmhub(
|
||||
resolution = _normalize_cmhub_resolution(ai_cfg.get("resolution", "1k"))
|
||||
_notify_step(on_step, "title_build_request")
|
||||
payload = {
|
||||
"prompt": _cmhub_title_prompt(title_prompt, old_title),
|
||||
"prompt": _compose_title_prompt(title_prompt, old_title),
|
||||
"model": runtime["alias"],
|
||||
"resolution": resolution,
|
||||
}
|
||||
@@ -1045,11 +1041,16 @@ def _cmhub_runtime(config, operation, cmhub_config_path):
|
||||
}
|
||||
|
||||
|
||||
def _cmhub_title_prompt(title_prompt, old_title):
|
||||
return "%s\n\n旧标题:\n%s\n\n请只返回新标题,不要解释。" % (
|
||||
str(title_prompt or "").strip(),
|
||||
str(old_title or ""),
|
||||
)
|
||||
def _compose_title_prompt(title_prompt, old_title):
|
||||
prompt = str(title_prompt or "").strip()
|
||||
old_title_text = str(old_title or "")
|
||||
if "{旧标题}" in prompt:
|
||||
body = prompt.replace("{旧标题}", old_title_text).strip()
|
||||
else:
|
||||
body = "%s\n\n旧标题:\n%s" % (prompt, old_title_text)
|
||||
if body:
|
||||
return "%s\n\n请只返回新标题,不要解释。" % body
|
||||
return "请只返回新标题,不要解释。"
|
||||
|
||||
|
||||
def _normalize_cmhub_resolution(resolution):
|
||||
|
||||
@@ -61,6 +61,8 @@ class GenerateTab(QWidget):
|
||||
prompts.load_title_prompt(self.title_prompt_path)
|
||||
)
|
||||
self.save_title_button = QPushButton("保存标题提示词")
|
||||
self.insert_old_title_button = QPushButton("插入旧标题")
|
||||
self.insert_old_title_button.setObjectName("insertOldTitleButton")
|
||||
self.cover_prompt_edit = QPlainTextEdit()
|
||||
self.cover_prompt_edit.setObjectName("coverPromptEdit")
|
||||
self.cover_prompt_edit.setPlaceholderText("封面提示词")
|
||||
@@ -115,7 +117,11 @@ class GenerateTab(QWidget):
|
||||
left_layout.setContentsMargins(0, 0, 12, 0)
|
||||
left_layout.addWidget(QLabel("标题提示词"))
|
||||
left_layout.addWidget(self.title_prompt_edit, 1)
|
||||
left_layout.addWidget(self.save_title_button)
|
||||
title_action_layout = QHBoxLayout()
|
||||
title_action_layout.addWidget(self.save_title_button)
|
||||
title_action_layout.addWidget(self.insert_old_title_button)
|
||||
title_action_layout.addStretch(1)
|
||||
left_layout.addLayout(title_action_layout)
|
||||
left_layout.addWidget(QLabel("封面提示词"))
|
||||
left_layout.addWidget(self.cover_template_combo)
|
||||
cover_template_layout = QHBoxLayout()
|
||||
@@ -230,6 +236,7 @@ class GenerateTab(QWidget):
|
||||
self.status_filter.currentIndexChanged.connect(self.refresh_tasks)
|
||||
self.refresh_button.clicked.connect(self.refresh_tasks)
|
||||
self.save_title_button.clicked.connect(self.save_title_prompt)
|
||||
self.insert_old_title_button.clicked.connect(self.insert_old_title_placeholder)
|
||||
self.cover_template_combo.currentIndexChanged.connect(self.load_selected_cover_template)
|
||||
self.new_cover_template_button.clicked.connect(self.new_cover_template)
|
||||
self.save_cover_template_button.clicked.connect(self.save_cover_template)
|
||||
@@ -454,6 +461,9 @@ class GenerateTab(QWidget):
|
||||
def insert_title_placeholder(self, checked=False):
|
||||
self.cover_prompt_edit.insertPlainText("{新标题}")
|
||||
|
||||
def insert_old_title_placeholder(self, checked=False):
|
||||
self.title_prompt_edit.insertPlainText("{旧标题}")
|
||||
|
||||
def preview_cover_prompt(self, checked=False):
|
||||
task = self._selected_task()
|
||||
if task is None:
|
||||
|
||||
Reference in New Issue
Block a user