Fix pyright errors in service_decorators.py
This commit is contained in:
@@ -360,7 +360,7 @@ def traced_tts(func: Callable | None = None, *, name: str | None = None) -> Call
|
|||||||
await original_setup(self, setup)
|
await original_setup(self, setup)
|
||||||
install_audio_context_patches(self)
|
install_audio_context_patches(self)
|
||||||
|
|
||||||
patched_setup.__tts_tracing_setup_wrapped__ = True
|
setattr(patched_setup, "__tts_tracing_setup_wrapped__", True)
|
||||||
owner.setup = patched_setup
|
owner.setup = patched_setup
|
||||||
|
|
||||||
def attach_run_tts_attributes(service, text, args, kwargs):
|
def attach_run_tts_attributes(service, text, args, kwargs):
|
||||||
@@ -418,7 +418,11 @@ def traced_tts(func: Callable | None = None, *, name: str | None = None) -> Call
|
|||||||
return _TracedTTSDescriptor()
|
return _TracedTTSDescriptor()
|
||||||
|
|
||||||
if func is not None:
|
if func is not None:
|
||||||
return decorator(func)
|
# ``decorator(func)`` returns a descriptor placeholder that
|
||||||
|
# Python replaces with the real wrapped function once
|
||||||
|
# ``__set_name__`` runs at class definition time. Pyright sees
|
||||||
|
# only the descriptor instance, hence the ignore.
|
||||||
|
return decorator(func) # type: ignore[return-value]
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
@@ -493,10 +497,12 @@ def traced_stt(func: Callable | None = None, *, name: str | None = None) -> Call
|
|||||||
"""Open the STT span, anchored at ``segment_start_time`` if set."""
|
"""Open the STT span, anchored at ``segment_start_time`` if set."""
|
||||||
parent = _get_turn_context(service) or _get_parent_service_context(service)
|
parent = _get_turn_context(service) or _get_parent_service_context(service)
|
||||||
tracer = trace.get_tracer("pipecat")
|
tracer = trace.get_tracer("pipecat")
|
||||||
kwargs = {"context": parent}
|
start_time_ns = (
|
||||||
if state["segment_start_time"] is not None:
|
int(state["segment_start_time"] * 1e9)
|
||||||
kwargs["start_time"] = int(state["segment_start_time"] * 1e9)
|
if state["segment_start_time"] is not None
|
||||||
span = tracer.start_span("stt", **kwargs)
|
else None
|
||||||
|
)
|
||||||
|
span = tracer.start_span("stt", context=parent, start_time=start_time_ns)
|
||||||
try:
|
try:
|
||||||
settings = getattr(service, "_settings", None)
|
settings = getattr(service, "_settings", None)
|
||||||
add_stt_span_attributes(
|
add_stt_span_attributes(
|
||||||
@@ -637,7 +643,7 @@ def traced_stt(func: Callable | None = None, *, name: str | None = None) -> Call
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.warning(f"Error in STT post-push tracing: {e}")
|
logging.warning(f"Error in STT post-push tracing: {e}")
|
||||||
|
|
||||||
patched_push_frame.__stt_tracing_push_frame_wrapped__ = True
|
setattr(patched_push_frame, "__stt_tracing_push_frame_wrapped__", True)
|
||||||
owner.push_frame = patched_push_frame
|
owner.push_frame = patched_push_frame
|
||||||
|
|
||||||
def patch_stop_ttfb_metrics(owner):
|
def patch_stop_ttfb_metrics(owner):
|
||||||
@@ -681,7 +687,7 @@ def traced_stt(func: Callable | None = None, *, name: str | None = None) -> Call
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.warning(f"Error in STT stop_ttfb_metrics tracing: {e}")
|
logging.warning(f"Error in STT stop_ttfb_metrics tracing: {e}")
|
||||||
|
|
||||||
patched_stop.__stt_tracing_stop_ttfb_wrapped__ = True
|
setattr(patched_stop, "__stt_tracing_stop_ttfb_wrapped__", True)
|
||||||
owner.stop_ttfb_metrics = patched_stop
|
owner.stop_ttfb_metrics = patched_stop
|
||||||
|
|
||||||
class _TracedSTTDescriptor:
|
class _TracedSTTDescriptor:
|
||||||
@@ -704,7 +710,11 @@ def traced_stt(func: Callable | None = None, *, name: str | None = None) -> Call
|
|||||||
return _TracedSTTDescriptor()
|
return _TracedSTTDescriptor()
|
||||||
|
|
||||||
if func is not None:
|
if func is not None:
|
||||||
return decorator(func)
|
# ``decorator(func)`` returns a descriptor placeholder that
|
||||||
|
# Python replaces with the real wrapped function once
|
||||||
|
# ``__set_name__`` runs at class definition time. Pyright sees
|
||||||
|
# only the descriptor instance, hence the ignore.
|
||||||
|
return decorator(func) # type: ignore[return-value]
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user