Add support for universal LLMContext to SambaNova LLM service

This commit is contained in:
Paul Kompfner
2025-09-02 15:40:15 -04:00
parent 91a3f63e28
commit e04f42167e

View File

@@ -18,6 +18,7 @@ from pipecat.frames.frames import (
LLMTextFrame, LLMTextFrame,
) )
from pipecat.metrics.metrics import LLMTokenUsage from pipecat.metrics.metrics import LLMTokenUsage
from pipecat.processors.aggregators.llm_context import LLMContext
from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContext from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContext
from pipecat.services.llm_service import FunctionCallFromLLM from pipecat.services.llm_service import FunctionCallFromLLM
from pipecat.services.openai.llm import OpenAILLMService from pipecat.services.openai.llm import OpenAILLMService
@@ -99,7 +100,9 @@ class SambaNovaLLMService(OpenAILLMService): # type: ignore
return params return params
@traced_llm # type: ignore @traced_llm # type: ignore
async def _process_context(self, context: OpenAILLMContext) -> AsyncStream[ChatCompletionChunk]: async def _process_context(
self, context: OpenAILLMContext | LLMContext
) -> AsyncStream[ChatCompletionChunk]:
"""Process OpenAI LLM context and stream chat completion chunks. """Process OpenAI LLM context and stream chat completion chunks.
This method handles the streaming response from SambaNova API, including This method handles the streaming response from SambaNova API, including
@@ -122,9 +125,11 @@ class SambaNovaLLMService(OpenAILLMService): # type: ignore
await self.start_ttfb_metrics() await self.start_ttfb_metrics()
chunk_stream: AsyncStream[ chunk_stream = await (
ChatCompletionChunk self._stream_chat_completions_specific_context(context)
] = await self._stream_chat_completions_specific_context(context) if isinstance(context, OpenAILLMContext)
else self._stream_chat_completions_universal_context(context)
)
async for chunk in chunk_stream: async for chunk in chunk_stream:
if chunk.usage: if chunk.usage:
@@ -210,12 +215,3 @@ class SambaNovaLLMService(OpenAILLMService): # type: ignore
) )
await self.run_function_calls(function_calls) await self.run_function_calls(function_calls)
@property
def supports_universal_context(self) -> bool:
"""Check if this service supports universal LLMContext.
Returns:
False, as SambaNovaLLMService does not yet support universal LLMContext.
"""
return False