dv-pipecat-ai 0.0.74.dev770__py3-none-any.whl → 0.0.82.dev776__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of dv-pipecat-ai might be problematic. Click here for more details.

Files changed (244) hide show
  1. {dv_pipecat_ai-0.0.74.dev770.dist-info → dv_pipecat_ai-0.0.82.dev776.dist-info}/METADATA +137 -93
  2. dv_pipecat_ai-0.0.82.dev776.dist-info/RECORD +340 -0
  3. pipecat/__init__.py +17 -0
  4. pipecat/adapters/base_llm_adapter.py +36 -1
  5. pipecat/adapters/schemas/direct_function.py +296 -0
  6. pipecat/adapters/schemas/function_schema.py +15 -6
  7. pipecat/adapters/schemas/tools_schema.py +55 -7
  8. pipecat/adapters/services/anthropic_adapter.py +22 -3
  9. pipecat/adapters/services/aws_nova_sonic_adapter.py +23 -3
  10. pipecat/adapters/services/bedrock_adapter.py +22 -3
  11. pipecat/adapters/services/gemini_adapter.py +16 -3
  12. pipecat/adapters/services/open_ai_adapter.py +17 -2
  13. pipecat/adapters/services/open_ai_realtime_adapter.py +23 -3
  14. pipecat/audio/filters/base_audio_filter.py +30 -6
  15. pipecat/audio/filters/koala_filter.py +37 -2
  16. pipecat/audio/filters/krisp_filter.py +59 -6
  17. pipecat/audio/filters/noisereduce_filter.py +37 -0
  18. pipecat/audio/interruptions/base_interruption_strategy.py +25 -5
  19. pipecat/audio/interruptions/min_words_interruption_strategy.py +21 -4
  20. pipecat/audio/mixers/base_audio_mixer.py +30 -7
  21. pipecat/audio/mixers/soundfile_mixer.py +53 -6
  22. pipecat/audio/resamplers/base_audio_resampler.py +17 -9
  23. pipecat/audio/resamplers/resampy_resampler.py +26 -1
  24. pipecat/audio/resamplers/soxr_resampler.py +32 -1
  25. pipecat/audio/resamplers/soxr_stream_resampler.py +101 -0
  26. pipecat/audio/utils.py +194 -1
  27. pipecat/audio/vad/silero.py +60 -3
  28. pipecat/audio/vad/vad_analyzer.py +114 -30
  29. pipecat/clocks/base_clock.py +19 -0
  30. pipecat/clocks/system_clock.py +25 -0
  31. pipecat/extensions/voicemail/__init__.py +0 -0
  32. pipecat/extensions/voicemail/voicemail_detector.py +707 -0
  33. pipecat/frames/frames.py +590 -156
  34. pipecat/metrics/metrics.py +64 -1
  35. pipecat/observers/base_observer.py +58 -19
  36. pipecat/observers/loggers/debug_log_observer.py +56 -64
  37. pipecat/observers/loggers/llm_log_observer.py +8 -1
  38. pipecat/observers/loggers/transcription_log_observer.py +19 -7
  39. pipecat/observers/loggers/user_bot_latency_log_observer.py +32 -5
  40. pipecat/observers/turn_tracking_observer.py +26 -1
  41. pipecat/pipeline/base_pipeline.py +5 -7
  42. pipecat/pipeline/base_task.py +52 -9
  43. pipecat/pipeline/parallel_pipeline.py +121 -177
  44. pipecat/pipeline/pipeline.py +129 -20
  45. pipecat/pipeline/runner.py +50 -1
  46. pipecat/pipeline/sync_parallel_pipeline.py +132 -32
  47. pipecat/pipeline/task.py +263 -280
  48. pipecat/pipeline/task_observer.py +85 -34
  49. pipecat/pipeline/to_be_updated/merge_pipeline.py +32 -2
  50. pipecat/processors/aggregators/dtmf_aggregator.py +29 -22
  51. pipecat/processors/aggregators/gated.py +25 -24
  52. pipecat/processors/aggregators/gated_openai_llm_context.py +22 -2
  53. pipecat/processors/aggregators/llm_response.py +398 -89
  54. pipecat/processors/aggregators/openai_llm_context.py +161 -13
  55. pipecat/processors/aggregators/sentence.py +25 -14
  56. pipecat/processors/aggregators/user_response.py +28 -3
  57. pipecat/processors/aggregators/vision_image_frame.py +24 -14
  58. pipecat/processors/async_generator.py +28 -0
  59. pipecat/processors/audio/audio_buffer_processor.py +78 -37
  60. pipecat/processors/consumer_processor.py +25 -6
  61. pipecat/processors/filters/frame_filter.py +23 -0
  62. pipecat/processors/filters/function_filter.py +30 -0
  63. pipecat/processors/filters/identity_filter.py +17 -2
  64. pipecat/processors/filters/null_filter.py +24 -1
  65. pipecat/processors/filters/stt_mute_filter.py +56 -21
  66. pipecat/processors/filters/wake_check_filter.py +46 -3
  67. pipecat/processors/filters/wake_notifier_filter.py +21 -3
  68. pipecat/processors/frame_processor.py +488 -131
  69. pipecat/processors/frameworks/langchain.py +38 -3
  70. pipecat/processors/frameworks/rtvi.py +719 -34
  71. pipecat/processors/gstreamer/pipeline_source.py +41 -0
  72. pipecat/processors/idle_frame_processor.py +26 -3
  73. pipecat/processors/logger.py +23 -0
  74. pipecat/processors/metrics/frame_processor_metrics.py +77 -4
  75. pipecat/processors/metrics/sentry.py +42 -4
  76. pipecat/processors/producer_processor.py +34 -14
  77. pipecat/processors/text_transformer.py +22 -10
  78. pipecat/processors/transcript_processor.py +48 -29
  79. pipecat/processors/user_idle_processor.py +31 -21
  80. pipecat/runner/__init__.py +1 -0
  81. pipecat/runner/daily.py +132 -0
  82. pipecat/runner/livekit.py +148 -0
  83. pipecat/runner/run.py +543 -0
  84. pipecat/runner/types.py +67 -0
  85. pipecat/runner/utils.py +515 -0
  86. pipecat/serializers/base_serializer.py +42 -0
  87. pipecat/serializers/exotel.py +17 -6
  88. pipecat/serializers/genesys.py +95 -0
  89. pipecat/serializers/livekit.py +33 -0
  90. pipecat/serializers/plivo.py +16 -15
  91. pipecat/serializers/protobuf.py +37 -1
  92. pipecat/serializers/telnyx.py +18 -17
  93. pipecat/serializers/twilio.py +32 -16
  94. pipecat/services/ai_service.py +5 -3
  95. pipecat/services/anthropic/llm.py +113 -43
  96. pipecat/services/assemblyai/models.py +63 -5
  97. pipecat/services/assemblyai/stt.py +64 -11
  98. pipecat/services/asyncai/__init__.py +0 -0
  99. pipecat/services/asyncai/tts.py +501 -0
  100. pipecat/services/aws/llm.py +185 -111
  101. pipecat/services/aws/stt.py +217 -23
  102. pipecat/services/aws/tts.py +118 -52
  103. pipecat/services/aws/utils.py +101 -5
  104. pipecat/services/aws_nova_sonic/aws.py +82 -64
  105. pipecat/services/aws_nova_sonic/context.py +15 -6
  106. pipecat/services/azure/common.py +10 -2
  107. pipecat/services/azure/image.py +32 -0
  108. pipecat/services/azure/llm.py +9 -7
  109. pipecat/services/azure/stt.py +65 -2
  110. pipecat/services/azure/tts.py +154 -23
  111. pipecat/services/cartesia/stt.py +125 -8
  112. pipecat/services/cartesia/tts.py +102 -38
  113. pipecat/services/cerebras/llm.py +15 -23
  114. pipecat/services/deepgram/stt.py +19 -11
  115. pipecat/services/deepgram/tts.py +36 -0
  116. pipecat/services/deepseek/llm.py +14 -23
  117. pipecat/services/elevenlabs/tts.py +330 -64
  118. pipecat/services/fal/image.py +43 -0
  119. pipecat/services/fal/stt.py +48 -10
  120. pipecat/services/fireworks/llm.py +14 -21
  121. pipecat/services/fish/tts.py +109 -9
  122. pipecat/services/gemini_multimodal_live/__init__.py +1 -0
  123. pipecat/services/gemini_multimodal_live/events.py +83 -2
  124. pipecat/services/gemini_multimodal_live/file_api.py +189 -0
  125. pipecat/services/gemini_multimodal_live/gemini.py +218 -21
  126. pipecat/services/gladia/config.py +17 -10
  127. pipecat/services/gladia/stt.py +82 -36
  128. pipecat/services/google/frames.py +40 -0
  129. pipecat/services/google/google.py +2 -0
  130. pipecat/services/google/image.py +39 -2
  131. pipecat/services/google/llm.py +176 -58
  132. pipecat/services/google/llm_openai.py +26 -4
  133. pipecat/services/google/llm_vertex.py +37 -15
  134. pipecat/services/google/rtvi.py +41 -0
  135. pipecat/services/google/stt.py +65 -17
  136. pipecat/services/google/test-google-chirp.py +45 -0
  137. pipecat/services/google/tts.py +390 -19
  138. pipecat/services/grok/llm.py +8 -6
  139. pipecat/services/groq/llm.py +8 -6
  140. pipecat/services/groq/stt.py +13 -9
  141. pipecat/services/groq/tts.py +40 -0
  142. pipecat/services/hamsa/__init__.py +9 -0
  143. pipecat/services/hamsa/stt.py +241 -0
  144. pipecat/services/heygen/__init__.py +5 -0
  145. pipecat/services/heygen/api.py +281 -0
  146. pipecat/services/heygen/client.py +620 -0
  147. pipecat/services/heygen/video.py +338 -0
  148. pipecat/services/image_service.py +5 -3
  149. pipecat/services/inworld/__init__.py +1 -0
  150. pipecat/services/inworld/tts.py +592 -0
  151. pipecat/services/llm_service.py +127 -45
  152. pipecat/services/lmnt/tts.py +80 -7
  153. pipecat/services/mcp_service.py +85 -44
  154. pipecat/services/mem0/memory.py +42 -13
  155. pipecat/services/minimax/tts.py +74 -15
  156. pipecat/services/mistral/__init__.py +0 -0
  157. pipecat/services/mistral/llm.py +185 -0
  158. pipecat/services/moondream/vision.py +55 -10
  159. pipecat/services/neuphonic/tts.py +275 -48
  160. pipecat/services/nim/llm.py +8 -6
  161. pipecat/services/ollama/llm.py +27 -7
  162. pipecat/services/openai/base_llm.py +54 -16
  163. pipecat/services/openai/image.py +30 -0
  164. pipecat/services/openai/llm.py +7 -5
  165. pipecat/services/openai/stt.py +13 -9
  166. pipecat/services/openai/tts.py +42 -10
  167. pipecat/services/openai_realtime_beta/azure.py +11 -9
  168. pipecat/services/openai_realtime_beta/context.py +7 -5
  169. pipecat/services/openai_realtime_beta/events.py +10 -7
  170. pipecat/services/openai_realtime_beta/openai.py +37 -18
  171. pipecat/services/openpipe/llm.py +30 -24
  172. pipecat/services/openrouter/llm.py +9 -7
  173. pipecat/services/perplexity/llm.py +15 -19
  174. pipecat/services/piper/tts.py +26 -12
  175. pipecat/services/playht/tts.py +227 -65
  176. pipecat/services/qwen/llm.py +8 -6
  177. pipecat/services/rime/tts.py +128 -17
  178. pipecat/services/riva/stt.py +160 -22
  179. pipecat/services/riva/tts.py +67 -2
  180. pipecat/services/sambanova/llm.py +19 -17
  181. pipecat/services/sambanova/stt.py +14 -8
  182. pipecat/services/sarvam/tts.py +60 -13
  183. pipecat/services/simli/video.py +82 -21
  184. pipecat/services/soniox/__init__.py +0 -0
  185. pipecat/services/soniox/stt.py +398 -0
  186. pipecat/services/speechmatics/stt.py +29 -17
  187. pipecat/services/stt_service.py +47 -11
  188. pipecat/services/tavus/video.py +94 -25
  189. pipecat/services/together/llm.py +8 -6
  190. pipecat/services/tts_service.py +77 -53
  191. pipecat/services/ultravox/stt.py +46 -43
  192. pipecat/services/vision_service.py +5 -3
  193. pipecat/services/websocket_service.py +12 -11
  194. pipecat/services/whisper/base_stt.py +58 -12
  195. pipecat/services/whisper/stt.py +69 -58
  196. pipecat/services/xtts/tts.py +59 -2
  197. pipecat/sync/base_notifier.py +19 -0
  198. pipecat/sync/event_notifier.py +24 -0
  199. pipecat/tests/utils.py +73 -5
  200. pipecat/transcriptions/language.py +24 -0
  201. pipecat/transports/base_input.py +112 -8
  202. pipecat/transports/base_output.py +235 -13
  203. pipecat/transports/base_transport.py +119 -0
  204. pipecat/transports/local/audio.py +76 -0
  205. pipecat/transports/local/tk.py +84 -0
  206. pipecat/transports/network/fastapi_websocket.py +174 -15
  207. pipecat/transports/network/small_webrtc.py +383 -39
  208. pipecat/transports/network/webrtc_connection.py +214 -8
  209. pipecat/transports/network/websocket_client.py +171 -1
  210. pipecat/transports/network/websocket_server.py +147 -9
  211. pipecat/transports/services/daily.py +792 -70
  212. pipecat/transports/services/helpers/daily_rest.py +122 -129
  213. pipecat/transports/services/livekit.py +339 -4
  214. pipecat/transports/services/tavus.py +273 -38
  215. pipecat/utils/asyncio/task_manager.py +92 -186
  216. pipecat/utils/base_object.py +83 -1
  217. pipecat/utils/network.py +2 -0
  218. pipecat/utils/string.py +114 -58
  219. pipecat/utils/text/base_text_aggregator.py +44 -13
  220. pipecat/utils/text/base_text_filter.py +46 -0
  221. pipecat/utils/text/markdown_text_filter.py +70 -14
  222. pipecat/utils/text/pattern_pair_aggregator.py +18 -14
  223. pipecat/utils/text/simple_text_aggregator.py +43 -2
  224. pipecat/utils/text/skip_tags_aggregator.py +21 -13
  225. pipecat/utils/time.py +36 -0
  226. pipecat/utils/tracing/class_decorators.py +32 -7
  227. pipecat/utils/tracing/conversation_context_provider.py +12 -2
  228. pipecat/utils/tracing/service_attributes.py +80 -64
  229. pipecat/utils/tracing/service_decorators.py +48 -21
  230. pipecat/utils/tracing/setup.py +13 -7
  231. pipecat/utils/tracing/turn_context_provider.py +12 -2
  232. pipecat/utils/tracing/turn_trace_observer.py +27 -0
  233. pipecat/utils/utils.py +14 -14
  234. dv_pipecat_ai-0.0.74.dev770.dist-info/RECORD +0 -319
  235. pipecat/examples/daily_runner.py +0 -64
  236. pipecat/examples/run.py +0 -265
  237. pipecat/utils/asyncio/watchdog_async_iterator.py +0 -72
  238. pipecat/utils/asyncio/watchdog_event.py +0 -42
  239. pipecat/utils/asyncio/watchdog_priority_queue.py +0 -48
  240. pipecat/utils/asyncio/watchdog_queue.py +0 -48
  241. {dv_pipecat_ai-0.0.74.dev770.dist-info → dv_pipecat_ai-0.0.82.dev776.dist-info}/WHEEL +0 -0
  242. {dv_pipecat_ai-0.0.74.dev770.dist-info → dv_pipecat_ai-0.0.82.dev776.dist-info}/licenses/LICENSE +0 -0
  243. {dv_pipecat_ai-0.0.74.dev770.dist-info → dv_pipecat_ai-0.0.82.dev776.dist-info}/top_level.txt +0 -0
  244. /pipecat/{examples → extensions}/__init__.py +0 -0
