dv-pipecat-ai 0.0.82.dev776__py3-none-any.whl → 0.0.82.dev807__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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dv-pipecat-ai
3
- Version: 0.0.82.dev776
3
+ Version: 0.0.82.dev807
4
4
  Summary: An open source framework for voice (and multimodal) assistants
5
5
  License-Expression: BSD-2-Clause
6
6
  Project-URL: Source, https://github.com/pipecat-ai/pipecat
@@ -1,4 +1,4 @@
1
- dv_pipecat_ai-0.0.82.dev776.dist-info/licenses/LICENSE,sha256=DWY2QGf2eMCFhuu2ChairtT6CB7BEFffNVhXWc4Od08,1301
1
+ dv_pipecat_ai-0.0.82.dev807.dist-info/licenses/LICENSE,sha256=DWY2QGf2eMCFhuu2ChairtT6CB7BEFffNVhXWc4Od08,1301
2
2
  pipecat/__init__.py,sha256=j0Xm6adxHhd7D06dIyyPV_GlBYLlBnTAERVvD_jAARQ,861
3
3
  pipecat/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  pipecat/adapters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -46,7 +46,7 @@ pipecat/audio/vad/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
46
46
  pipecat/audio/vad/silero.py,sha256=r9UL8aEe-QoRMNDGWLUlgUYew93-QFojE9sIqLO0VYE,7792
47
47
  pipecat/audio/vad/vad_analyzer.py,sha256=XkZLEe4z7Ja0lGoYZst1HNYqt5qOwG-vjsk_w8chiNA,7430
48
48
  pipecat/audio/vad/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
- pipecat/audio/vad/data/silero_vad.onnx,sha256=JiOilT9v89LB5hdAxs23FoEzR5smff7xFKSjzFvdeI8,2327524
49
+ pipecat/audio/vad/data/silero_vad.onnx,sha256=WX0ws-wHZgjQWUd7sUz-_9-VG_XK43DTj2XTO7_oIAQ,2327524
50
50
  pipecat/clocks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
51
51
  pipecat/clocks/base_clock.py,sha256=PuTmCtPKz5VG0VxhN5cyhbvduEBnfNPgA6GLAu1eSns,929
52
52
  pipecat/clocks/system_clock.py,sha256=ht6TdDAn0JVXEmhLdt5igcHMQOkKO4YHNuOjuKcxkUU,1315
@@ -279,6 +279,8 @@ pipecat/services/together/__init__.py,sha256=hNMycJDDf3CLiL9WA9fwvMdYphyDWLv0Oab
279
279
  pipecat/services/together/llm.py,sha256=VSayO-U6g9Ld0xK9CXRQPUsd5gWJKtiA8qDAyXgsSkE,1958
280
280
  pipecat/services/ultravox/__init__.py,sha256=EoHCSXI2o0DFQslELgkhAGZtxDj63gZi-9ZEhXljaKE,259
281
281
  pipecat/services/ultravox/stt.py,sha256=uCQm_-LbycXdXRV6IE1a6Mymis6tyww7V8PnPzAQtx8,16586
282
+ pipecat/services/vistaar/__init__.py,sha256=UFfSWFN5rbzl6NN-E_OH_MFaSYodZWNlenAU0wk-rAI,110
283
+ pipecat/services/vistaar/llm.py,sha256=O-sznJDPivnhY_XUsr5xYcwkCqXpMv_zOuZ1rJBfn9Y,14631
282
284
  pipecat/services/whisper/__init__.py,sha256=smADmw0Fv98k7cGRuHTEcljKTO2WdZqLpJd0qsTCwH8,281
283
285
  pipecat/services/whisper/base_stt.py,sha256=VhslESPnYIeVbmnQTzmlZPV35TH49duxYTvJe0epNnE,7850
284
286
  pipecat/services/whisper/stt.py,sha256=9Qd56vWMzg3LtHikQnfgyMtl4odE6BCHDbpAn3HSWjw,17480
@@ -334,7 +336,7 @@ pipecat/utils/tracing/service_decorators.py,sha256=HwDCqLGijhYD3F8nxDuQmEw-YkRw0
334
336
  pipecat/utils/tracing/setup.py,sha256=7TEgPNpq6M8lww8OQvf0P9FzYc5A30xICGklVA-fua0,2892
