Skip to content

Commit bb1748d

Browse files
committed
ll;m edit
1 parent 1135c1e commit bb1748d

File tree

4 files changed

+54
-15
lines changed

4 files changed

+54
-15
lines changed

next/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## now
44

55
- real cloning
6+
- handle different romanization prompts for languages not just chinese
67
- summarize kaikki definitions w llm
78

89
## future

next/app/api/translate/route.ts

+28-9
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ if (!process.env.DEEPINFRA_API_KEY) {
1616
const romanizationSchema = z.object({
1717
translation: z.string(),
1818
romanization: z.string(),
19+
edited: z.string(),
1920
});
2021

2122
const standardSchema = z.object({
2223
translation: z.string(),
24+
edited: z.string(),
2325
});
2426

2527
const inputSchema = z.object({
@@ -34,17 +36,34 @@ export async function POST(request: NextRequest) {
3436

3537
const prompt =
3638
language === Language.CHINESE_CN
37-
? `Translate the following text into Simplified Chinese (Mandarin).
38-
Make sure to:
39-
1. Use only Simplified Chinese characters (not Traditional).
40-
2. Use pinyin with diacritic marks (not numeric).
41-
3. Return a valid JSON object with:
42-
- "translation" key: Simplified Chinese character translation
43-
- "romanization" key: pinyin romanization with diacritic marks (NOT numeric) and syllables separated by spaces.
39+
? `Given the following text, return:
40+
1. A grammatically corrected version of the original text with proper punctuation, ensuring complete sentences and avoiding fragments
41+
2. A translation into Simplified Chinese (Mandarin)
42+
3. Pinyin romanization with diacritic marks
43+
44+
When correcting the text:
45+
- Join sentence fragments into complete thoughts
46+
- Ensure proper subject-verb relationships
47+
- Maintain the original meaning while making the text more cohesive
48+
49+
Return a valid JSON object with:
50+
- "edited" key: corrected original text with complete sentences
51+
- "translation" key: Simplified Chinese character translation
52+
- "romanization" key: pinyin with diacritic marks (NOT numeric) and syllables separated by spaces
4453
4554
Text: ${text}`
46-
: `Translate the following text into ${language}.
47-
Return a valid JSON object with a single key "translation" whose value is the translation.
55+
: `Given the following text, return:
56+
1. A grammatically corrected version of the original text with proper punctuation, ensuring complete sentences and avoiding fragments
57+
2. A translation into ${language}
58+
59+
When correcting the text:
60+
- Join sentence fragments into complete thoughts
61+
- Ensure proper subject-verb relationships
62+
- Maintain the original meaning while making the text more cohesive
63+
64+
Return a valid JSON object with:
65+
- "edited" key: corrected original text with complete sentences
66+
- "translation" key: translation
4867
4968
Text: ${text}`;
5069

next/components/assembly-view.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ const AssemblyView: () => JSX.Element = () => {
203203
...f,
204204
translated: result.data.translation,
205205
romanization: result.data.romanization,
206+
edited: result.data.edited,
206207
}
207208
: f
208209
)

next/components/fragment.tsx

+24-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export type Fragment = {
2626
createdAt: number;
2727
translated?: string;
2828
romanization?: string;
29+
edited?: string;
2930
isPartial?: boolean;
3031
};
3132

@@ -95,11 +96,20 @@ export const FragmentComponent = ({
9596
if (!showTranslation) {
9697
return (
9798
<div
98-
className={`border border-black p-4 rounded-md ${
99+
className={`border-2 ${
100+
fragment.edited && fragment.edited !== fragment.text
101+
? "border-dotted border-black/70 bg-amber-50/30"
102+
: "border-solid border-black"
103+
} p-4 rounded-md ${
99104
fragment.type === "speech" ? "bg-black/5" : ""
100105
} ${isPartial ? "opacity-50" : ""}`}
101106
>
102-
<div>{fragment.text}</div>
107+
<div>{fragment.edited || fragment.text}</div>
108+
{fragment.edited && fragment.edited !== fragment.text && (
109+
<div className="text-xs mt-1 text-gray-500">
110+
Original: {fragment.text}
111+
</div>
112+
)}
103113
</div>
104114
);
105115
}
@@ -208,11 +218,15 @@ export const FragmentComponent = ({
208218
<ResizablePanel defaultSize={70}>
209219
<div className="grid grid-cols-2 gap-4 items-start">
210220
<div
211-
className={`border border-black p-4 rounded-md ${
221+
className={`border-2 ${
222+
fragment.edited && fragment.edited !== fragment.text
223+
? "border-dotted border-black/70 bg-amber-50/30"
224+
: "border-solid border-black"
225+
} p-4 rounded-md ${
212226
fragment.type === "speech" ? "bg-black/5" : ""
213227
} ${isPartial ? "opacity-50" : ""}`}
214228
>
215-
{fragment.text}
229+
{fragment.edited || fragment.text}
216230
</div>
217231
<div className="border border-black p-4 rounded-md">
218232
{fragment.translated ? (
@@ -244,11 +258,15 @@ export const FragmentComponent = ({
244258
<>
245259
<div className="grid grid-cols-2 gap-4 items-start">
246260
<div
247-
className={`border border-black p-4 rounded-md ${
261+
className={`border-2 ${
262+
fragment.edited && fragment.edited !== fragment.text
263+
? "border-dotted border-black/70 bg-amber-50/30"
264+
: "border-solid border-black"
265+
} p-4 rounded-md ${
248266
fragment.type === "speech" ? "bg-black/5" : ""
249267
} ${isPartial ? "opacity-50" : ""}`}
250268
>
251-
{fragment.text}
269+
{fragment.edited || fragment.text}
252270
</div>
253271
<div className="border border-black p-4 rounded-md">
254272
{fragment.translated ? (

0 commit comments

Comments
 (0)