@@ -41,9 +41,15 @@ T = TypeVar("T")
41
41
  R = TypeVar("R")
42
42
 
43
43
 
44
- # Internal helper functions
45
44
  def _noop_decorator(func):
46
- """No-op fallback decorator when tracing is unavailable."""
45
+ """No-op fallback decorator when tracing is unavailable.
46
+
47
+ Args:
48
+ func: The function to pass through unchanged.
49
+
50
+ Returns:
51
+ The original function unchanged.
52
+ """
47
53
  return func
48
54
 
49
55
 
@@ -53,10 +59,10 @@ def _get_parent_service_context(self):
53
59
  This looks for the service span that was created when the service was initialized.
54
60
 
55
61
  Args:
56
- self: The service instance
62
+ self: The service instance.
57
63
 
58
64
  Returns:
59
- Context or None: The parent service context, or None if unavailable
65
+ The parent service context, or None if unavailable.
60
66
  """
61
67
  if not is_tracing_available():
62
68
  return None
@@ -73,8 +79,8 @@ def _add_token_usage_to_span(span, token_usage):
73
79
  """Add token usage metrics to a span (internal use only).
74
80
 
75
81
  Args:
76
- span: The span to add token metrics to
77
- token_usage: Dictionary or object containing token usage information
82
+ span: The span to add token metrics to.
83
+ token_usage: Dictionary or object containing token usage information.
78
84
  """
79
85
  if not is_tracing_available() or not token_usage:
80
86
  return
@@ -93,9 +99,10 @@ def _add_token_usage_to_span(span, token_usage):
93
99
 
94
100
 
95
101
  def traced_tts(func: Optional[Callable] = None, *, name: Optional[str] = None) -> Callable:
96
- """Traces TTS service methods with TTS-specific attributes.
102
+ """Trace TTS service methods with TTS-specific attributes.
97
103
 
98
104
  Automatically captures and records:
105
+
99
106
  - Service name and model information
100
107
  - Voice ID and settings
101
108
  - Character count and text content
@@ -118,8 +125,17 @@ def traced_tts(func: Optional[Callable] = None, *, name: Optional[str] = None) -
118
125
 
119
126
  @contextlib.asynccontextmanager
120
127
  async def tracing_context(self, text):
121
- """Async context manager for TTS tracing."""
122
- if not is_tracing_available():
128
+ """Async context manager for TTS tracing.
129
+
130
+ Args:
131
+ self: The TTS service instance.
132
+ text: The text being synthesized.
133
+
134
+ Yields:
135
+ The active span for the TTS operation.
136
+ """
137
+ # Check if tracing is enabled for this service instance
138
+ if not getattr(self, "_tracing_enabled", False):
123
139
  yield None
124
140
  return
125
141
 
@@ -163,7 +179,8 @@ def traced_tts(func: Optional[Callable] = None, *, name: Optional[str] = None) -
163
179
  @functools.wraps(f)
164
180
  async def gen_wrapper(self, text, *args, **kwargs):
165
181
  try:
166
- if not is_tracing_available():
182
+ # Check if tracing is enabled for this service instance
183
+ if not getattr(self, "_tracing_enabled", False):
167
184
  async for item in f(self, text, *args, **kwargs):
168
185
  yield item
169
186
  return
@@ -183,7 +200,8 @@ def traced_tts(func: Optional[Callable] = None, *, name: Optional[str] = None) -
183
200
  @functools.wraps(f)
184
201
  async def wrapper(self, text, *args, **kwargs):
185
202
  try:
186
- if not is_tracing_available():
203
+ # Check if tracing is enabled for this service instance
204
+ if not getattr(self, "_tracing_enabled", False):
187
205
  return await f(self, text, *args, **kwargs)
188
206
 
189
207
  async with tracing_context(self, text):
@@ -201,9 +219,10 @@ def traced_tts(func: Optional[Callable] = None, *, name: Optional[str] = None) -
201
219
 
202
220
 
203
221
  def traced_stt(func: Optional[Callable] = None, *, name: Optional[str] = None) -> Callable:
204
- """Traces STT service methods with transcription attributes.
222
+ """Trace STT service methods with transcription attributes.
205
223
 
206
224
  Automatically captures and records:
225
+
207
226
  - Service name and model information
208
227
  - Transcription text and final status
209
228
  - Language information
@@ -223,7 +242,8 @@ def traced_stt(func: Optional[Callable] = None, *, name: Optional[str] = None) -
223
242
  @functools.wraps(f)
224
243
  async def wrapper(self, transcript, is_final, language=None):
225
244
  try:
226
- if not is_tracing_available():
245
+ # Check if tracing is enabled for this service instance
246
+ if not getattr(self, "_tracing_enabled", False):
227
247
  return await f(self, transcript, is_final, language)
228
248
 
229
249
  service_class_name = self.__class__.__name__
@@ -254,6 +274,7 @@ def traced_stt(func: Optional[Callable] = None, *, name: Optional[str] = None) -
254
274
  transcript=transcript,
255
275
  is_final=is_final,
256
276
  language=str(language) if language else None,
277
+ user_id=getattr(self, "_user_id", None),
257
278
  vad_enabled=getattr(self, "vad_enabled", False),
258
279
  settings=settings,
259
280
  ttfb=ttfb,
@@ -278,9 +299,10 @@ def traced_stt(func: Optional[Callable] = None, *, name: Optional[str] = None) -
278
299
 
279
300
 
280
301
  def traced_llm(func: Optional[Callable] = None, *, name: Optional[str] = None) -> Callable:
281
- """Traces LLM service methods with LLM-specific attributes.
302
+ """Trace LLM service methods with LLM-specific attributes.
282
303
 
283
304
  Automatically captures and records:
305
+
284
306
  - Service name and model information
285
307
  - Context content and messages
286
308
  - Tool configurations
@@ -302,7 +324,8 @@ def traced_llm(func: Optional[Callable] = None, *, name: Optional[str] = None) -
302
324
  @functools.wraps(f)
303
325
  async def wrapper(self, context, *args, **kwargs):
304
326
  try:
305
- if not is_tracing_available():
327
+ # Check if tracing is enabled for this service instance
328
+ if not getattr(self, "_tracing_enabled", False):
306
329
  return await f(self, context, *args, **kwargs)
307
330
 
308
331
  service_class_name = self.__class__.__name__
@@ -482,16 +505,17 @@ def traced_llm(func: Optional[Callable] = None, *, name: Optional[str] = None) -
482
505
 
483
506
 
484
507
  def traced_gemini_live(operation: str) -> Callable:
485
- """Traces Gemini Live service methods with operation-specific attributes.
508
+ """Trace Gemini Live service methods with operation-specific attributes.
486
509
 
487
510
  This decorator automatically captures relevant information based on the operation type:
511
+
488
512
  - llm_setup: Configuration, tools definitions, and system instructions
489
513
  - llm_tool_call: Function call information
490
514
  - llm_tool_result: Function execution results
491
515
  - llm_response: Complete LLM response with usage and output
492
516
 
493
517
  Args:
494
- operation: The operation name (matches the event type being handled)
518
+ operation: The operation name (matches the event type being handled).
495
519
 
496
520
  Returns:
497
521
  Wrapped method with Gemini Live specific tracing.
@@ -503,7 +527,8 @@ def traced_gemini_live(operation: str) -> Callable:
503
527
  @functools.wraps(func)
504
528
  async def wrapper(self, *args, **kwargs):
505
529
  try:
506
- if not is_tracing_available():
530
+ # Check if tracing is enabled for this service instance
531
+ if not getattr(self, "_tracing_enabled", False):
507
532
  return await func(self, *args, **kwargs)
508
533
 
509
534
  service_class_name = self.__class__.__name__
@@ -786,15 +811,16 @@ def traced_gemini_live(operation: str) -> Callable:
786
811
 
787
812
 
788
813
  def traced_openai_realtime(operation: str) -> Callable:
789
- """Traces OpenAI Realtime service methods with operation-specific attributes.
814
+ """Trace OpenAI Realtime service methods with operation-specific attributes.
790
815
 
791
816
  This decorator automatically captures relevant information based on the operation type:
817
+
792
818
  - llm_setup: Session configuration and tools
793
819
  - llm_request: Context and input messages
794
820
  - llm_response: Usage metadata, output, and function calls
795
821
 
796
822
  Args:
797
- operation: The operation name (matches the event type being handled)
823
+ operation: The operation name (matches the event type being handled).
798
824
 
799
825
  Returns:
800
826
  Wrapped method with OpenAI Realtime specific tracing.
@@ -806,7 +832,8 @@ def traced_openai_realtime(operation: str) -> Callable:
806
832
  @functools.wraps(func)
807
833
  async def wrapper(self, *args, **kwargs):
808
834
  try:
809
- if not is_tracing_available():
835
+ # Check if tracing is enabled for this service instance
836
+ if not getattr(self, "_tracing_enabled", False):
810
837
  return await func(self, *args, **kwargs)
811
838
 
812
839
  service_class_name = self.__class__.__name__
@@ -4,7 +4,12 @@
4
4
  # SPDX-License-Identifier: BSD 2-Clause License
5
5
  #
6
6
 
7
- """Core OpenTelemetry tracing utilities and setup for Pipecat."""
7
+ """Core OpenTelemetry tracing utilities and setup for Pipecat.
8
+
9
+ This module provides functions to check availability and configure OpenTelemetry
10
+ tracing for Pipecat applications. It handles the optional nature of OpenTelemetry
11
+ dependencies and provides a safe setup process.
12
+ """
8
13
 
9
14
  import os
10
15
 
@@ -21,10 +26,10 @@ except ImportError:
21
26
 
22
27
 
23
28
  def is_tracing_available() -> bool:
24
- """Returns True if OpenTelemetry tracing is available and configured.
29
+ """Check if OpenTelemetry tracing is available and configured.
25
30
 
26
31
  Returns:
27
- bool: True if tracing is available, False otherwise.
32
+ True if tracing is available, False otherwise.
28
33
  """
