优化已发现问题

This commit is contained in:
Azmat@qq.com
2026-09-18 14:51:57 +08:00
parent abccf4393a
commit b5d970a4b5
8 changed files with 1080 additions and 236 deletions
+114 -1
View File
@@ -1993,6 +1993,14 @@ class CreationConversationViewSet(TeamScopedViewSetMixin, ModelViewSet):
pending.save(update_fields=["payload", "updated_at"])
if is_product_gate:
_mark_product_source_resolved(conversation)
is_character_gate = any(t in ("character", "model") for t in asset_types)
if is_character_gate:
memory = dict(conversation.memory or {})
memory["person_source"] = "auto"
memory["person_source_ready"] = True
memory["person_source_pending"] = False
conversation.memory = memory
conversation.save(update_fields=["memory", "updated_at"])
force_creative_turn = True
if hits:
@@ -2089,6 +2097,24 @@ class CreationConversationViewSet(TeamScopedViewSetMixin, ModelViewSet):
continuation_instruction = apply_pain_point_direction(
conversation, payload, choice
)
elif payload.get("topic") == "product_info":
clean_ans = text.strip()
memory = dict(conversation.memory or {})
memory["product_info_resolved"] = True
if clean_ans and not any(kw in clean_ans for kw in ("按图片", "设计品牌", "不用再问")):
memory["product_brand_and_name"] = clean_ans
for r in (conversation.pinned_refs or []):
if isinstance(r, dict) and r.get("type") in ("asset", "product"):
r["name"] = clean_ans
break
conversation.pinned_refs = conversation.pinned_refs
continuation_instruction = f"用户已提供商品品牌与品名:【{clean_ans}】。直接围绕该商品推进方案,不要重复追问。"
else:
continuation_instruction = "用户要求直接根据图片内容设计品牌与品名推进创作。直接基于图片外观特征推进方案,不要重复追问品牌。"
conversation.memory = memory
conversation.save(update_fields=["memory", "pinned_refs", "updated_at"])
text = ""
record_user_message = False
else:
continuation_instruction = (
"用户刚用输入框回答了你上一句问题。直接基于这条真实回答继续原任务;"
@@ -2097,6 +2123,30 @@ class CreationConversationViewSet(TeamScopedViewSetMixin, ModelViewSet):
if params_changed:
continuation_instruction += " 会话参数已更新,旧方案作废,按新参数重新产出。"
# 用户对刚生成的角色给出确认/重刷反馈
clean_text = text.strip()
if re.search(r"^(使用这[个位只]角色|就用这[个位只]角色|就用[她他它]|满意|确认使用|合适|可以)[继续创作。!! ]*$", clean_text) or clean_text in ("使用这个角色继续创作", "使用这个宠物角色继续创作"):
force_creative_turn = True
continuation_instruction = (
"用户已确认使用当前生成的角色出镜。直接基于该角色继续推进创作方案"
"(若尚未选商品则确定商品,已选好商品则开始写创作策略和方案),不要再次追问角色来源。"
)
elif re.search(r"^(重新生成|再生成|重刷|换一个|换位|不满意).{0,6}(角色|人物|模特|宠物)?[。!! ]*$", clean_text) and (conversation.memory or {}).get("person_source") == "platform_generate":
person_prompt = str((conversation.memory or {}).get("person_prompt") or "").strip()
try:
generating = submit_generated_person_reference(
conversation=conversation,
user=request.user,
appearance_prompt=person_prompt,
)
return JsonResponse({
"conversation_id": str(conversation.id),
"agent_status": conversation.agent_status,
"messages": [CreationMessageSerializer(generating).data],
}, status=202)
except Exception:
pass
if kind == "confirm":
reply_to = str(request.data.get("reply_to") or "").strip()
card = conversation.messages.filter(
@@ -2215,7 +2265,7 @@ class CreationConversationViewSet(TeamScopedViewSetMixin, ModelViewSet):
]
valid = any(
AssetModel.objects.filter(
team=conversation.team,
Q(team=conversation.team) | Q(is_official=True),
id=ref.get("id"),
is_deleted=False,
purged_at__isnull=True,
@@ -2322,10 +2372,12 @@ class CreationConversationViewSet(TeamScopedViewSetMixin, ModelViewSet):
elif payload.get("interaction") == "person_source_gate":
source = str(answers.get("person_source") or "").strip()
if source == "platform_generate":
person_prompt = str(answers.get("person_prompt") or "").strip()[:500]
try:
generating = submit_generated_person_reference(
conversation=conversation,
user=request.user,
appearance_prompt=person_prompt,
)
except ValueError as exc:
# 生图没提交成功,把闸门放回去供用户换方式或重试。
@@ -2357,10 +2409,40 @@ class CreationConversationViewSet(TeamScopedViewSetMixin, ModelViewSet):
text = ""
record_user_message = False
force_creative_turn = True
is_pet = "宠物" in str(conversation.preset or "")
continuation_instruction = (
"用户已选定出镜宠物角色,该宠物形象已作为整条视频的固定身份参考。"
"直接继续创作;所有镜头和分段保持同一宠物,不要再追问角色来源。"
if is_pet else
"用户已选定出镜人物,该人物已作为整条视频的固定身份参考。"
"直接继续创作;所有镜头和分段保持同一人,不要再追问人物来源。"
)
elif payload.get("topic") == "product_info":
ans = str(answers.get("product_brand_and_name") or "").strip()
memory = dict(conversation.memory or {})
memory["product_info_resolved"] = True
clean_ans = ans.replace("品牌是:,商品名是:", "").strip()
if clean_ans and not any(kw in clean_ans for kw in ("按图片", "设计品牌", "不用再问")):
memory["product_brand_and_name"] = clean_ans
bm = re.search(r"品牌[::是为]?\s*([^\n,,。!!]+)", clean_ans)
nm = re.search(r"(?:品名|商品名|产品名)[::是为]?\s*([^\n,,。!!]+)", clean_ans)
if bm:
memory["product_brand"] = bm.group(1).strip()
if nm:
memory["product_name"] = nm.group(1).strip()
for r in (conversation.pinned_refs or []):
if isinstance(r, dict) and r.get("type") in ("asset", "product"):
r["name"] = clean_ans
break
conversation.pinned_refs = conversation.pinned_refs
continuation_instruction = f"用户已提供商品品牌与品名:【{clean_ans}】。直接围绕该商品推进方案,不要重复追问。"
else:
continuation_instruction = "用户要求直接根据图片内容设计品牌与品名推进创作。直接基于图片外观特征推进方案,不要重复追问品牌。"
conversation.memory = memory
conversation.save(update_fields=["memory", "pinned_refs", "updated_at"])
text = ""
record_user_message = False
force_creative_turn = True
elif payload.get("phase") == "gate":
choice = str(answers.get("_asset_gate") or "").strip()
pending = payload.get("pending_fields") or []
@@ -2411,6 +2493,14 @@ class CreationConversationViewSet(TeamScopedViewSetMixin, ModelViewSet):
force_creative_turn = True
if is_product_gate:
_mark_product_source_resolved(conversation)
is_character_gate = any(t in ("character", "model") for t in gate_types)
if is_character_gate:
memory = dict(conversation.memory or {})
memory["person_source"] = "auto"
memory["person_source_ready"] = True
memory["person_source_pending"] = False
conversation.memory = memory
conversation.save(update_fields=["memory", "updated_at"])
else:
# 卡片本身已经记录了用户的选择。不要再伪造一条黑色用户气泡;
# 继续原任务,并明确告诉模型不要再次追问同一项素材。
@@ -2423,6 +2513,29 @@ class CreationConversationViewSet(TeamScopedViewSetMixin, ModelViewSet):
"用户刚选择暂不添加这项素材。接受这个选择,按会话里已有的需求和合理默认继续原任务。"
"先用一句自然的话承接,随后直接推进创作;不要再次追问同一素材,不要只说收到或有需要再说。"
)
elif payload.get("phase") == "pick" and (
answers.get("_action") == "cancel"
or any(str(v).lower() in ("cancel", "取消", "skip", "跳过") for v in answers.values())
):
pick_fields = payload.get("fields") or []
primary = pick_fields[0] if pick_fields else {}
types = primary.get("asset_types") or []
key = str(primary.get("key") or "").strip()
if "product" in types or key == "product":
_mark_product_source_resolved(conversation)
if any(t in types for t in ("character", "model")) or key in ("character", "model", "person"):
memory = dict(conversation.memory or {})
memory["person_source_ready"] = True
memory["person_source_pending"] = False
conversation.memory = memory
conversation.save(update_fields=["memory", "updated_at"])
text = ""
record_user_message = False
force_creative_turn = True
continuation_instruction = (
"用户取消了从列表选择素材(素材库暂无合适素材或用户放弃选择)。"
"接受这个选择,根据会话里已有的需求和合理默认继续推进原任务,不要重复追问同一项素材。"
)
else:
params_changed = apply_session_params(conversation, payload.get("fields") or [], answers)
# 点选商品/角色必须钉成 Ref:模型常把选项做成单选文字,前端只回 answers。