SuperAPI AI Directory

prompt-analyzer

Agents & models

View repository

Updated 10-15 22:14

About this skill

Prompt Analyzer - Prompt Analyzer

🎯 Core Responsibilities

Focus on the analysis and insights of generated prompts, not responsible for generating new prompts.

Provides the following 5 major functions:

  1. View details - Analyze which elements a prompt uses
  2. Comparison analysis - Compare the differences between two prompts
  3. Similar recommendations - Recommend similar prompts
  4. Element statistics - Query element library statistics
  5. Style recommendations - Recommend the best element combinations by style

📋 Function 1: View prompt details

Trigger scenarios

The user says:

  • "View the details of Prompt #5"
  • "Analyze which elements Prompt #5 uses"
  • "Show the complete information of Prompt #5"
  • "What does Prompt #5 contain?"

SKILL processing flow

Step 1: Identify intent

Extract the Prompt ID from the user input:

# 示例:用户说 "查看Prompt #5的详情"
prompt_id = 5

Step 2: Call the execution layer

from prompt_analyzer import analyze_prompt_detail

result = analyze_prompt_detail(prompt_id=5)

Step 3: Check the result

If the prompt does not exist:

if 'error' in result:
    print(f"❌ {result['error']}")
    # 提示用户:该Prompt不存在,可能还没生成过任何Prompt

Step 4: Format the display

📸 Prompt #5 详情

**用户需求**: {result['user_intent']}
**生成时间**: {result['generation_date']}
**质量评分**: {result['quality_score']}/10
**风格标签**: {result['style_tag']}

**使用的元素** ({len(result['elements'])}个):

1. [{field_name}] {chinese_name} (复用度: {reusability})
   - 类别: {category}
   - 模板: {template}

2. ...

**完整Prompt**:
────────────────────────────────────────────────────────
{result['prompt_text']}
────────────────────────────────────────────────────────

📋 Function 2: Compare two prompts

Trigger scenarios

The user says:

  • "Compare Prompt #5 and #17"
  • "What is the difference between #5 and #17?"
  • "Compare Prompt #5 and #17"

SKILL processing flow

Step 1: Identify intent

Extract two Prompt IDs from the user input:

# 示例:用户说 "对比Prompt #5和#17"
prompt_id1 = 5
prompt_id2 = 17

Step 2: Call the execution layer

from prompt_analyzer import compare_prompts

result = compare_prompts(prompt_id1=5, prompt_id2=17)

Step 3: Analyze dimensions of difference

SKILL analyzes the returned data and generates a comparison table:

⚖️ Prompt对比:#5 vs #17

### 基本信息对比

| 维度 | Prompt #5 | Prompt #17 |
|------|-----------|-----------|
| 用户需求 | {p1['user_intent']} | {p2['user_intent']} |
| 风格标签 | {p1['style_tag']} | {p2['style_tag']} |
| 质量评分 | {p1['quality_score']}/10 | {p2['quality_score']}/10 |
| 元素总数 | {len(p1['elements'])}个 | {len(p2['elements'])}个 |
| 生成时间 | {p1['generation_date']} | {p2['generation_date']} |

### 元素差异分析

**相似度**: {result['similarity_score']*100:.1f}%

**共同元素** ({len(result['common_elements'])}个):
- {common_element['chinese_name']} ({common_element['category']})
- ...

**Prompt #5 独有** ({len(result['unique_to_p1'])}个):
- {element['chinese_name']} ({element['category']})
  关键词: {element['template'][:50]}...
- ...

**Prompt #17 独有** ({len(result['unique_to_p2'])}个):
- {element['chinese_name']} ({element['category']})
  关键词: {element['template'][:50]}...
- ...

Step 4: Analyze the conclusion

SKILL gives a conclusion based on similarity:

if result['similarity_score'] > 0.7:
    print("💡 这两个Prompt非常相似,风格接近")
elif result['similarity_score'] > 0.4:
    print("💡 这两个Prompt有一定相似性,但风格有明显差异")
else:
    print("💡 这两个Prompt完全不同,属于不同风格")

📋 Function 3: Recommend similar prompts

Trigger scenarios

The user says:

  • "Recommend prompts similar to #5"
  • "Are there any similar to #5?"
  • "Find some similar prompts"
  • "Recommend similar ones based on Prompt #5"

SKILL processing flow

Step 1: Identify intent

# 示例:用户说 "推荐与#5相似的Prompt"
prompt_id = 5
top_n = 3  # 默认推荐3个

Step 2: Call the execution layer

from prompt_analyzer import recommend_similar_prompts

result = recommend_similar_prompts(prompt_id=5, top_n=3)

Step 3: Analyze recommendation reasons

SKILL interprets the reasons for similarity and generates a reason for each recommended prompt:

# 分析共同元素,找出相似的原因
def analyze_similarity_reason(common_element_ids, target_prompt, candidate_prompt):
    """
    分析两个Prompt为什么相似

    返回:
    - 共同的风格标签
    - 共同的元素类别
    - 推荐理由列表
    """
    reasons = []

    # 检查风格标签
    if target_prompt['style_tag'] == candidate_prompt['style_tag']:
        reasons.append(f"✓ 同为{candidate_prompt['style_tag']}风格")

    # 按类别统计共同元素
    category_count = {}
    for elem_id in common_element_ids:
        # 查询元素详情获取category
        # ... (执行层已返回)
        category = ...
        category_count[category] = category_count.get(category, 0) + 1

    # 列出重要的共同类别
    for category, count in category_count.items():
        if count >= 2:
            reasons.append(f"✓ {count}个共同的{category}元素")

    return reasons

Step 4: Format the display

🔍 为Prompt #5推荐相似提示词

[1] Prompt #{recommendation['prompt_id']} - {recommendation['user_intent']}
    相似度: {recommendation['similarity']*100:.1f}%
    共同元素: {recommendation['common_count']}个
    质量评分: {recommendation['quality_score']}/10

    理由:
    - ✓ 同为{style_tag}风格
    - ✓ 共用3个makeup元素
    - ✓ 共用2个lighting元素

[2] ...

[3] ...

📋 Function 4: Element library statistics

Trigger scenarios

The user says:

  • "What categories are in the element library?"
  • "How many elements are in the makeup category?"
  • "Which elements are used the most?"
  • "View element library statistics"
  • "Detailed information of makeup_styles"

SKILL processing flow

Step 1: Identify intent

# 场景A:用户说 "元素库有哪些类别?"
category = None  # 查询整体统计

# 场景B:用户说 "makeup类别有多少个元素?"
category = 'makeup_styles'  # 查询特定类别

Step 2: Call the execution layer

from prompt_analyzer import get_library_statistics

# 整体统计
result = get_library_statistics()

# 或者特定类别
result = get_library_statistics(category='makeup_styles')

Step 3: Format the display

Scenario A: Overall statistics

📊 元素库统计

**总计**: {result['total_elements']} 个元素

**按类别分布**:
- makeup_styles: {count}个
- clothing_styles: {count}个
- hair_styles: {count}个
- lighting_techniques: {count}个
- facial_features: {count}个
- ...

💡 使用 "查看makeup_styles详情" 查看具体元素列表

Scenario B: Category details

📊 元素库统计 - {category}

**类别**: {result['category_details']['category']}
**总数**: {result['category_details']['total_count']} 个元素

**最常用元素** (Top 10):

| 排名 | 元素名称 | 复用度 | 使用次数 | 平均质量 |
|------|---------|--------|---------|---------|
| 1 | {chinese_name} | {reusability} | {usage_count}次 | {avg_quality}/10 |
| 2 | ... | ... | ... | ... |
| ... |

**最高质量元素** (Top 5):
[按avg_quality排序]

**从未使用的元素** ({count}个):
[usage_count = 0的元素]

📋 Function 5: Recommend element combinations by style

Trigger scenarios

The user says:

  • "What elements should be used for the ancient costume style?"
  • "What is the best combination of elements for a sci-fi style?"
  • "Recommend elements for a Westworld style"
  • "Which elements are good for the ancient_chinese style?"

SKILL Processing Flow

Step 1: Identify Intent

# 示例:用户说 "古装风格应该用什么元素?"

# 映射用户描述到style_tag
style_mapping = {
    '古装': 'ancient_chinese',
    '古装中式': 'ancient_chinese',
    '仙剑奇侠传': 'ancient_chinese',
    '科幻': 'modern_sci_fi',
    '西部世界': 'westworld_android',
    '赛博朋克': 'cyberpunk',
    '奇幻': 'fantasy'
}

style = style_mapping.get('古装', 'ancient_chinese')

Step 2: Call the Execution Layer

from prompt_analyzer import recommend_elements_by_style

result = recommend_elements_by_style(style='ancient_chinese')

Step 3: Organize Recommendations by Category

SKILL groups the returned elements by category for easy display:

# 按category分组
elements_by_category = {}
for element in result['recommended_elements']:
    category = element['category']
    if category not in elements_by_category:
        elements_by_category[category] = []
    elements_by_category[category].append(element)

# 按类别的最高使用频率排序
sorted_categories = sorted(
    elements_by_category.items(),
    key=lambda x: max(e['usage_frequency'] for e in x[1]),
    reverse=True
)

Step 4: Format for Display

🎨 风格推荐:{result['style']}

**数据来源**: 基于{result['total_prompts']}个历史Prompt分析

**推荐元素组合** (按类别):

### 1. {category_name}

[{field_name}] {chinese_name}
- 使用频率: {usage_frequency*100:.0f}% ({usage_count}/{total_prompts}个Prompt使用)
- 复用度: {reusability}/10
- 平均质量: {avg_quality}/10
- 关键词: {template[:80]}...

### 2. {category_name}

...