29
34
  return OPENTELEMETRY_AVAILABLE
30
35
 
@@ -37,15 +42,16 @@ def setup_tracing(
37
42
  """Set up OpenTelemetry tracing with a user-provided exporter.
38
43
 
39
44
  Args:
40
- service_name: The name of the service for traces
45
+ service_name: The name of the service for traces.
41
46
  exporter: A pre-configured OpenTelemetry span exporter instance.
42
47
  If None, only console export will be available if enabled.
43
- console_export: Whether to also export traces to console (useful for debugging)
48
+ console_export: Whether to also export traces to console (useful for debugging).
44
49
 
45
50
  Returns:
46
- bool: True if setup was successful, False otherwise
51
+ True if setup was successful, False otherwise.
52
+
53
+ Example::
47
54
 
48
- Example:
49
55
  # With OTLP exporter
50
56
  from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
51
57
 
@@ -4,6 +4,13 @@
4
4
  # SPDX-License-Identifier: BSD 2-Clause License
5
5
  #
6
6
 
7
+ """Turn context provider for OpenTelemetry tracing in Pipecat.
8
+
9
+ This module provides a singleton context provider that manages the current
10
+ turn's tracing context, allowing services to create child spans that are
11
+ properly associated with the conversation turn.
12
+ """
13
+
7
14
  from typing import TYPE_CHECKING, Optional
8
15
 
9
16
  # Import types for type checking only
@@ -30,7 +37,11 @@ class TurnContextProvider:
30
37
 
31
38
  @classmethod
32
39
  def get_instance(cls):
33
- """Get the singleton instance."""
40
+ """Get the singleton instance.
41
+
42
+ Returns:
43
+ The singleton TurnContextProvider instance.
44
+ """
34
45
  if cls._instance is None:
35
46
  cls._instance = TurnContextProvider()
36
47
  return cls._instance
@@ -60,7 +71,6 @@ class TurnContextProvider:
60
71
  return self._current_turn_context
61
72
 
62
73
 
63
- # Create a simple helper function to get the current turn context
64
74
  def get_current_turn_context() -> Optional["Context"]:
65
75
  """Get the OpenTelemetry context for the current turn.
66
76
 
@@ -4,6 +4,13 @@
4
4
  # SPDX-License-Identifier: BSD 2-Clause License
5
5
  #
6
6
 
7
+ """Turn trace observer for OpenTelemetry tracing in Pipecat.
8
+
9
+ This module provides an observer that creates trace spans for each conversation
10
+ turn, integrating with the turn tracking system to provide hierarchical tracing
11
+ of conversation flows.
12
+ """
13
+
7
14
  from typing import TYPE_CHECKING, Dict, Optional
8
15
 
9
16
  from loguru import logger
@@ -41,6 +48,14 @@ class TurnTraceObserver(BaseObserver):
41
48
  additional_span_attributes: Optional[dict] = None,
42
49
  **kwargs,
43
50
  ):
