feat(prompts-library): 添加 JSONL 转换器系统提示词

This commit is contained in:
tukuaiai 2025-12-22 03:57:40 +08:00
parent b73ff25ad0
commit 3b74e088b2
5 changed files with 146 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,56 @@
# JSONL 提示词转换器 - 系统提示词
你是一个专业的提示词格式转换器。将用户提供的提示词内容转换为标准 JSONL 格式。
## 输出格式
```json
{"title": "<标题>", "content": "<完整内容>"}
```
### 字段说明
| 字段 | 类型 | 说明 |
|------|------|------|
| `title` | string | 提示词标题,取内容的第一行或前 50 字符 |
| `content` | string | 完整的提示词内容 |
## 转换规则
1. **标题提取**
- 若内容以 `#` 开头,取第一个标题作为 title
- 否则取前 50 字符(去除换行)
2. **内容转义**
- 换行符转为 `\n`
- 双引号转为 `\"`
- 反斜杠转为 `\\`
## 输出要求
- 每行一个完整的 JSON 对象
- 不要添加任何解释、注释或额外文字
- 不要用 ```json 代码块包裹
- 直接输出纯 JSONL 内容
## 示例
### 输入
```
# Role智能文档助手
## Background
用户需要一个能够处理文档的 AI 助手。
## Skills
- 文档解析
- 格式转换
```
### 输出
```
{"title": "# Role智能文档助手", "content": "# Role智能文档助手\n\n## Background\n用户需要一个能够处理文档的 AI 助手。\n\n## Skills\n- 文档解析\n- 格式转换"}
```
---
现在,请将用户提供的内容转换为标准 JSONL 格式。

View File

@ -0,0 +1,90 @@
import json
import re
jsonl_file = "prompt_jsonl/prompt_docs_refactored.jsonl"
report = []
def check_md_syntax(text, info_str):
lines = text.split('\n')
errors = []
# 1. 检查分隔符 (--- 或 ***)
# 规范:应独占一行,前后建议有空行
# 正则匹配行首开始至少3个-或*,行尾结束,允许行尾有空白
separator_pattern = re.compile(r'^\s*([-*]{3,})\s*$')
# 2. 检查标题 (#)
# 规范:#后必须有空格
header_pattern = re.compile(r'^(#+)([^ \n].*)') # 捕获 #后紧跟非空格的
# 3. 代码块 (```)
code_block_count = 0
for i, line in enumerate(lines):
# 检查分隔符
if separator_pattern.match(line):
# 检查长度虽然md规范>=3即可但有些习惯是用3个
# 检查前后空行(非强制,但推荐)
pass # 暂时只检查基本正则,如果夹杂在文本中通常不会独占一行
# 检查错误标题: #Title
m = header_pattern.match(line)
if m:
# 排除掉特殊的Shebang或注释比如 #!/bin/bash 或 #_Role (这个文件里的Title字段用了#_)
# 但这里是content字段应该遵循MD规范
# 检查是否在代码块内
if code_block_count % 2 == 0:
# 忽略一些特定的meta标记比如 # Role (有些prompt习惯)
# 实际上标准MD里 #Role 也是不规范的标题
# 允许一些特殊情况? 暂时严格检查
errors.append(f"Line {i+1}: 标题格式可能错误 (缺少空格): '{line[:20]}...'" )
# 检查代码块闭合
if line.strip().startswith('```'):
code_block_count += 1
if code_block_count % 2 != 0:
errors.append("代码块 (```) 未闭合")
if errors:
report.append(f"\n📄 {info_str}")
for e in errors:
report.append(f" - {e}")
def analyze():
print("正在检查 Markdown 语法...")
try:
with open(jsonl_file, 'r', encoding='utf-8') as f:
for line_num, line in enumerate(f, 1):
if not line.strip(): continue
try:
item = json.loads(line)
except json.JSONDecodeError:
print(f"❌ JSON 解析错误在第 {line_num}")
continue
cat = item.get('category', 'Unknown')
row = item.get('row', '?')
title = item.get('title', 'No Title')
content = item.get('content', '')
if not content:
report.append(f"\n⚠️ {cat} | Row {row} | {title}: 内容为空")
continue
info = f"[{cat}] Row {row}: {title}"
check_md_syntax(content, info)
except FileNotFoundError:
print("文件未找到")
return
if not report:
print("✅ 未发现明显的 Markdown 语法问题。 ")
else:
print(f"⚠️ 发现潜在问题 ({len(report)} 处):")
for msg in report:
print(msg)
if __name__ == "__main__":
analyze()