@@ -147,7 +147,6 @@ async function recursivelyTranslate(
147
147
subCurrentSegment . length ) <
148
148
MAXLEN
149
149
) {
150
- console . log ( "Merging segments" ) ;
151
150
subSegments [ subSegments . length - 1 ] [ 1 ] += subCurrentSegment ;
152
151
} else {
153
152
subSegments . push ( [ true , subCurrentSegment ] ) ;
@@ -251,9 +250,27 @@ async function recursivelyTranslate(
251
250
252
251
if ( currentDepth === 2 ) {
253
252
// We are closing a segment element.
254
- segments . push ( [ true , currentSegment ] ) ;
255
- currentSegment = "" ;
256
- isRecording = false ;
253
+ if (
254
+ tagName === "LATEXINLINE" ||
255
+ tagName === "LATEX" ||
256
+ tagName === "SNIPPET" ||
257
+ tagName === "SCHEMEINLINE" ||
258
+ tagName === "SCHEME"
259
+ ) {
260
+ segments . push ( [ false , currentSegment ] ) ;
261
+ } else {
262
+ if (
263
+ segments . length > 0 &&
264
+ segments [ segments . length - 1 ] [ 0 ] &&
265
+ ( segments [ segments . length - 1 ] [ 1 ] . length +
266
+ currentSegment . length ) <
267
+ MAXLEN
268
+ ) {
269
+ segments [ segments . length - 1 ] [ 1 ] += currentSegment ;
270
+ } else {
271
+ segments . push ( [ true , currentSegment ] ) ;
272
+ }
273
+ }
257
274
}
258
275
259
276
if ( currentDepth === 1 ) {
@@ -280,7 +297,6 @@ async function recursivelyTranslate(
280
297
translated . push ( segment [ 1 ] ) ;
281
298
}
282
299
}
283
- console . log ( `Done translating all segments.` ) ;
284
300
resolve ( ) ;
285
301
} ) ;
286
302
@@ -299,9 +315,13 @@ async function recursivelyTranslate(
299
315
if ( chunk . trim ( ) === "" || chunk . trim ( ) === "," || chunk . trim ( ) === "." ) {
300
316
return chunk ;
301
317
}
302
-
318
+
319
+ console . log ( "Translating chunk of length: " + chunk . length ) ;
320
+ if ( chunk . length < 100 ) {
321
+ console . log ( "\nchunk: " + chunk )
322
+ }
323
+
303
324
let translatedChunk = "" ;
304
- console . log ( "Translating chunk of length: " + chunk . length + "\n" + chunk ) ;
305
325
306
326
try {
307
327
await ai . beta . threads . messages . create ( thread . id , {
0 commit comments