@@ -26,10 +26,7 @@ async def start_handler(message: Message, app: App):
2626 You can also <b>reply</b> to any text message from me to chat about its transcript or summary with LLM.
2727 """
2828 )
29- await send_safe (
30- message .chat .id ,
31- welcome_message
32- )
29+ await send_safe (message .chat .id , welcome_message )
3330
3431
3532@commands_menu .botspot_command ("help" , "Show this help message" )
@@ -63,14 +60,13 @@ async def help_handler(message: Message, app: App):
6360 So you might need to explore that as well to understand it. Basic template is available <a href="https://github.com/calmmage/botspot-template">here</a>
6461 """
6562 )
66- await send_safe (
67- message .chat .id ,
68- help_message
69- )
63+ await send_safe (message .chat .id , help_message )
64+
7065
7166class Language (BaseModel ):
7267 language_code : str
7368
69+
7470@router .message (F .audio | F .voice | F .video | F .document | F .video_note )
7571async def media_handler (message : Message , app : App , state : FSMContext ):
7672 assert message .from_user is not None
@@ -99,7 +95,7 @@ async def media_handler(message: Message, app: App, state: FSMContext):
9995 notif = await reply_safe (
10096 message , "Processing your media file. Estimating transcription time..."
10197 )
102-
98+
10399 # Transcribe the audio
104100 transcription = await app .process_message (
105101 message ,
@@ -128,9 +124,9 @@ async def media_handler(message: Message, app: App, state: FSMContext):
128124
129125 # Get and display cost information
130126 cost_info = await app .get_total_cost (username , message_id = message .message_id )
131- total_cost = cost_info ["total_cost" ]
127+ total_cost = float ( cost_info ["total_cost" ])
132128 if total_cost > 0.01 :
133- operation_costs = float ( cost_info ["operation_costs" ])
129+ operation_costs = cost_info ["operation_costs" ]
134130
135131 cost_breakdown = "\n " .join (
136132 [
@@ -150,7 +146,7 @@ async def media_handler(message: Message, app: App, state: FSMContext):
150146
151147def create_notification_callback (notification_message : Message ):
152148 text = notification_message .text
153-
149+
154150 async def callback (update_text : str ):
155151 nonlocal text
156152 assert text is not None
@@ -159,6 +155,7 @@ async def callback(update_text: str):
159155
160156 return callback
161157
158+
162159async def ask_user_language (message : Message , app : App , state : FSMContext ):
163160 assert message .from_user is not None
164161 username = message .from_user .username
@@ -190,18 +187,21 @@ async def ask_user_language(message: Message, app: App, state: FSMContext):
190187 await message .reply ("No language provided, please retry." )
191188 return
192189 parsed_language : Language = await aquery_llm_structured (
193- prompt = language_str ,
190+ prompt = language_str ,
194191 output_schema = Language ,
195192 model = "gpt-4.1-nano" ,
196193 system_message = "You are a language detection assistant. Your goal is to return the language code in ISO 639-1 format (e.g., 'en' for English, 'ru' for Russian)." ,
197194 user = username ,
198195 )
199196 language_code = parsed_language .language_code
200- logger .info (f"User input: { language_str } , detected language code: { language_code } " )
197+ logger .info (
198+ f"User input: { language_str } , detected language code: { language_code } "
199+ )
201200 else :
202201 language_code = language
203202 return language_code
204203
204+
205205@router .message ()
206206async def chat_handler (message : Message , app : App ):
207207 if message .reply_to_message :
@@ -224,7 +224,9 @@ async def _reply_chat_handler(message: Message, app: App):
224224 prompt = await get_message_text (message , include_reply = True )
225225
226226 # Process chat request
227- response = await app .chat_about_transcript (full_prompt = prompt , username = username , message_id = message .message_id )
227+ response = await app .chat_about_transcript (
228+ full_prompt = prompt , username = username , message_id = message .message_id
229+ )
228230 response = markdown_to_html (response )
229231
230232 cost = await app .get_total_cost (username , message_id = message .message_id )
@@ -246,6 +248,6 @@ async def _basic_chat_handler(message: Message, app: App):
246248 await answer_safe (
247249 message ,
248250 "This is a Whisper bot. "
249- "\n \n Send an Audio, Video, Voice or Video Note message to transcribe and summarize it." ,
251+ "\n \n Send an Audio, Video, Voice or Video Note message to transcribe and summarize it."
250252 "\n \n <b>Reply</b> to a text message from bot to chat about its transcript or summary with LLM" ,
251253 )
0 commit comments