@@ -72,7 +72,7 @@ def Talk(self, request_iterator, context):
7272import os
7373from concurrent import futures
7474from dataclasses import dataclass
75- from typing import Any , Callable , Dict , Iterator , Optional
75+ from typing import Any , Callable , Dict , Optional
7676
7777import grpc
7878from grpc import ServerInterceptor
@@ -176,6 +176,7 @@ def abort(ignored_request, context):
176176 context .abort (
177177 grpc .StatusCode .UNAUTHENTICATED , "Invalid authorization token"
178178 )
179+
179180 return grpc .unary_unary_rpc_method_handler (abort )
180181
181182
@@ -223,9 +224,7 @@ def Talk(self, request_iterator, context):
223224 # RESPONSE BUILDERS - Send data back to Rapida
224225 # ========================================================================
225226
226- def response (
227- self , code : int = 200 , success : bool = True , ** kwargs
228- ) -> TalkOutput :
227+ def response (self , code : int = 200 , success : bool = True , ** kwargs ) -> TalkOutput :
229228 """
230229 Build a generic response to send back to Rapida.
231230
@@ -338,13 +337,12 @@ def tool_call(
338337 for k , v in (args or {}).items ():
339338 _args [str (k )] = string_to_any (str (v ))
340339
341- return self .response (tool = ConversationToolCall (
342- id = str (msg_id ),
343- toolId = str (tool_id ),
344- name = str (name ),
345- args = _args
346- ))
347-
340+ return self .response (
341+ tool = ConversationToolCall (
342+ id = str (msg_id ), toolId = str (tool_id ), name = str (name ), args = _args
343+ )
344+ )
345+
348346 def tool_call_result (
349347 self , msg_id : str , tool_id : str , name : str , result : Any , success : bool = True
350348 ) -> TalkOutput :
@@ -373,17 +371,17 @@ def tool_call_result(
373371 # For non-dict results, store under "result" key
374372 _args ["result" ] = string_to_any (str (result ))
375373
376- return self .response (toolResult = ConversationToolResult (
377- id = str (msg_id ),
378- toolId = str (tool_id ),
379- name = str (name ),
380- success = bool (success ),
381- args = _args
382- ))
374+ return self .response (
375+ toolResult = ConversationToolResult (
376+ id = str (msg_id ),
377+ toolId = str (tool_id ),
378+ name = str (name ),
379+ success = bool (success ),
380+ args = _args ,
381+ )
382+ )
383383
384- def transfer_call (
385- self , msg_id : str , args : Dict [str , Any ]
386- ) -> TalkOutput :
384+ def transfer_call (self , msg_id : str , args : Dict [str , Any ]) -> TalkOutput :
387385 """
388386 Send a transfer call directive back to Rapida.
389387
@@ -399,15 +397,15 @@ def transfer_call(
399397 for k , v in (args or {}).items ():
400398 _args [str (k )] = string_to_any (str (v ))
401399
402- return self .response (directive = ConversationDirective (
403- id = str (msg_id ),
404- type = ConversationDirective .TRANSFER_CONVERSATION ,
405- args = _args
406- ))
400+ return self .response (
401+ directive = ConversationDirective (
402+ id = str (msg_id ),
403+ type = ConversationDirective .TRANSFER_CONVERSATION ,
404+ args = _args ,
405+ )
406+ )
407407
408- def terminate_call (
409- self , msg_id : str , args : Dict [str , Any ]
410- ) -> TalkOutput :
408+ def terminate_call (self , msg_id : str , args : Dict [str , Any ]) -> TalkOutput :
411409 """
412410 Send a tool call that ends the conversation back to Rapida.
413411
@@ -424,11 +422,12 @@ def terminate_call(
424422 # Set map fields with Any values after construction
425423 for k , v in (args or {}).items ():
426424 _arg [str (k )] = string_to_any (str (v ))
427-
428- return self .response (directive = ConversationDirective (
429- id = str (msg_id ),
430- type = ConversationDirective .END_CONVERSATION ,
431- args = _arg ))
425+
426+ return self .response (
427+ directive = ConversationDirective (
428+ id = str (msg_id ), type = ConversationDirective .END_CONVERSATION , args = _arg
429+ )
430+ )
432431
433432 # ========================================================================
434433 # REQUEST HELPERS - Receive data from Rapida
@@ -486,7 +485,9 @@ def get_assistant_id(self, request: TalkInput) -> Optional[int]:
486485 Returns:
487486 Assistant ID, or None if not an initialization request or assistant is unset
488487 """
489- if request .HasField ("initialization" ) and request .initialization .HasField ("assistant" ):
488+ if request .HasField ("initialization" ) and request .initialization .HasField (
489+ "assistant"
490+ ):
490491 return request .initialization .assistant .assistantId
491492 return None
492493
@@ -504,17 +505,11 @@ def is_message_request(self, request: TalkInput) -> bool:
504505
505506 def is_text_message (self , request : TalkInput ) -> bool :
506507 """Check if request is a text message."""
507- return (
508- request .HasField ("message" )
509- and request .message .HasField ("text" )
510- )
508+ return request .HasField ("message" ) and request .message .HasField ("text" )
511509
512510 def is_audio_message (self , request : TalkInput ) -> bool :
513511 """Check if request is an audio message."""
514- return (
515- request .HasField ("message" )
516- and request .message .HasField ("audio" )
517- )
512+ return request .HasField ("message" ) and request .message .HasField ("audio" )
518513
519514
520515# ============================================================================
0 commit comments