335
337
  pipecat/utils/tracing/turn_context_provider.py,sha256=ikon3plFOx0XbMrH6DdeHttNpb-U0gzMZIm3bWLc9eI,2485
336
338
  pipecat/utils/tracing/turn_trace_observer.py,sha256=dma16SBJpYSOE58YDWy89QzHyQFc_9gQZszKeWixuwc,9725
337
- dv_pipecat_ai-0.0.82.dev776.dist-info/METADATA,sha256=VJAth6kEBgJT2SJHJ5KnMorgpHZvF6ZMg6Uqc65CL-Q,32457
338
- dv_pipecat_ai-0.0.82.dev776.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
339
- dv_pipecat_ai-0.0.82.dev776.dist-info/top_level.txt,sha256=kQzG20CxGf-nSsHmtXHx3hY2-8zHA3jYg8jk0TajqXc,8
340
- dv_pipecat_ai-0.0.82.dev776.dist-info/RECORD,,
339
+ dv_pipecat_ai-0.0.82.dev807.dist-info/METADATA,sha256=KiRlQndV2W1crKYJlr_ksFAeOJOee9sac40jX_hbyHg,32457
340
+ dv_pipecat_ai-0.0.82.dev807.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
341
+ dv_pipecat_ai-0.0.82.dev807.dist-info/top_level.txt,sha256=kQzG20CxGf-nSsHmtXHx3hY2-8zHA3jYg8jk0TajqXc,8
342
+ dv_pipecat_ai-0.0.82.dev807.dist-info/RECORD,,
Binary file
@@ -0,0 +1,5 @@
1
+ """Vistaar AI service implementations."""
2
+
3
+ from .llm import VistaarLLMService
4
+
5
+ __all__ = ["VistaarLLMService"]
@@ -0,0 +1,377 @@
1
+ """Vistaar LLM Service implementation."""
2
+
3
+ import asyncio
4
+ import json
5
+ import time
6
+ import uuid
7
+ from dataclasses import dataclass
8
+ from typing import Any, AsyncGenerator, Dict, Optional
9
+ from urllib.parse import urlencode
10
+
11
+ import httpx
12
+ from loguru import logger
13
+ from pydantic import BaseModel, Field
14
+
15
+ from pipecat.frames.frames import (
16
+ Frame,
17
+ LLMFullResponseEndFrame,
18
+ LLMFullResponseStartFrame,
19
+ LLMMessagesFrame,
20
+ LLMTextFrame,
21
+ LLMUpdateSettingsFrame,
22
+ StartInterruptionFrame,
23
+ StopInterruptionFrame,
24
+ )
25
+ from pipecat.processors.aggregators.llm_response import (
26
+ LLMAssistantAggregatorParams,
27
+ LLMUserAggregatorParams,
28
+ )
29
+ from pipecat.processors.aggregators.openai_llm_context import (
30
+ OpenAILLMContext,
31
+ OpenAILLMContextFrame,
32
+ )
33
+ from pipecat.services.openai.llm import (
34
+ OpenAIAssistantContextAggregator,
35
+ OpenAIContextAggregatorPair,
36
+ OpenAIUserContextAggregator,
37
+ )
38
+ from pipecat.processors.frame_processor import FrameDirection
39
+ from pipecat.services.llm_service import LLMService
40
+
41
+
42
+ class VistaarLLMService(LLMService):
43
+ """A service for interacting with Vistaar's voice API using Server-Sent Events.
44
+
45
+ This service handles text generation through Vistaar's SSE endpoint which
46
+ streams responses in real-time. Vistaar maintains all conversation context
47
+ server-side via session_id, so we only send the latest user message.
48
+ """
49
+
50
+ class InputParams(BaseModel):
51
+ """Input parameters for Vistaar model configuration.
52
+
53
+ Parameters:
54
+ source_lang: Source language code (e.g., 'mr' for Marathi, 'hi' for Hindi).
55
+ target_lang: Target language code for responses.
56
+ session_id: Session ID for maintaining conversation context.
57
+ extra: Additional model-specific parameters.
58
+ """
59
+
60
+ source_lang: Optional[str] = Field(default="mr")
61
+ target_lang: Optional[str] = Field(default="mr")
62
+ session_id: Optional[str] = Field(default=None)
63
+ extra: Optional[Dict[str, Any]] = Field(default_factory=dict)
64
+
65
+ def __init__(
66
+ self,
67
+ *,
68
+ base_url: str = "https://vistaar.kenpath.ai/api",
69
+ params: Optional[InputParams] = None,
70
+ timeout: float = 30.0,
71
+ **kwargs,
72
+ ):
73
+ """Initialize Vistaar LLM service.
74
+
75
+ Args:
76
+ base_url: The base URL for Vistaar API. Defaults to "https://vistaar.kenpath.ai/api".
77
+ params: Input parameters for model configuration and behavior.
78
+ timeout: Request timeout in seconds. Defaults to 30.0 seconds.
79
+ **kwargs: Additional arguments passed to the parent LLMService.
80
+ """
81
+ super().__init__(**kwargs)
82
+
83
+ params = params or VistaarLLMService.InputParams()
84
+
85
+ self._base_url = base_url.rstrip("/")
86
+ self._source_lang = params.source_lang
87
+ self._target_lang = params.target_lang
88
+ self._session_id = params.session_id or str(uuid.uuid4())
89
+ self._extra = params.extra if isinstance(params.extra, dict) else {}
90
+ self._timeout = timeout
91
+
92
+ # Create an async HTTP client
93
+ self._client = httpx.AsyncClient(timeout=httpx.Timeout(self._timeout))
94
+
95
+ # Interruption handling state
96
+ self._current_response = None # Track current HTTP response stream
97
+ self._is_interrupted = False # Track if current generation was interrupted
98
+ self._partial_response = [] # Track what was actually sent before interruption
99
+
100
+ logger.info(
101
+ f"Vistaar LLM initialized - Base URL: {self._base_url}, Session ID: {self._session_id}, Source Lang: {self._source_lang}, Target Lang: {self._target_lang}, Timeout: {self._timeout}s"
102
+ )
103
+
104
+ async def _extract_messages_to_query(self, context: OpenAILLMContext) -> str:
105
+ """Extract only the last user message from context.
106
+
107
+ Since Vistaar maintains context server-side via session_id,
108
+ we only need to send the most recent user message.
109
+
110
+ As a fallback for context synchronization, we can optionally include
111
+ information about interrupted responses.
112
+
113
+ Args:
114
+ context: The OpenAI LLM context containing messages.
115
+
116
+ Returns:
117
+ The last user message as a query string, optionally with context hints.
118
+ """
119
+ messages = context.get_messages()
120
+ query_parts = []
121
+
122
+ # Include interrupted response context as a hint (optional fallback strategy)
123
+ if hasattr(self, "_last_interrupted_response"):
124
+ interrupted_text = self._last_interrupted_response[:100] # Limit length
125
+ query_parts.append(
126
+ f"[Context: I was previously saying '{interrupted_text}...' when interrupted]"
127
+ )
128
+ # Clear the interrupted response after using it
129
+ delattr(self, "_last_interrupted_response")
130
+
131
+ # Find the last user message (iterate in reverse for efficiency)
132
+ for message in reversed(messages):
133
+ if message.get("role") == "user":
134
+ content = message.get("content", "")
135
+
136
+ # Handle content that might be a list (for multimodal messages)
137
+ if isinstance(content, list):
138
+ text_parts = [
139
+ item.get("text", "") for item in content if item.get("type") == "text"
140
+ ]
141
+ content = " ".join(text_parts)
142
+
143
+ if isinstance(content, str):
144
+ query_parts.append(content.strip())
145
+ break
146
+
147
+ # If no user message found, return empty string or just context
148
+ return " ".join(query_parts) if query_parts else ""
149
+
150
+ async def _handle_interruption(self):
151
+ """Handle interruption by cancelling ongoing stream."""
152
+ logger.debug("Handling interruption for Vistaar LLM")
153
+
154
+ # Set interruption flag
155
+ self._is_interrupted = True
156
+
157
+ # Cancel ongoing HTTP response stream if active
158
+ if self._current_response:
159
+ try:
160
+ await self._current_response.aclose()
161
+ logger.debug("Closed active Vistaar response stream")
162
+ except Exception as e:
163
+ logger.warning(f"Error closing Vistaar response stream: {e}")
164
+ finally:
165
+ self._current_response = None
166
+
167
+ # Store partial response for potential inclusion in next query
168
+ if self._partial_response:
169
+ partial_text = "".join(self._partial_response)
170
+ logger.debug(f"Storing interrupted response: {partial_text[:100]}...")
171
+ # Store the interrupted response for next query context
172
+ self._last_interrupted_response = partial_text
173
+
174
+ # Clear current partial response
175
+ self._partial_response = []
176
+
177
+ async def _stream_response(self, query: str) -> AsyncGenerator[str, None]:
178
+ """Stream response from Vistaar API using Server-Sent Events.
179
+
180
+ Args:
181
+ query: The user's query to send to the API.
182
+
183
+ Yields:
184
+ Text chunks from the streaming response.
185
+ """
186
+ # Prepare query parameters
187
+ params = {
188
+ "query": query,
189
+ "session_id": self._session_id,
190
+ "source_lang": self._source_lang,
191
+ "target_lang": self._target_lang,
192
+ }
193
+
194
+ # Add any extra parameters
195
+ params.update(self._extra)
196
+
197
+ # Construct the full URL with query parameters
198
+ url = f"{self._base_url}/voice/?{urlencode(params)}"
199
+
200
+ logger.info(
201
+ f"Vistaar API request - URL: {self._base_url}/voice/, Session: {self._session_id}, Query: {query[:100]}..."
202
+ )
203
+ logger.debug(f"Full URL with params: {url}")
204
+
205
+ # Reset interruption state and partial response for new request
206
+ self._is_interrupted = False
207
+ self._partial_response = []
208
+
209
+ try:
210
+ # Use httpx to handle SSE streaming
211
+ async with self._client.stream("GET", url) as response:
212
+ self._current_response = response # Store for potential cancellation
213
+ response.raise_for_status()
214
+
215
+ # Process the SSE stream
216
+ async for line in response.aiter_lines():
217
+ # Check for interruption before processing each line
218
+ if self._is_interrupted:
219
+ logger.debug("Stream interrupted, stopping processing")
220
+ break
221
+
222
+ if not line:
223
+ continue
224
+
225
+ self._partial_response.append(line) # Track what we're sending
226
+ yield line
227
+
228
+ except httpx.HTTPStatusError as e:
229
+ logger.error(
230
+ f"Vistaar HTTP error - Status: {e.response.status_code}, URL: {url}, Response: {e.response.text if hasattr(e.response, 'text') else 'N/A'}"
231
+ )
232
+ raise
233
+ except httpx.TimeoutException as e:
234
+ logger.error(f"Vistaar timeout error - URL: {url}, Timeout: {self._timeout}s")
235
+ raise
236
+ except Exception as e:
237
+ logger.error(
238
+ f"Vistaar unexpected error - Type: {type(e).__name__}, Message: {str(e)}, URL: {url}"
239
+ )
240
+ raise
241
+ finally:
242
+ # Clean up response reference
243
+ self._current_response = None
244
+
245
+ async def _process_context(self, context: OpenAILLMContext):
246
+ """Process the LLM context and generate streaming response.
247
+
248
+ Args:
249
+ context: The OpenAI LLM context containing messages to process.
250
+ """
251
+ logger.info(f"Vistaar processing context - Session: {self._session_id}")
252
+ try:
253
+ # Extract query from context
254
+ query = await self._extract_messages_to_query(context)
255
+
256
+ if not query:
257
+ logger.warning(
258
+ f"Vistaar: No query extracted from context - Session: {self._session_id}"
259
+ )
260
+ return
261
+
262
+ logger.info(f"Vistaar extracted query: {query}")
263
+
264
+ logger.debug(f"Processing query: {query[:100]}...")
265
+
266
+ # Start response
267
+ await self.push_frame(LLMFullResponseStartFrame())
268
+ await self.start_processing_metrics()
269
+ await self.start_ttfb_metrics()
270
+
271
+ first_chunk = True
272
+ full_response = []
273
+
274
+ # Stream the response
275
+ async for text_chunk in self._stream_response(query):
276
+ if first_chunk:
277
+ await self.stop_ttfb_metrics()
278
+ first_chunk = False
279
+
280
+ # Push each text chunk as it arrives
281
+ await self.push_frame(LLMTextFrame(text=text_chunk))
282
+ full_response.append(text_chunk)
283
+
284
+ # No need to update context - Vistaar maintains all context server-side
285
+ # The response has already been sent via LLMTextFrame chunks
286
+
287
+ except Exception as e:
288
+ logger.error(
289
+ f"Vistaar context processing error - Session: {self._session_id}, Error: {type(e).__name__}: {str(e)}"
290
+ )
291
+ import traceback
292
+
293
+ logger.error(f"Vistaar traceback: {traceback.format_exc()}")
294
+ raise
295
+ finally:
296
+ await self.stop_processing_metrics()
297
+ await self.push_frame(LLMFullResponseEndFrame())
298
+
299
+ async def process_frame(self, frame: Frame, direction: FrameDirection):
300
+ """Process frames for LLM completion requests.
301
+
302
+ Handles OpenAILLMContextFrame, LLMMessagesFrame, and LLMUpdateSettingsFrame
303
+ to trigger LLM completions and manage settings.
304
+
305
+ Args:
306
+ frame: The frame to process.
307
+ direction: The direction of frame processing.
308
+ """
309
+ await super().process_frame(frame, direction)
310
+ context = None
311
+ if isinstance(frame, StartInterruptionFrame):
312
+ await self._handle_interruption()
313
+ await self.push_frame(frame, direction)
314
+ return
315
+ elif isinstance(frame, OpenAILLMContextFrame):
316
+ context = frame.context
317
+ elif isinstance(frame, LLMMessagesFrame):
318
+ context = OpenAILLMContext.from_messages(frame.messages)
319
+ elif isinstance(frame, LLMUpdateSettingsFrame):
320
+ # Update settings if needed
321
+ settings = frame.settings
322
+ if "source_lang" in settings:
323
+ self._source_lang = settings["source_lang"]
324
+ if "target_lang" in settings:
325
+ self._target_lang = settings["target_lang"]
326
+ if "session_id" in settings:
327
+ self._session_id = settings["session_id"]
328
+ logger.debug(f"Updated Vistaar settings: {settings}")
329
+ else:
330
+ await self.push_frame(frame, direction)
331
+
332
+ if context:
333
+ try:
334
+ await self._process_context(context)
335
+ except httpx.TimeoutException:
336
+ logger.error("Timeout while processing Vistaar request")
337
+ await self._call_event_handler("on_completion_timeout")
338
+ except Exception as e:
339
+ logger.error(f"Error processing Vistaar request: {e}")
340
+ raise
341
+
342
+ def create_context_aggregator(
343
+ self,
344
+ context: OpenAILLMContext,
345
+ *,
346
+ user_params: LLMUserAggregatorParams = LLMUserAggregatorParams(),
347
+ assistant_params: LLMAssistantAggregatorParams = LLMAssistantAggregatorParams(),
348
+ ) -> OpenAIContextAggregatorPair:
349
+ """Create context aggregators for Vistaar LLM.
350
+
351
+ Since Vistaar uses OpenAI-compatible message format, we reuse OpenAI's
352
+ context aggregators directly, similar to how Groq and Azure services work.
353
+
354
+ Args:
355
+ context: The LLM context to create aggregators for.
356
+ user_params: Parameters for user message aggregation.
357
+ assistant_params: Parameters for assistant message aggregation.
358
+
359
+ Returns:
360
+ OpenAIContextAggregatorPair: A pair of OpenAI context aggregators,
361
+ compatible with Vistaar's OpenAI-like message format.
362
+ """
363
+ context.set_llm_adapter(self.get_llm_adapter())
364
+ user = OpenAIUserContextAggregator(context, params=user_params)
365
+ assistant = OpenAIAssistantContextAggregator(context, params=assistant_params)
366
+ return OpenAIContextAggregatorPair(_user=user, _assistant=assistant)
367
+
368
+ async def close(self):
369
+ """Close the HTTP client when the service is destroyed."""
370
+ await self._client.aclose()
371
+
372
+ def __del__(self):
373
+ """Ensure the client is closed on deletion."""
374
+ try:
375
+ asyncio.create_task(self._client.aclose())
376
+ except:
377
+ pass