Skip to content
Snippets Groups Projects
Commit f3c5e4c1 authored by Juuso Rytilahti's avatar Juuso Rytilahti
Browse files

Much cleaner version of the multi-step translation

parent 87529cb3
Branches
No related tags found
No related merge requests found
......@@ -297,9 +297,9 @@ if file_content:
CHUNK_SIZE_PLAIN_TEXT_OR_MD_GPT_4 = 290
chunks = split_into_chunks(file_content, chunk_size=CHUNK_SIZE_LATEX_GPT_4)
final_text = ""
original_full_translation = ""
previous_messages = None
print("input.md has been broken down to "+str(len(chunks)) + " chunks.")
if(False):
for i, chunk in enumerate(chunks):
print(" ")
print(" ")
......@@ -319,27 +319,28 @@ if file_content:
#Divination between chuns to add readability (Normally woith GPT-3.5 if the translation fails, the translation of the whole chunk fails)
chunk_divination = "\n\n---\n# Chunk "+ str(i)+"\n---\n\n"
if not USE_DEBUG_TEXT_IN_THE_OUTPUT:
final_text = final_text + trans # exclude the debug text
original_full_translation = original_full_translation + trans # exclude the debug text
else:
final_text =final_text + chunk_divination + trans
original_full_translation =original_full_translation + chunk_divination + trans
# In case the translation fails to an error when only part of the translation is done
# write the currently translated text also to the output.md
write_to_file("original_full_translation.md", original_full_translation)
#GET IMPROVED VERSION WITH TRATIONALE
improved_trans_with_rationale = get_improved_translation_for_chunk(chunk, trans)
write_to_file("./debug/chunk" + str(i) + "_improved_translation_with_rationale.md", improved_trans_with_rationale)
#EXTRACT THE FINAL TRANSLATION
final_translation_of_chunk = extract_final_translation(improved_trans_with_rationale)
write_to_file("./debug/chunk"+str(i)+"_final_translation.md", final_translation_of_chunk)
final_text = final_text + final_translation_of_chunk
# Just in case, write the current progress to output files.
write_to_file("original_full_translation.md", original_full_translation)
write_to_file("output.md", final_text)
# Create the better versions
if(False):
for i, chunk in enumerate(chunks):
#TODO add error management The translations should be gained through better way
translation = read_from_file('./debug/chunk'+str(i)+'_translation.md')
improved_trans = get_improved_translation_for_chunk(chunk, translation)
write_to_file("./debug/chunk" + str(i) + "_improved_translation.md", improved_trans)
final_text = final_text + improved_trans
#Parse the final_text
for i, chunk in enumerate(chunks):
final_translation = read_from_file('./debug/chunk'+str(i)+'_improved_translation.md')
final_translation = extract_final_translation(final_translation)
write_to_file("./debug/chunk" + str(i) + "_final_translation.md", final_translation)
final_text = final_text+final_translation
print(" ")
print(" ")
write_to_file("original_full_translation.md", original_full_translation)
write_to_file("output.md", final_text)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment