@@ -117,7 +117,7 @@ def build_retouch_prompt() -> str:
117117
118118async def summarize_text (transcript : str , gemini_client ) -> str :
119119 """Generates a journalist-friendly summary of the transcript.
120- Uses model chain: primary (gemma) → fallbacks.
120+ Uses model chain: primary (gemma) → fallbacks with async retries .
121121 """
122122 if not gemini_client :
123123 return "Summarization disabled: Gemini API key not configured or client failed to load."
@@ -129,25 +129,35 @@ async def summarize_text(transcript: str, gemini_client) -> str:
129129 from model_manager import try_model_chain
130130
131131 chain = get_model_chain ("summary" )
132- config = types .GenerateContentConfig (temperature = 0.3 )
133-
134- response = await asyncio .to_thread (
135- try_model_chain ,
136- gemini_client ,
137- chain ,
138- [prompt , transcript ],
139- config ,
140- "summary"
141- )
132+ gen_config = types .GenerateContentConfig (temperature = 0.3 )
133+ max_retries = config .Config .MODEL_RETRY_COUNT
134+ retry_delay = config .Config .MODEL_RETRY_DELAY_SECONDS
135+
136+ for attempt in range (max_retries ):
137+ response = await asyncio .to_thread (
138+ try_model_chain ,
139+ gemini_client ,
140+ chain ,
141+ [prompt , transcript ],
142+ gen_config ,
143+ "summary"
144+ )
145+
146+ if response and response .text :
147+ return response .text
148+
149+ # If all models failed and this wasn't the last attempt, retry
150+ if attempt < max_retries - 1 :
151+ sleep_time = retry_delay * (attempt + 1 )
152+ log ("GEMINI" , f"All models failed for summary, retrying after { sleep_time } s..." )
153+ await asyncio .sleep (sleep_time )
142154
143- if response and response .text :
144- return response .text
145155 return "❌ Error generating summary: all models failed"
146156
147157
148158async def retouch_transcript (transcript : str , gemini_client ) -> str :
149159 """Retouch/clean up transcript: fix typos, punctuation, add paragraph breaks.
150- Uses model chain: primary (gemma) → fallbacks.
160+ Uses model chain: primary (gemma) → fallbacks with async retries .
151161 """
152162 if not gemini_client :
153163 return transcript # Return original if no client
@@ -159,19 +169,29 @@ async def retouch_transcript(transcript: str, gemini_client) -> str:
159169 from model_manager import try_model_chain
160170
161171 chain = get_model_chain ("retouch" )
162- config = types .GenerateContentConfig (temperature = 0.3 )
163-
164- response = await asyncio .to_thread (
165- try_model_chain ,
166- gemini_client ,
167- chain ,
168- contents ,
169- config ,
170- "retouch"
171- )
172+ gen_config = types .GenerateContentConfig (temperature = 0.3 )
173+ max_retries = config .Config .MODEL_RETRY_COUNT
174+ retry_delay = config .Config .MODEL_RETRY_DELAY_SECONDS
175+
176+ for attempt in range (max_retries ):
177+ response = await asyncio .to_thread (
178+ try_model_chain ,
179+ gemini_client ,
180+ chain ,
181+ contents ,
182+ gen_config ,
183+ "retouch"
184+ )
185+
186+ if response and response .text :
187+ return response .text
188+
189+ # If all models failed and this wasn't the last attempt, retry
190+ if attempt < max_retries - 1 :
191+ sleep_time = retry_delay * (attempt + 1 )
192+ log ("GEMINI" , f"All models failed for retouch, retrying after { sleep_time } s..." )
193+ await asyncio .sleep (sleep_time )
172194
173- if response and response .text :
174- return response .text
175195 return transcript # Return original on error
176196
177197
0 commit comments