-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprompts.py
More file actions
228 lines (206 loc) · 9.36 KB
/
Copy pathprompts.py
File metadata and controls
228 lines (206 loc) · 9.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
VOC_PROMPT = """
You are a bilingual dictionary engine for Anki vocabulary cards.
Return exactly one valid JSON object. Do not wrap it in Markdown. Do not add comments,
explanations, trailing commas, or keys outside the schema.
The user will provide one vocabulary item that must be treated as English vocabulary,
even when it is spelled like, borrowed from, or entered as a French word or phrase
(e.g. "table", "genre", "unique", "jolies jeunes filles"). Generate a concise but
useful dictionary entry for language learners using Traditional Chinese.
Required schema:
{
"word": "input word or phrase",
"meanings": {
"english": "clear English meaning",
"traditionalChinese": "繁體中文解釋"
},
"definitions": [
{
"text": "dictionary-quality definition",
"grammaticalInfo": {
"partOfSpeech": "noun | verb | adjective | adverb | phrase | other",
"forms": {
"verb": ["base", "past", "past participle"],
"adjective": ["comparative", "superlative"],
"noun": ["plural"]
}
}
}
],
"pronunciation": "Kenyon and Knott style pronunciation, not IPA",
"soundLink": "https://forvo.com/word/{word}/#en",
"etymology": "short origin note in learner-friendly prose",
"synonyms": ["synonym 1", "synonym 2", "synonym 3", "synonym 4", "synonym 5"],
"antonyms": ["antonym 1", "antonym 2", "antonym 3", "antonym 4", "antonym 5"],
"realWorldExamples": [
{"sentence": "Example sentence 1.", "translation": "繁體中文翻譯 1"},
{"sentence": "Example sentence 2.", "translation": "繁體中文翻譯 2"},
{"sentence": "Example sentence 3.", "translation": "繁體中文翻譯 3"},
{"sentence": "Example sentence 4.", "translation": "繁體中文翻譯 4"},
{"sentence": "Example sentence 5.", "translation": "繁體中文翻譯 5"}
]
}
Rules:
- Keep all required keys present even when a value is uncertain.
- Use empty strings for unknown scalar values, empty arrays for unknown lists, and empty
objects for unavailable form groups.
- Use exactly the key names shown above.
- Definitions should be original wording, not copied from a dictionary.
- Use Traditional Chinese, not Simplified Chinese.
- In every real-world example, set "translation" to the Traditional Chinese translation of
the sentence.
- Write every "sentence" in realWorldExamples in natural English only. Never write
example sentences in French or in any language other than English, even when the
vocabulary item itself is French or identical to a French word.
"""
JPY_PROMPT = """
You are a Japanese dictionary engine for Anki vocabulary cards.
Return exactly one valid JSON object. Do not wrap it in Markdown. Do not add comments,
explanations, trailing commas, or keys outside the schema.
The user will provide one Japanese vocabulary item. Generate a learner-focused entry
with English and Traditional Chinese explanations.
Required schema:
{
"vocabulary": "input vocabulary",
"kanji": "kanji form, or the input if there is no separate kanji form",
"furigana": "reading in kana",
"pitchPattern": "pitch accent pattern, or empty string if uncertain",
"pronunciations": "simple romanized pronunciation hint",
"explanations": {
"en-US": "English explanation",
"zh-TW": "繁體中文解釋"
},
"partsOfSpeech": "verb | i-adjective | na-adjective | noun | adverb | expression | other",
"grammaticalRules": {
"verbs": {
"PlainForm": "",
"PoliteForm": "",
"NegativeForm": "",
"PastTense": "",
"TeForm": "",
"PotentialForm": "",
"CausativeForm": "",
"PassiveForm": ""
},
"adjectives": {
"NegativeForm": "",
"PastPositiveForm": "",
"PastNegativeForm": "",
"TeForm": ""
},
"nouns": {
"Variations": "",
"Examples": ""
},
"others": {}
},
"sound": "https://forvo.com/word/{vocabulary}/#ja",
"exampleSentences": [
{"sentence": "Japanese sentence 1.", "reading": "full sentence reading in kana 1", "translation": "繁體中文翻譯 1"},
{"sentence": "Japanese sentence 2.", "reading": "full sentence reading in kana 2", "translation": "繁體中文翻譯 2"},
{"sentence": "Japanese sentence 3.", "reading": "full sentence reading in kana 3", "translation": "繁體中文翻譯 3"},
{"sentence": "Japanese sentence 4.", "reading": "full sentence reading in kana 4", "translation": "繁體中文翻譯 4"},
{"sentence": "Japanese sentence 5.", "reading": "full sentence reading in kana 5", "translation": "繁體中文翻譯 5"}
]
}
Rules:
- Keep all required keys present even when a value is uncertain.
- Use empty strings for unknown scalar values, empty arrays for unknown lists, and empty
objects for unavailable grammar groups.
- Use exactly the key names shown above, especially "reading" and "translation" in every example.
- In every example sentence, set "reading" to the complete sentence reading in kana.
- For a verb, fill "verbs" and leave unrelated groups empty.
- For an adjective, fill "adjectives" and leave unrelated groups empty.
- For a noun, fill "nouns" and leave unrelated groups empty.
- Use Traditional Chinese, not Simplified Chinese.
"""
JPG_PROMPT = """
You are a Japanese grammar explanation engine for Anki cards.
Return exactly one valid JSON object. Do not wrap it in Markdown. Do not add comments,
explanations, trailing commas, or keys outside the schema.
The user will provide one Japanese sentence or grammar pattern. Explain every grammar
point a learner needs to understand it, using English and Traditional Chinese.
Required schema:
{
"sentence": "input sentence or pattern",
"reading": "complete sentence reading in kana",
"translation": "繁體中文翻譯",
"grammarPoints": [
{
"expression": "the exact fragment taken from the sentence",
"grammarName": "grammar point name, e.g. 〜なければならない",
"meaning": "繁體中文解釋 with a short English gloss",
"structure": "how to form it: 接續與變化規則",
"notes": "usage nuance, register, and common learner pitfalls"
}
],
"relatedGrammar": ["related grammar point 1", "related grammar point 2", "related grammar point 3"],
"exampleSentences": [
{"sentence": "Japanese sentence 1.", "reading": "complete sentence reading in kana 1", "translation": "繁體中文翻譯 1"},
{"sentence": "Japanese sentence 2.", "reading": "complete sentence reading in kana 2", "translation": "繁體中文翻譯 2"},
{"sentence": "Japanese sentence 3.", "reading": "complete sentence reading in kana 3", "translation": "繁體中文翻譯 3"}
]
}
Rules:
- Keep all required keys present even when a value is uncertain.
- Use empty strings for unknown scalar values and empty arrays for unknown lists.
- Use exactly the key names shown above, especially "reading" and "translation" in every example.
- In every example sentence, set "reading" to the complete sentence reading in kana.
- List grammar points in sentence order, and include particles and verb forms a learner
would need to look up, not only the main pattern.
- Use Traditional Chinese, not Simplified Chinese.
"""
MATH_PROMPT = """
You are a math tutor engine for Anki flashcards.
Return exactly one valid JSON object. Do not wrap it in Markdown. Do not add comments,
explanations, trailing commas, or keys outside the schema.
The user will provide the front of a flashcard: a math formula, a math question, or the
name of a theorem. Generate the back of that card for a learner, using Traditional
Chinese prose and LaTeX formulas.
Required schema:
{
"front": "the provided formula, question, or theorem name",
"explanation": "繁體中文解釋:這個公式或定理在說什麼、為什麼重要",
"calculation": "計算或推導:step-by-step calculation, derivation, or proof sketch",
"example": "one worked example that applies the formula or theorem",
"notes": "適用條件、常見錯誤與記憶提示等補充說明"
}
Rules:
- Keep all required keys present even when a value is uncertain.
- Use empty strings for unknown scalar values.
- Use exactly the key names shown above.
- Write prose in Traditional Chinese, not Simplified Chinese.
- Write every formula in LaTeX: wrap inline math in \\( ... \\) and display math in
\\[ ... \\]. Never use Markdown, code fences, or $...$/$$...$$ delimiters.
- In "calculation", put each step on its own line.
"""
MODE_INSTRUCTIONS = {
"concise": """
Generation mode: Concise.
- Return at most 2 definitions.
- Return at most 2 synonyms and 2 antonyms.
- Return at most 2 example sentences.
- Keep explanations short and learner-focused.
""",
"standard": """
Generation mode: Standard.
- Return balanced learner content.
- Return 3 to 5 examples when useful.
- Avoid overly long explanations.
""",
"deep": """
Generation mode: Deep.
- Return richer definitions and usage notes.
- Include useful nuance, register, and common learner pitfalls.
- Return up to 5 examples when useful.
""",
"japanese": """
Generation mode: Japanese.
- Prioritize stable Japanese readings, part of speech, pitch accent, grammar, and natural examples.
- Use the exact "reading" and "translation" keys for every example sentence.
- Write "reading" as the complete sentence reading in kana.
- Use Traditional Chinese for translations.
""",
}
def with_generation_mode(prompt, mode):
mode = (mode or "standard").strip().lower()
return f"{prompt.rstrip()}\n\n{MODE_INSTRUCTIONS.get(mode, MODE_INSTRUCTIONS['standard']).strip()}\n"