@@ -50,32 +50,27 @@ def translate_text(text, target_language, special=False):
50
50
return text
51
51
print (f" Translating text: { text [:50 ]} ..." )
52
52
53
- retries = 3
54
- for attempt in range (retries ):
55
- try :
56
- response = client .chat .completions .create (
57
- model = MODEL_NAME ,
58
- messages = [
59
- {"role" : "system" , "content" : create_translation_prompt (target_language , special )},
60
- {"role" : "user" , "content" : text }
61
- ],
62
- stream = False
63
- )
64
- if not response or not response .choices or not response .choices [0 ].message .content :
65
- print (f" Error: Translation response is empty or invalid: { response } " )
66
- if response and response .choices :
67
- translated_text = response .choices [0 ].message .content
68
- return translated_text
69
- else :
70
- print (f" Translation failed on attempt { attempt + 1 } ." )
71
- if attempt == retries - 1 :
72
- return None
73
- except Exception as e :
74
- print (f" Translation failed with error on attempt { attempt + 1 } : { e } " )
75
- if attempt == retries - 1 :
76
- return None
77
- time .sleep (1 ) # Wait before retrying
78
- return None
53
+ try :
54
+ response = client .chat .completions .create (
55
+ model = MODEL_NAME ,
56
+ messages = [
57
+ {"role" : "system" , "content" : create_translation_prompt (target_language , special )},
58
+ {"role" : "user" , "content" : text }
59
+ ],
60
+ stream = False
61
+ )
62
+ if not response or not response .choices or not response .choices [0 ].message .content :
63
+ print (f" Error: Translation response is empty or invalid: { response } " )
64
+ return None
65
+ if response and response .choices :
66
+ translated_text = response .choices [0 ].message .content
67
+ return translated_text
68
+ else :
69
+ print (f" Translation failed." )
70
+ return None
71
+ except Exception as e :
72
+ print (f" Translation failed with error: { e } " )
73
+ return None
79
74
80
75
def translate_front_matter (front_matter , target_language , input_file ):
81
76
print (f" Translating front matter for: { input_file } " )
0 commit comments