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