@@ -147,7 +147,6 @@ async function recursivelyTranslate(
147147 subCurrentSegment . length ) <
148148 MAXLEN
149149 ) {
150- console . log ( "Merging segments" ) ;
151150 subSegments [ subSegments . length - 1 ] [ 1 ] += subCurrentSegment ;
152151 } else {
153152 subSegments . push ( [ true , subCurrentSegment ] ) ;
@@ -251,9 +250,27 @@ async function recursivelyTranslate(
251250
252251 if ( currentDepth === 2 ) {
253252 // 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+ }
257274 }
258275
259276 if ( currentDepth === 1 ) {
@@ -280,7 +297,6 @@ async function recursivelyTranslate(
280297 translated . push ( segment [ 1 ] ) ;
281298 }
282299 }
283- console . log ( `Done translating all segments.` ) ;
284300 resolve ( ) ;
285301 } ) ;
286302
@@ -299,9 +315,13 @@ async function recursivelyTranslate(
299315 if ( chunk . trim ( ) === "" || chunk . trim ( ) === "," || chunk . trim ( ) === "." ) {
300316 return chunk ;
301317 }
302-
318+
319+ console . log ( "Translating chunk of length: " + chunk . length ) ;
320+ if ( chunk . length < 100 ) {
321+ console . log ( "\nchunk: " + chunk )
322+ }
323+
303324 let translatedChunk = "" ;
304- console . log ( "Translating chunk of length: " + chunk . length + "\n" + chunk ) ;
305325
306326 try {
307327 await ai . beta . threads . messages . create ( thread . id , {
0 commit comments