mirror of
https://github.com/tradecatlabs/vibe-coding-cn.git
synced 2026-08-14 03:18:04 +00:00
docs(prompts-library): 完善 main.py 转换规范文档
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import json
|
||||
import shutil
|
||||
from collections import defaultdict
|
||||
|
||||
input_file = "prompt_jsonl/prompt_docs_refactored.jsonl"
|
||||
output_file = "prompt_jsonl/prompt_docs_refactored_clean.jsonl"
|
||||
backup_file = "prompt_jsonl/prompt_docs_refactored.jsonl.bak"
|
||||
|
||||
def filter_versions():
|
||||
# 1. Backup
|
||||
shutil.copy(input_file, backup_file)
|
||||
print(f"Backup created: {backup_file}")
|
||||
|
||||
# 2. Group by (category, row) and find max col
|
||||
latest_versions = {} # Key: (category, row), Value: item_dict
|
||||
|
||||
with open(input_file, 'r', encoding='utf-8') as f:
|
||||
for line in f:
|
||||
if not line.strip(): continue
|
||||
item = json.loads(line)
|
||||
|
||||
cat = item.get('category', 'Uncategorized')
|
||||
row = item.get('row', 0)
|
||||
col = item.get('col', 0)
|
||||
|
||||
key = (cat, row)
|
||||
|
||||
if key not in latest_versions:
|
||||
latest_versions[key] = item
|
||||
else:
|
||||
# If current item has higher col, replace it
|
||||
if col > latest_versions[key].get('col', 0):
|
||||
latest_versions[key] = item
|
||||
|
||||
# 3. Write filtered data
|
||||
count = 0
|
||||
with open(output_file, 'w', encoding='utf-8') as f:
|
||||
# Sort by category then row for tidiness
|
||||
sorted_keys = sorted(latest_versions.keys(), key=lambda x: (x[0], x[1]))
|
||||
for key in sorted_keys:
|
||||
item = latest_versions[key]
|
||||
f.write(json.dumps(item, ensure_ascii=False) + '\n')
|
||||
count += 1
|
||||
|
||||
print(f"Filtered file written: {output_file}")
|
||||
print(f"Total prompts retained: {count}")
|
||||
|
||||
# Overwrite original for downstream scripts
|
||||
shutil.move(output_file, input_file)
|
||||
print(f"Overwritten original file: {input_file}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
filter_versions()
|
||||
@@ -0,0 +1,36 @@
|
||||
import json
|
||||
import pandas as pd
|
||||
|
||||
input_file = "prompt_jsonl/prompt_docs_refactored.jsonl"
|
||||
output_file = "prompt_excel/prompt_docs_refactored.xlsx"
|
||||
|
||||
def process():
|
||||
data_by_cat = {}
|
||||
with open(input_file, 'r', encoding='utf-8') as f:
|
||||
for line in f:
|
||||
if not line.strip(): continue
|
||||
item = json.loads(line)
|
||||
cat = item['category']
|
||||
if cat not in data_by_cat:
|
||||
data_by_cat[cat] = []
|
||||
|
||||
# Reconstruct the JSON string for the cell as it was in original Excel
|
||||
cell_data = {
|
||||
"title": item.get('title', ''),
|
||||
"content": item.get('content', '')
|
||||
}
|
||||
data_by_cat[cat].append(json.dumps(cell_data, ensure_ascii=False))
|
||||
|
||||
with pd.ExcelWriter(output_file, engine='openpyxl') as writer:
|
||||
# Sort categories to keep a consistent order
|
||||
sorted_cats = sorted(data_by_cat.keys())
|
||||
for cat in sorted_cats:
|
||||
items = data_by_cat[cat]
|
||||
# Each item in its own row, column 0
|
||||
df = pd.DataFrame(items)
|
||||
df.to_excel(writer, sheet_name=cat, index=False, header=False)
|
||||
|
||||
print(f"Excel created: {output_file}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
process()
|
||||
@@ -0,0 +1,154 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
mapping = {
|
||||
# 编程技术
|
||||
"软件工程,glue_coding_用提示词": "编程技术",
|
||||
"前端复刻流程": "编程技术",
|
||||
"输入转单行JSON": "编程技术",
|
||||
"序列图生成": "编程技术",
|
||||
"流程图": "编程技术",
|
||||
"函数化万物": "编程技术",
|
||||
"编程知识库": "编程技术",
|
||||
"网页UI逆向分析提示词": "编程技术",
|
||||
"用户优化前端设计": "编程技术",
|
||||
"图像特征提取": "编程技术",
|
||||
"前端通用设计": "编程技术",
|
||||
|
||||
# 逻辑工具箱
|
||||
"哲学工具箱": "逻辑工具箱",
|
||||
"逻辑工具箱": "逻辑工具箱",
|
||||
"批判性思维分析": "逻辑工具箱",
|
||||
"思维模型": "逻辑工具箱",
|
||||
"政治批判工具箱": "逻辑工具箱",
|
||||
"未来视角": "逻辑工具箱",
|
||||
"层级结构分析": "逻辑工具箱",
|
||||
"问题分类识别": "逻辑工具箱",
|
||||
"分析": "逻辑工具箱",
|
||||
"终极本质分析": "逻辑工具箱",
|
||||
"事实核查": "逻辑工具箱",
|
||||
"关键词图谱": "逻辑工具箱",
|
||||
"语言分析元prompt": "逻辑工具箱",
|
||||
"逻辑分析": "逻辑工具箱",
|
||||
"黄金圈解释": "逻辑工具箱",
|
||||
"谋士": "逻辑工具箱",
|
||||
"经验": "逻辑工具箱",
|
||||
"道": "逻辑工具箱",
|
||||
"法": "逻辑工具箱",
|
||||
"术": "逻辑工具箱",
|
||||
"器": "逻辑工具箱",
|
||||
"心经口诀创作提示词": "逻辑工具箱",
|
||||
"临界知识": "逻辑工具箱",
|
||||
"项目分析": "逻辑工具箱",
|
||||
"对话提问": "逻辑工具箱",
|
||||
"思维导图": "逻辑工具箱",
|
||||
|
||||
# 内容创作
|
||||
"文案逆向": "内容创作",
|
||||
"x_prompt收集": "内容创作",
|
||||
"x提示词收集": "内容创作",
|
||||
"x爆款文案生成器": "内容创作",
|
||||
"推文制作提示词": "内容创作",
|
||||
"李继刚文选": "内容创作",
|
||||
"解释提示词": "内容创作",
|
||||
"一句话描述任何内容": "内容创作",
|
||||
"子弹总结": "内容创作",
|
||||
"文本转md语法电子书处理": "内容创作",
|
||||
"排版和图片,视频转文本": "内容创作",
|
||||
"艺术风格描述": "内容创作",
|
||||
"视频生成提示词": "内容创作",
|
||||
"图片逆向": "内容创作",
|
||||
"排版": "内容创作",
|
||||
"内容提炼": "内容创作",
|
||||
"简讯提示词": "内容创作",
|
||||
"艺术": "内容创作",
|
||||
"人话写作": "内容创作",
|
||||
"小红书": "内容创作",
|
||||
"组织语言": "内容创作",
|
||||
"正向人物生平报告官方文案": "内容创作",
|
||||
"gemini字幕处理": "内容创作",
|
||||
|
||||
# 学习教育
|
||||
"学习提示词": "学习教育",
|
||||
"学习用提示词": "学习教育",
|
||||
"ai学习用提示词": "学习教育",
|
||||
"书籍结构化分析": "学习教育",
|
||||
"典籍句子学习": "学习教育",
|
||||
"anki卡片格式输出": "学习教育",
|
||||
"notebookllm用提示词": "学习教育",
|
||||
"英文学习": "学习教育",
|
||||
"速成学习": "学习教育",
|
||||
"论文解读": "学习教育",
|
||||
"真传一句话": "学习教育",
|
||||
"学习音频": "学习教育",
|
||||
"豆包听书": "学习教育",
|
||||
"最小知识框架": "学习教育",
|
||||
|
||||
# 商业分析
|
||||
"grok商业金融分析提示词": "商业分析",
|
||||
"投资调研": "商业分析",
|
||||
"行业分析": "商业分析",
|
||||
"需求对齐": "商业分析",
|
||||
"需求结构化描述": "商业分析",
|
||||
"麦肯锡行业分析": "商业分析",
|
||||
"产品策略": "商业分析",
|
||||
"行业咨询": "商业分析",
|
||||
"需求解析": "商业分析",
|
||||
"SOP制作": "商业分析",
|
||||
|
||||
# 提示词工程
|
||||
"元提示词": "提示词工程",
|
||||
"提示词模块": "提示词工程",
|
||||
"根据内容逆向提示词": "提示词工程",
|
||||
"系统提示词": "提示词工程",
|
||||
"AI使用思维": "提示词工程",
|
||||
"使用ai的思维": "提示词工程",
|
||||
"最小字数系统提示词": "提示词工程",
|
||||
"ChatGPT": "提示词工程",
|
||||
"Reddit提示词": "提示词工程",
|
||||
"好prompt生成器": "提示词工程",
|
||||
"思维协议": "提示词工程",
|
||||
"grok抓取提示词": "提示词工程",
|
||||
|
||||
# 其他
|
||||
"AI_交易系统提示词": "综合杂项",
|
||||
"面向CZ": "综合杂项",
|
||||
}
|
||||
|
||||
id_map = {
|
||||
"编程技术": 1,
|
||||
"逻辑工具箱": 2,
|
||||
"内容创作": 3,
|
||||
"学习教育": 4,
|
||||
"商业分析": 5,
|
||||
"提示词工程": 6,
|
||||
"综合杂项": 7
|
||||
}
|
||||
|
||||
input_file = "prompt_jsonl/prompt_docs_2025_1222_004537.jsonl"
|
||||
output_file = "prompt_jsonl/prompt_docs_refactored.jsonl"
|
||||
|
||||
def process():
|
||||
stats = {}
|
||||
with open(input_file, 'r', encoding='utf-8') as fin, \
|
||||
open(output_file, 'w', encoding='utf-8') as fout:
|
||||
for line in fin:
|
||||
if not line.strip(): continue
|
||||
data = json.loads(line)
|
||||
old_cat = data.get('category', '')
|
||||
new_cat = mapping.get(old_cat, "综合杂项")
|
||||
|
||||
# Keep original category in tags if it doesn't exist?
|
||||
# Or just replace. The user said "只调整 'category'"
|
||||
data['category'] = new_cat
|
||||
data['category_id'] = id_map.get(new_cat, 7)
|
||||
|
||||
fout.write(json.dumps(data, ensure_ascii=False) + '\n')
|
||||
stats[new_cat] = stats.get(new_cat, 0) + 1
|
||||
|
||||
print("Refactor complete.")
|
||||
for cat, count in stats.items():
|
||||
print(f"{cat}: {count}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
process()
|
||||
@@ -0,0 +1,49 @@
|
||||
import json
|
||||
import shutil
|
||||
from collections import defaultdict
|
||||
|
||||
input_file = "prompt_jsonl/prompt_docs_refactored.jsonl"
|
||||
output_file = "prompt_jsonl/prompt_docs_refactored_reindexed.jsonl"
|
||||
backup_file = "prompt_jsonl/prompt_docs_refactored_before_reindex.jsonl.bak"
|
||||
|
||||
def reindex_rows():
|
||||
# 1. Backup
|
||||
shutil.copy(input_file, backup_file)
|
||||
print(f"Backup created: {backup_file}")
|
||||
|
||||
# 2. Load and Group
|
||||
items_by_cat = defaultdict(list)
|
||||
|
||||
with open(input_file, 'r', encoding='utf-8') as f:
|
||||
for line in f:
|
||||
if not line.strip(): continue
|
||||
item = json.loads(line)
|
||||
cat = item.get('category', 'Uncategorized')
|
||||
items_by_cat[cat].append(item)
|
||||
|
||||
# 3. Sort and Reindex
|
||||
total_items = 0
|
||||
with open(output_file, 'w', encoding='utf-8') as f:
|
||||
# Sort categories for consistent file order
|
||||
for cat in sorted(items_by_cat.keys()):
|
||||
items = items_by_cat[cat]
|
||||
# Sort items by their OLD row to preserve relative order
|
||||
items.sort(key=lambda x: x.get('row', 0))
|
||||
|
||||
# Reassign row numbers starting from 1
|
||||
for i, item in enumerate(items):
|
||||
item['row'] = i + 1
|
||||
f.write(json.dumps(item, ensure_ascii=False) + '\n')
|
||||
total_items += 1
|
||||
|
||||
print(f"Category '{cat}': re-indexed {len(items)} items.")
|
||||
|
||||
print(f"Re-indexed file written: {output_file}")
|
||||
print(f"Total items: {total_items}")
|
||||
|
||||
# Overwrite original
|
||||
shutil.move(output_file, input_file)
|
||||
print(f"Overwritten original file: {input_file}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
reindex_rows()
|
||||
@@ -0,0 +1,109 @@
|
||||
import json
|
||||
import os
|
||||
from collections import defaultdict
|
||||
|
||||
jsonl_path = "prompt_jsonl/prompt_docs_refactored.jsonl"
|
||||
docs_root = "prompt_docs/prompt_docs_refactored/prompts"
|
||||
|
||||
def verify():
|
||||
print("=== 开始全面完整性检查 ===\n")
|
||||
|
||||
# 1. JSONL 数据加载与基础检查
|
||||
if not os.path.exists(jsonl_path):
|
||||
print(f"❌ 错误: JSONL 文件不存在: {jsonl_path}")
|
||||
return
|
||||
|
||||
data = []
|
||||
with open(jsonl_path, 'r', encoding='utf-8') as f:
|
||||
for line in f:
|
||||
if line.strip():
|
||||
try:
|
||||
data.append(json.loads(line))
|
||||
except json.JSONDecodeError:
|
||||
print(f"❌ 错误: 发现无效的 JSON 行: {line[:50]}...")
|
||||
|
||||
total_items = len(data)
|
||||
print(f"✅ JSONL 读取成功,共 {total_items} 条数据。")
|
||||
|
||||
# 2. 规则验证
|
||||
errors = []
|
||||
categories = defaultdict(list)
|
||||
|
||||
expected_categories = {
|
||||
"内容创作", "商业分析", "学习教育", "提示词工程", "综合杂项", "编程技术", "逻辑工具箱"
|
||||
}
|
||||
|
||||
for item in data:
|
||||
cat = item.get('category')
|
||||
row = item.get('row')
|
||||
col = item.get('col')
|
||||
title = item.get('title')
|
||||
content = item.get('content')
|
||||
|
||||
# 收集分类数据用于后续分析
|
||||
categories[cat].append(row)
|
||||
|
||||
# 检查 1: 分类合法性
|
||||
if cat not in expected_categories:
|
||||
errors.append(f"❌ 未知分类: '{cat}' (Title: {title[:20]}...)")
|
||||
|
||||
# 检查 2: 列归位 (col == 1)
|
||||
if col != 1:
|
||||
errors.append(f"❌ 列未归位: Category '{cat}', Row {row}, Col {col} (应为 1)")
|
||||
|
||||
# 检查 3: 内容完整性 (简单检查)
|
||||
if not title:
|
||||
errors.append(f"⚠️ 警告: 标题为空 (Category '{cat}', Row {row})")
|
||||
if not content or len(content) < 5:
|
||||
errors.append(f"⚠️ 警告: 内容过短或为空 (Category '{cat}', Row {row}, Content len: {len(content) if content else 0})")
|
||||
|
||||
# 检查 4: 行连续性
|
||||
print("\n--- 分类与行号连续性检查 ---")
|
||||
for cat, rows in categories.items():
|
||||
rows.sort()
|
||||
count = len(rows)
|
||||
if count == 0:
|
||||
print(f"⚠️ 分类 '{cat}' 为空")
|
||||
continue
|
||||
|
||||
max_row = rows[-1]
|
||||
expected_rows = list(range(1, count + 1))
|
||||
|
||||
status = "✅ 正常"
|
||||
if rows != expected_rows:
|
||||
status = "❌ 异常 (行号不连续或重复)"
|
||||
errors.append(f"行号错误: {cat} (Expect 1-{count}, Got max {max_row})")
|
||||
|
||||
print(f"{cat.ljust(10)}: {count} 条 | Max Row: {max_row} | {status}")
|
||||
|
||||
# 3. 文件系统同步检查
|
||||
print("\n--- 文档文件同步检查 ---")
|
||||
files_found = 0
|
||||
if os.path.exists(docs_root):
|
||||
for root, dirs, files in os.walk(docs_root):
|
||||
for file in files:
|
||||
if file.endswith(".md") and not file.startswith("index"):
|
||||
files_found += 1
|
||||
else:
|
||||
print(f"❌ 文档目录不存在: {docs_root}")
|
||||
|
||||
print(f"JSONL 条目数: {total_items}")
|
||||
print(f"Markdown 文件数: {files_found}")
|
||||
|
||||
if total_items == files_found:
|
||||
print("✅ 文件数量一致")
|
||||
else:
|
||||
print(f"❌ 文件数量不匹配! (差值: {files_found - total_items})")
|
||||
errors.append("文件系统数量与 JSONL 不一致")
|
||||
|
||||
# 4. 总结
|
||||
print("\n=== 检查总结 ===")
|
||||
if not errors:
|
||||
print("🎉 完美!所有检查通过。数据结构完整、规范。")
|
||||
else:
|
||||
print(f"发现 {len(errors)} 个问题,请检视:")
|
||||
for err in errors:
|
||||
print(err)
|
||||
|
||||
if __name__ == "__main__":
|
||||
verify()
|
||||
Reference in New Issue
Block a user