feat: support Java prompt_context passthrough (Plan A)
- content_generate_v2: use Java prompt_context if provided, fallback to local - topic_generate_v2: same passthrough support - Maintains backward compatibility with direct Python calls
This commit is contained in:
parent
73cc12fe65
commit
09bc862eee
@ -121,6 +121,9 @@ class ContentGenerateEngineV2(BaseAIGCEngine):
|
||||
self.log("开始生成内容 (V2)")
|
||||
self.set_progress(task_id, 10)
|
||||
|
||||
# 🎯 方案A: 检查是否有 Java 透传的 prompt_context
|
||||
prompt_context = params.get('prompt_context')
|
||||
|
||||
# 提取参数
|
||||
topic = params.get('topic', {})
|
||||
|
||||
@ -149,26 +152,37 @@ class ContentGenerateEngineV2(BaseAIGCEngine):
|
||||
# 获取 PromptRegistry
|
||||
prompt_registry = self._get_prompt_registry()
|
||||
|
||||
# 从 subject 提取产品信息
|
||||
current_product = None
|
||||
if subject and subject.get('products'):
|
||||
current_product = subject['products'][0]
|
||||
|
||||
# 如果没有用户指定的参考内容,加载内置参考文献库
|
||||
use_builtin_examples = not reference or reference.get('mode') == 'none'
|
||||
|
||||
# 构建 prompt 上下文
|
||||
context = {
|
||||
'style_content': self._format_style(style, topic),
|
||||
'demand_content': self._format_audience(audience, topic),
|
||||
'object_content': self._format_subject(subject, topic),
|
||||
'product_content': self._format_product(current_product),
|
||||
'hot_topics': hot_topics,
|
||||
'reference': reference,
|
||||
# 内置参考文献 (仅在无用户指定参考时使用)
|
||||
'title_examples': self._get_title_examples(20) if use_builtin_examples else None,
|
||||
'content_examples': self._get_content_examples(3) if use_builtin_examples else None,
|
||||
}
|
||||
# 🎯 方案A: 如果有 Java 透传的 context,直接使用;否则本地构建
|
||||
if prompt_context:
|
||||
self.log("使用 Java 透传的 prompt_context")
|
||||
context = prompt_context
|
||||
# 补充可能缺少的字段
|
||||
if 'hot_topics' not in context and hot_topics:
|
||||
context['hot_topics'] = hot_topics
|
||||
if 'reference' not in context and reference:
|
||||
context['reference'] = reference
|
||||
else:
|
||||
self.log("使用本地构建的 context (兼容模式)")
|
||||
# 从 subject 提取产品信息
|
||||
current_product = None
|
||||
if subject and subject.get('products'):
|
||||
current_product = subject['products'][0]
|
||||
|
||||
# 如果没有用户指定的参考内容,加载内置参考文献库
|
||||
use_builtin_examples = not reference or reference.get('mode') == 'none'
|
||||
|
||||
# 构建 prompt 上下文
|
||||
context = {
|
||||
'style_content': self._format_style(style, topic),
|
||||
'demand_content': self._format_audience(audience, topic),
|
||||
'object_content': self._format_subject(subject, topic),
|
||||
'product_content': self._format_product(current_product),
|
||||
'hot_topics': hot_topics,
|
||||
'reference': reference,
|
||||
# 内置参考文献 (仅在无用户指定参考时使用)
|
||||
'title_examples': self._get_title_examples(20) if use_builtin_examples else None,
|
||||
'content_examples': self._get_content_examples(3) if use_builtin_examples else None,
|
||||
}
|
||||
|
||||
# 渲染 prompt
|
||||
system_prompt, user_prompt = prompt_registry.render(
|
||||
|
||||
@ -158,20 +158,35 @@ class TopicGenerateEngineV2(BaseAIGCEngine):
|
||||
# 获取 PromptRegistry
|
||||
prompt_registry = self._get_prompt_registry()
|
||||
|
||||
# 构建 prompt 上下文
|
||||
context = {
|
||||
'num_topics': num_topics,
|
||||
'month': month,
|
||||
'subject': subject,
|
||||
# 兼容旧 prompt 模板
|
||||
'scenic_spot': subject,
|
||||
'product': subject.get('products', [{}])[0] if subject and subject.get('products') else product,
|
||||
'style': style,
|
||||
'audience': audience,
|
||||
'hot_topics': hot_topics,
|
||||
'styles_list': self._format_list(styles_list),
|
||||
'audiences_list': self._format_list(audiences_list),
|
||||
}
|
||||
# 🎯 方案A: 检查是否有 Java 透传的 prompt_context
|
||||
prompt_context = params.get('prompt_context')
|
||||
|
||||
if prompt_context:
|
||||
self.log("使用 Java 透传的 prompt_context")
|
||||
context = prompt_context
|
||||
# 补充必要字段
|
||||
if 'num_topics' not in context:
|
||||
context['num_topics'] = num_topics
|
||||
if 'month' not in context:
|
||||
context['month'] = month
|
||||
if 'hot_topics' not in context and hot_topics:
|
||||
context['hot_topics'] = hot_topics
|
||||
else:
|
||||
self.log("使用本地构建的 context (兼容模式)")
|
||||
# 构建 prompt 上下文
|
||||
context = {
|
||||
'num_topics': num_topics,
|
||||
'month': month,
|
||||
'subject': subject,
|
||||
# 兼容旧 prompt 模板
|
||||
'scenic_spot': subject,
|
||||
'product': subject.get('products', [{}])[0] if subject and subject.get('products') else product,
|
||||
'style': style,
|
||||
'audience': audience,
|
||||
'hot_topics': hot_topics,
|
||||
'styles_list': self._format_list(styles_list),
|
||||
'audiences_list': self._format_list(audiences_list),
|
||||
}
|
||||
|
||||
# 渲染 prompt
|
||||
system_prompt, user_prompt = prompt_registry.render(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user