51
+ """Initialize the turn trace observer.
52
+
53
+ Args:
54
+ turn_tracker: The turn tracking observer to monitor.
55
+ conversation_id: Optional conversation ID for grouping turns.
56
+ additional_span_attributes: Additional attributes to add to spans.
57
+ **kwargs: Additional arguments passed to parent class.
58
+ """
44
59
  super().__init__(**kwargs)
45
60
  self._turn_tracker = turn_tracker
46
61
  self._current_span: Optional["Span"] = None
@@ -68,6 +83,9 @@ class TurnTraceObserver(BaseObserver):
68
83
 
69
84
  This observer doesn't need to process individual frames as it
70
85
  relies on turn start/end events from the turn tracker.
86
+
87
+ Args:
88
+ data: The frame push event data.
71
89
  """
72
90
  pass
73
91
 
@@ -198,6 +216,9 @@ class TurnTraceObserver(BaseObserver):
198
216
  """Get the span context for the current turn.
199
217
 
200
218
  This can be used by services to create child spans.
219
+
220
+ Returns:
221
+ The current turn's span context or None if not available.
201
222
  """
202
223
  if not is_tracing_available() or not self._current_span:
203
224
  return None
@@ -208,6 +229,12 @@ class TurnTraceObserver(BaseObserver):
208
229
  """Get the span context for a specific turn.
