包含七步编排入口、结构化/向量化/聚类/词频/报告模块与 prompts 配置;忽略原始 CSV 与本地密钥。 Co-authored-by: Cursor <cursoragent@cursor.com>
59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
"""
|
|
结构化提取 Prompt 入口(外置 prompts/ 目录,每次调用重读磁盘)。
|
|
|
|
对外 API 保持不变,供 结构化_server.py 动态加载。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from typing import List, Tuple
|
|
|
|
from prompts.loader import (
|
|
build_batch_extraction_system,
|
|
build_batch_extraction_user,
|
|
build_single_extraction_template,
|
|
format_examples,
|
|
)
|
|
|
|
|
|
def build_batch_review_analysis_prompts(
|
|
industry: str,
|
|
product_name: str,
|
|
keys: List[str],
|
|
tagged_input: str,
|
|
) -> Tuple[str, str]:
|
|
"""
|
|
生成批量评论分析用的 (system_prompt, user_prompt)。
|
|
tagged_input 形如多行 "[C1] ...\\n[C2] ...";模型须输出仅含这些键的 JSON 对象。
|
|
"""
|
|
keys_literal = ", ".join(json.dumps(k) for k in keys)
|
|
n_keys = len(keys)
|
|
system_prompt = build_batch_extraction_system(
|
|
industry,
|
|
product_name,
|
|
n_keys=n_keys,
|
|
keys_literal=keys_literal,
|
|
)
|
|
user_prompt = build_batch_extraction_user(
|
|
n_keys=n_keys,
|
|
keys_literal=keys_literal,
|
|
tagged_input=tagged_input,
|
|
)
|
|
return system_prompt, user_prompt
|
|
|
|
|
|
def generate_extraction_prompt_template(industry: str = "行业", product_name: str = "产品") -> str:
|
|
"""
|
|
根据行业和产品名,动态生成适合大模型结构化提取的 Prompt 模版。
|
|
返回的字符串中包含 {review_content} 占位符,供后续批量处理时填入真实评论。
|
|
"""
|
|
return build_single_extraction_template(industry, product_name)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
general_prompt = generate_extraction_prompt_template(
|
|
industry="线上教育及宠物用品",
|
|
product_name="综合商品",
|
|
)
|
|
print("============== Prompt 预览 ==============\n")
|
|
print(general_prompt)
|