**使用建议**:
- ✓ 这个组合在{style}风格中最常用,质量稳定
- ✓ 推荐搭配:{推荐的基础属性,如"东亚女性"}
- ⚠️ 避免搭配:{冲突的元素}

🔧 Execution Layer Function List

SKILL calls the following execution functions (the code layer only executes, it does not make decisions):

# 所有函数在 prompt_analyzer.py 中

def analyze_prompt_detail(prompt_id: int) -> dict:
    """查询Prompt完整信息"""

def compare_prompts(prompt_id1: int, prompt_id2: int) -> dict:
    """对比两个Prompt差异"""

def recommend_similar_prompts(prompt_id: int, top_n: int = 3) -> list:
    """推荐相似Prompts"""

def get_library_statistics(category: str = None) -> dict:
    """查询元素库统计"""

def recommend_elements_by_style(style: str) -> dict:
    """按风格推荐元素组合"""

📁 Data Dependencies

elements.db
├── elements                 # 元素库(由universal-learner维护)
├── generated_prompts        # 生成历史(由intelligent-prompt-generator写入)
├── prompt_elements          # Prompt-元素关联
└── element_usage_stats      # 元素使用统计

Important: prompt-analyzer depends on the historical data generated by intelligent-prompt-generator. If there are no generated_prompts records in the database, the analysis function cannot work.


⚙️ Architectural Principles

✅ SKILL = Brain (Decision Layer)

  • Identify user intent
  • Analyze returned data
  • Format the display of results
  • Generate recommendation reasons

✅ Code = Hands and Feet (Execution Layer)

  • Query the database
  • Calculate similarity
  • Return raw data

❌ Code does not make decisions

  • Does not judge "which is better"
  • Does not decide "what to display"
  • Only responsible for "fetching data"

Usage Examples

Example 1: View Details

User: "View details of Prompt #1"

SKILL processing:

from prompt_analyzer import analyze_prompt_detail

result = analyze_prompt_detail(prompt_id=1)

# 展示格式化结果
print(f"📸 Prompt #{result['prompt_id']} 详情\n")
print(f"**用户需求**: {result['user_intent']}")
print(f"**生成时间**: {result['generation_date']}")
# ...

Example 2: Compare Prompts

User: "Compare Prompt #1 and #2"

SKILL processing:

from prompt_analyzer import compare_prompts

result = compare_prompts(prompt_id1=1, prompt_id2=2)

# 分析相似度
similarity = result['similarity_score']
if similarity > 0.7:
    conclusion = "非常相似"
elif similarity > 0.4:
    conclusion = "有一定相似性"
else:
    conclusion = "完全不同"

# 展示对比表格和结论
# ...

Example 3: Recommend Similar Prompts

User: "Recommend Prompts similar to #1"

SKILL processing:

from prompt_analyzer import recommend_similar_prompts

recommendations = recommend_similar_prompts(prompt_id=1, top_n=3)

# 为每个推荐分析理由
for rec in recommendations:
    reasons = analyze_similarity_reason(
        rec['common_element_ids'],
        target_prompt_id=1,
        candidate_prompt_id=rec['prompt_id']
    )

    # 展示推荐和理由
    # ...

Example 4: Element Library Statistics

User: "View details of the makeup_styles category"

SKILL processing:

from prompt_analyzer import get_library_statistics

result = get_library_statistics(category='makeup_styles')

# 展示统计表格
details = result['category_details']
print(f"📊 {details['category']} - {details['total_count']}个元素\n")

# 按使用次数排序展示
# ...

Example 5: Style Recommendations

User: "What elements should be used for ancient costume style?"

SKILL processing:

from prompt_analyzer import recommend_elements_by_style

result = recommend_elements_by_style(style='ancient_chinese')

# 按类别组织展示
elements_by_category = group_by_category(result['recommended_elements'])

# 展示每个类别的推荐
for category, elements in elements_by_category.items():
    print(f"### {category}")
    for elem in elements:
        print(f"  - {elem['chinese_name']} (使用频率: {elem['usage_frequency']*100:.0f}%)")
# ...

⚠️ Important Reminders

  1. Data Prerequisite: There must be generation history before analysis is possible

    • If the user says "View Prompt #5", but there is no Prompt in the database, it should prompt:
      ❌ 数据库中还没有生成历史。
      💡 请先使用 intelligent-prompt-generator 生成一些Prompt。
      
  2. Prompt ID Range: Only existing Prompt IDs can be queried

    • The ID entered by the user may not exist, so the error field needs to be checked
  3. Style Tag Consistency: Style recommendations depend on style_tag

    • style_tag is set by intelligent-prompt-generator when saving
    • Common tags: ancient_chinese, modern_sci_fi, cyberpunk, fantasy, westworld_android
  4. Element Category Names: Use the correct category name when querying statistics

    • makeup_styles (not makeup)
    • lighting_techniques (not lighting)
    • clothing_styles, hair_styles, facial_features, etc.

Ready to analyze prompts! Waiting for the user's analysis request.