209
230
 
210
231
  This can be used by services to create child spans.
232
+
233
+ Args:
234
+ turn_number: The turn number to get context for.
235
+
236
+ Returns:
237
+ The specified turn's span context or None if not available.
211
238
  """
212
239
  if not is_tracing_available():
213
240
  return None
pipecat/utils/utils.py CHANGED
@@ -4,6 +4,12 @@
4
4
  # SPDX-License-Identifier: BSD 2-Clause License
5
5
  #
6
6
 
7
+ """Utility functions for object identification and counting.
8
+
9
+ This module provides thread-safe utilities for generating unique identifiers
10
+ and maintaining per-class instance counts across the Pipecat framework.
11
+ """
12
+
7
13
  import collections
8
14
  import itertools
9
15
  import threading
@@ -17,27 +23,21 @@ _ID_LOCK = threading.Lock()
17
23
  def obj_id() -> int:
18
24
  """Generate a unique id for an object.
19
25
 
20
- >>> obj_id()
21
- 0
22
- >>> obj_id()
23
- 1
24
- >>> obj_id()
25
- 2
26
+ Returns:
27
+ A unique integer identifier that increments globally across all objects.
26
28
  """
27
29
  with _ID_LOCK:
28
30
  return next(_ID)
29
31
 
30
32
 
31
33
  def obj_count(obj) -> int:
32
- """Generate a unique id for an object.
34
+ """Generate a unique count for an object based on its class.
33
35
 
34
- >>> obj_count(object())
35
- 0
36
- >>> obj_count(object())
37
- 1
38
- >>> new_type = type('NewType', (object,), {})
39
- >>> obj_count(new_type())
40
- 0
36
+ Args:
37
+ obj: The object instance to count.
38
+
39
+ Returns:
40
+ A unique integer count that increments per class type.
41
41
  """
42
42
  with _COUNTS_LOCK:
43
43
  return next(_COUNTS[obj.__class__.__name__])