CCTI:ccti ai prompt.py: 두 판 사이의 차이
편집 요약 없음 |
편집 요약 없음 |
||
| 314번째 줄: | 314번째 줄: | ||
remark = row.get("remark") or "" | remark = row.get("remark") or "" | ||
if category and remark: | if category and remark: | ||
return (f"아래 Input XML의 한문 문장에 대한 기본 정보는 다음과 같습니다. 글의 성격에 부합하는 Output을 제공해 주세요." | return (f"아래 Input XML의 한문 문장에 대한 기본 정보는 다음과 같습니다. 글의 성격에 부합하는 Output을 제공해 주세요.\n" | ||
f" | f"1. Id (식별자): {key}\n" | ||
f" | f"2. Category (글의 유형/범주): {category}\n" | ||
f" | f"3. Remark (글의 성격 또는 내용에 관한 정보): {remark}\n" ) | ||
return "" | return "" | ||
</pre> | </pre> | ||
[[분류:CCTI]] | |||
2026년 6월 1일 (월) 07:37 기준 최신판
# ccti_ai_prompt.py
SYSTEM_PROMPT = (
"You are a translator of Chinese classics. Perform the tasks requested by the user based on the given dataset.\n"
"When a specific XML format is requested, you MUST:\n"
"- Output ONLY the XML payload (no preface/epilog, no code fences).\n"
"- Obey the schema exactly (tags, nesting, tag names).\n"
"- Keep tags well-formed and closed.\n"
"- Do NOT invent undeclared tags or attributes.\n"
)
##################################################
# prompts for Hanmun data AI processing
##################################################
def _build_task_prompt(action: str, text_info: str, input_data: str, model: str, option: int) -> str:
if action == "GLOSSARY":
return f"""
당신은 한문 문헌을 교육용으로 해석하기 위한 “표준표점 + 용어사전(키워드/문형)” 생성 도우미입니다.
아래 Input XML의 한문 원문을 읽고, (1) 표준표점(standard punctuation)을 부가한 한문 텍스트를 만들고, (2) 이 문장의 정확한 이해에 필요한 핵심 용어와 문법/문형(허사 포함)을 추출하여 용어사전을 작성하세요.
반드시 다음 규칙을 지키세요.
[출력 규칙]
1. 출력은 오직 XML만 제공합니다. 설명 문장, 코드블록(```xml) 금지.
2. <text_unit>의 id는 입력과 동일해야 합니다.
3. 입력에 <translation> 요소가 있는 경우, 그 내용만 표준표점과 glossary 생성에 반영하고, Output XML에는 포함하지 않습니다.
** hanmun_text:
4. Output XML의 <hanmun_text punctuation_scheme="standard">에는 표준표점이 반영된 한문만 넣습니다. 표준표점은 현대 중국어식 구두점(, 。 : ; 、 「 」)을 기본으로 하되, 문장 단위 의미 분절을 우선합니다.
5. <hanmun_text> 요소 내의 모든 하위 요소(태그와 속성)는 그대로 유지합니다. (<annotation>, <commentary>, <imperial_inscription>, <title>, <preface>, <poem>, <ref>, <fnote>, <이두>, <인명>, <지명>, <서명> 등)
6. 한글 현토(는, 하고, 이니, 요, 하며, 이라, 라, 하면 등)가 있는 경우 모두 제거합니다. 주석문(<annotation>, <commentary> 내부)의 한글 현토도 동일하게 제거하고 표점을 추가합니다.
** glossary:
7. <glossary status="draft" model="{model}">를 새로 생성하여 <text_unit> 내부에 포함합니다.
8. <term>의 id는 생략하지 말고 id=""로 둡니다. (권장: 빈 문자열)
9. <sense scope>는 기본적으로 "this_text_unit"을 사용하지만, 일반적인 사전적 정의인 경우에는 "general"을 사용합니다.
10. 용어 유형(type)은 아래 목록 중에서만 선택합니다.
Person|Place|Event|Timespan|Object|Record|ArtWork|Food|Clothing|Concept|Grammar|이두
11. Grammar 항목에는 이 문장에서 해석을 좌우하는 문형/허사 용법(예: 以~云爾, 豈不~哉, 則, 乃, 而 등)을 포함하세요.
12. 용어 유형(type) "이두"는 한국식 한문 독법에 쓰이는 현토를 한자로 표기한 것을 말합니다. Text 속의 이두는 <glossary>에 포함시키되 한국어 조사나 어미로 해석해 주세요.
13. definition은 짧고 명확한 한국어로(1~2문장) 작성하고, sense_note에는 “이 문장에서의 해석 포인트/주의점”을 간단히 적습니다.
14. 의미 파악이 안되는 용어에 대해서는 <term> 요소 밑에 <lemma> 요소만 넣고 <sense> 요소는 생략하세요.
15. <term>의 갯수는 기본적으로 {option} 개 이상, 30 개 이하로 생성합니다.
[한문 원문에 대한 정보]
{text_info}
[Input XML]
{input_data}
[출력 형식(반드시 이 구조)]
<text_unit id="...">
<hanmun_text punctuation_scheme="standard" model="{model}">
...
<!--Input Xml에 있는 hanmun_text 요소의 하위 요소들은 그대로 유지 -->
...
</hanmun_text>
<glossary status="draft" model="{model}">
<term type="..." id="">
<lemma>
<hanmun>...</hanmun>
<korean>...</korean>
</lemma>
<sense scope="this_text_unit|general">
<definition>...</definition>
<sense_note>...</sense_note>
</sense>
</term>
</glossary>
</text_unit>
""".strip()
elif action == "PUNCTUATION":
return f"""
당신은 한문 문헌을 교육용으로 해석하기 위한 “표준표점” 생성 도우미입니다.
아래 Input XML의 한문 원문을 읽고, 표준표점(standard punctuation)을 부가한 한문 텍스트를 만들어 주세요.,
반드시 다음 규칙을 지키세요.
[출력 규칙]
1. 출력은 오직 XML만 제공합니다. 설명 문장, 코드블록(```xml) 금지.
2. Output XML의 <hanmun_text punctuation_scheme="standard" model="{model}">에는 표준표점이 반영된 한문만 넣습니다. 표준표점은 현대 중국어식 구두점(, 。 : ; 、 「 」)을 기본으로 하되, 문장 단위 의미 분절을 우선합니다.
3. Iutput XML의 <hanmun_text> 요소 내의 모든 하위 요소(태그와 속성)는 Output XML의 <hanmun_text> 요소에서도 그대로 유지합니다. (<annotation>, <commentary>, <imperial_inscription>, <title>, <preface>, <poem>, <ref>, <fnote>, <이두>, <인명>, <지명>, <서명> 등)
4. Iutput XML에 <translation> 요소가 있는 경우, 그 내용만 표준표점 생성에 반영하고, Output XML에는 포함하지 않습니다.
5. 한글 현토(는, 하고, 이니, 요, 하며, 이라, 라, 하면 등)가 있는 경우 모두 제거합니다. 주석문(<annotation>, <commentary> 내부)의 한글 현토도 동일하게 제거하고 표점을 추가합니다.
[한문 원문에 대한 정보]
{text_info}
[Input XML]
{input_data}
[출력 형식(반드시 이 구조)]
<hanmun_text punctuation_scheme="standard" model="{model}">
...
<!--Input Xml에 있는 hanmun_text 요소의 하위 요소들은 그대로 유지 -->
....
</hanmun_text>
""".strip()
elif action == "GLOSSARY_ONLY":
return f"""
당신은 한문 문헌을 교육용으로 해석하기 위한 “용어사전(키워드/문형)” 생성 도우미입니다.
아래 Input XML의 한문 원문을 읽고, 이 문장의 정확한 이해에 필요한 핵심 용어와 문법/문형(허사 포함)을 추출하여 용어사전을 작성하세요.
반드시 다음 규칙을 지키세요.
[출력 규칙]
1. 출력은 오직 XML만 제공합니다. 설명 문장, 코드블록(```xml) 금지.
2. <glossary status="draft" model="{model}">를 새로 생성합니다. (최상위 요소)
3. <term>의 id는 생략하지 말고 id=""로 둡니다. (권장: 빈 문자열)
4. <sense scope>는 기본적으로 "this_text_unit"을 사용하지만, 일반적인 사전적 정의인 경우에는 "general"을 사용합니다.
5. 용어 유형(type)은 아래 목록 중에서만 선택합니다.
Person|Place|Event|Timespan|Object|Record|ArtWork|Food|Clothing|Concept|Grammar|이두
6. Grammar 항목에는 이 문장에서 해석을 좌우하는 문형/허사 용법(예: 以~云爾, 豈不~哉, 則, 乃, 而 등)을 포함하세요.
7. 용어 유형(type) "이두"는 한국식 한문 독법에 쓰이는 현토를 한자로 표기한 것을 말합니다. Text 속의 이두는 <glossary>에 포함시키되 한국어 조사나 어미로 해석해 주세요.
8. definition은 짧고 명확한 한국어로(1~2문장) 작성하고, sense_note에는 “이 문장에서의 해석 포인트/주의점”을 간단히 적습니다.
9. 의미 파악이 안되는 용어에 대해서는 <term> 요소 밑에 <lemma> 요소만 넣고 <sense> 요소는 생략하세요.
10. <term>의 갯수는 기본적으로 {option} 개 이상, 30 개 이하로 생성합니다.
[한문 원문에 대한 정보]
{text_info}
[Input XML]
{input_data}
[출력 형식(반드시 이 구조)]
<glossary status="draft" model="{model}">
<term type="..." id="">
<lemma>
<hanmun>...</hanmun>
<korean>...</korean>
</lemma>
<sense scope="this_text_unit|general">
<definition>...</definition>
<sense_note>...</sense_note>
</sense>
</term>
</glossary>
""".strip()
elif action == "TRANSLATE_KOR":
return f"""
당신은 한문 문헌을 **검토 완료된 용어사전(glossary)**을 근거로 정확하게 번역하는 번역 도우미입니다.
아래 Input XML에는 (1) 표준표점이 부가된 한문 원문과 (2) 검토(reviewed)된 용어사전이 포함되어 있습니다.
이 glossary는 이 문장을 올바르게 해석하기 위해 확정된 기준 정보이므로,
번역 시 반드시 glossary의 정의와 문형 해석을 우선적으로 따르세요.
[번역 규칙]
1. 출력은 오직 XML만 제공합니다. 설명 문장, 코드블록(```xml) 사용 금지.
2. <text_unit>의 id는 입력과 동일해야 합니다.
3. 입력 데이터 <hanmun_text>의 한문을 한국어로 번역하여 <translation lang="KOR" status="draft" model="{model}"> 요소 안에 담습니다.
4. 입력 데이터 <hanmun_text>의 하위요소(<annotation>, <commentary>, <imperial_inscription>, <title>, <preface>, <poem>, <ref>, <fnote>, <이두>, <인명>, <지명>, <서명> 등)는 그대로 유지하면서 요소 값만 한국어로 번역합니다.
5. 번역문은 고전 한문에 익숙하지 않은 대학생·일반 학습자도 이해할 수 있는 평이한 현대 한국어로 작성하세요.
6. 필요하면 문장을 나누되, 의미를 임의로 추가하지 마세요.
7. glossary에 포함된 용어와 문형은 다음 원칙을 따르세요.
- Person / Place / Event / Timespan / Object / Record / ArtWork / Food / Clothing / Concept 등은 glossary의 정의에 맞게 번역
- Grammar 항목(문형·허사)은 glossary의 해석 원칙을 우선 적용
특히 의도·희망·전언 / 완료 여부 / 반문·판단과 관련된 문형은 glossary 해석을 그대로 반영
8. 이두 항목(한국어 조사나 어미의 한자 표기)은 한국어 조사나 어미로 적용
[한문 원문에 대한 정보]
{text_info}
[Input XML]
{input_data}
[Output XML 형식 — 반드시 이 구조]
<text_unit id="...">
<translation lang="KOR" status="draft" model="{model}">
...
<!--Input Xml에 있는 hanmun_text 요소의 하위 요소들은 그대로 유지하면서 요소 값만 번역 -->
...
</translation>
</text_unit>
""".strip()
elif action == "TRANSLATE_ENG":
return f"""
You are a translation assistant specialized in accurately translating Classical Chinese texts based on a **reviewed glossary**.
The Input XML below contains:
(1) the original Classical Chinese text with standardized punctuation, and
(2) a reviewed glossary.
This glossary contains authoritative interpretations required for correctly understanding the text.
When translating, you must prioritize the glossary’s definitions and grammatical interpretations.
[Translation Rules]
1. Output XML only. Do not include explanations or code blocks (```xml).
2. The id attribute of <text_unit> must remain identical to the input.
3. Translate the Classical Chinese text in <hanmun_text> into English and place it inside:
<translation lang="ENG" status="draft" model="{model}">
4. Preserve all child elements inside <hanmun_text>
(<annotation>, <commentary>, <imperial_inscription>, <title>, <preface>, <poem>, <ref>, <fnote>, <이두>, <인명>, <지명>, <서명>, etc.)
while translating only their textual content into English.
5. The translation should be written in clear and natural modern English understandable to university students and general readers unfamiliar with Classical Chinese.
6. You may divide sentences when necessary, but do not add meanings not present in the original text.
7. For glossary entries, follow these principles:
- Person / Place / Event / Timespan / Object / Record / ArtWork / Food / Clothing / Concept, etc.:
translate according to the glossary definitions.
- For Grammar entries (grammatical patterns and particles),
apply the glossary’s interpretation rules with highest priority.
In particular, preserve the glossary’s interpretation regarding:
intention, desire, reported speech, completion, rhetorical questions, and judgments.
8. 이두 (Korean grammatical markers written in Chinese characters) should be rendered as appropriate English grammatical expressions.
[Information about the Classical Chinese text]
{text_info}
[Input XML]
{input_data}
[Required Output XML Structure]
<text_unit id="...">
<translation lang="ENG" status="draft" model="{model}">
...
<!-- Preserve child elements from hanmun_text and translate only their contents -->
...
</translation>
</text_unit>
""".strip()
elif action == "TRANSLATE_KORnENG":
return f"""
You are a translation assistant specialized in accurately translating Classical Chinese texts based on a **reviewed glossary**.
The Input XML below contains:
(1) the original Classical Chinese text with standardized punctuation, and
(2) a reviewed glossary.
This glossary contains authoritative interpretations required for correctly understanding the text.
When translating, you must prioritize the glossary’s definitions and grammatical interpretations.
[Translation Rules]
1. Output XML only. Do not include explanations or code blocks (```xml).
2. The id attribute of <text_unit> must remain identical to the input.
3. Translate the Classical Chinese text in <hanmun_text> into:
- modern Korean inside:
<translation lang="KOR" status="draft" model="{model}">
- modern English inside:
<translation lang="ENG" status="draft" model="{model}">
4. Preserve all child elements inside <hanmun_text>
(<annotation>, <commentary>, <imperial_inscription>, <title>, <preface>, <poem>, <ref>, <fnote>, <이두>, <인명>, <지명>, <서명>, etc.)
while translating only their textual content into Korean and English.
5. The Korean translation should be written in clear and natural modern Korean understandable to university students and general readers unfamiliar with Classical Chinese.
6. The English translation should be written in clear and natural modern English understandable to university students and general readers unfamiliar with Classical Chinese.
7. You may divide sentences when necessary, but do not add meanings not present in the original text.
8. For glossary entries, follow these principles:
- Person / Place / Event / Timespan / Object / Record / ArtWork / Food / Clothing / Concept, etc.:
translate according to the glossary definitions.
- For Grammar entries (grammatical patterns and particles),
apply the glossary’s interpretation rules with highest priority.
In particular, preserve the glossary’s interpretation regarding:
intention, desire, reported speech, completion, rhetorical questions, and judgments.
9. 이두 (Korean grammatical markers written in Chinese characters) should:
- be rendered as appropriate Korean particles/endings in the Korean translation
- be rendered as appropriate English grammatical expressions in the English translation
10. The Korean and English translations should reflect the same interpretation of the original text and glossary.
[Information about the Classical Chinese text]
{text_info}
[Input XML]
{input_data}
[Required Output XML Structure]
<text_unit id="...">
<translation lang="KOR" status="draft" model="{model}">
...
<!-- Preserve child elements from hanmun_text and translate only their contents -->
...
</translation>
<translation lang="ENG" status="draft" model="{model}">
...
<!-- Preserve child elements from hanmun_text and translate only their contents -->
...
</translation>
</text_unit>
""".strip()
def _text_info(row, key: str) -> str:
category = row.get("category") or ""
remark = row.get("remark") or ""
if category and remark:
return (f"아래 Input XML의 한문 문장에 대한 기본 정보는 다음과 같습니다. 글의 성격에 부합하는 Output을 제공해 주세요.\n"
f"1. Id (식별자): {key}\n"
f"2. Category (글의 유형/범주): {category}\n"
f"3. Remark (글의 성격 또는 내용에 관한 정보): {remark}\n" )
return ""