From 8714c9137fc3e36a12584f85ed7a184b4864f247 Mon Sep 17 00:00:00 2001 From: Mark Backman Date: Tue, 12 Aug 2025 14:44:34 -0400 Subject: [PATCH] Code review fixes --- CHANGELOG.md | 15 +++++---------- src/pipecat/services/openai/base_llm.py | 9 +++++---- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 005f5293d..da4b2be40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Gemini model can be prompted to insert styled speech to control the TTS output. +- For `OpenAILLMService` and its subclasses, added the ability to retry + executing a chat completion after a timeout period. The new args are + `retry_timeout_secs` and `retry_on_timeout`. This feature is disabled by + default. + - Added Exotel support to Pipecat's development runner. You can now connect using the runner with `uv run bot.py -t exotel` and an ngrok connection to HTTP port 7860. @@ -63,8 +68,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed an issue that would cause system frames to not be processed with higher priority than other frames. This could cause slower interruption times. -### Fixed - - Fixed an issue where retrying a websocket connection error would result in an error. @@ -106,14 +109,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 `LLMUserContextAggregator` and `LLMAssistantResponseAggregator` (or LLM-specific subclasses thereof) instead. -## [Unreleased] - -### Added - -- For `OpenAILLMService` and its subclasses, added the ability to retry - executing a chat completion after a timeout period. The new args are - `timeout` and `retry_on_timeout`. This feature is disabled by default. - ## [0.0.78] - 2025-08-07 ### Added diff --git a/src/pipecat/services/openai/base_llm.py b/src/pipecat/services/openai/base_llm.py index 5fb11ea4d..ecde66eec 100644 --- a/src/pipecat/services/openai/base_llm.py +++ b/src/pipecat/services/openai/base_llm.py @@ -93,7 +93,7 @@ class BaseOpenAILLMService(LLMService): project=None, default_headers: Optional[Mapping[str, str]] = None, params: Optional[InputParams] = None, - timeout: Optional[float] = 5.0, + retry_timeout_secs: Optional[float] = 5.0, retry_on_timeout: Optional[bool] = False, **kwargs, ): @@ -107,7 +107,7 @@ class BaseOpenAILLMService(LLMService): project: OpenAI project ID. default_headers: Additional HTTP headers to include in requests. params: Input parameters for model configuration and behavior. - timeout: Request timeout in seconds. Defaults to 5.0 seconds. + retry_timeout_secs: Request timeout in seconds. Defaults to 5.0 seconds. retry_on_timeout: Whether to retry the request once if it times out. **kwargs: Additional arguments passed to the parent LLMService. """ @@ -125,7 +125,7 @@ class BaseOpenAILLMService(LLMService): "max_completion_tokens": params.max_completion_tokens, "extra": params.extra if isinstance(params.extra, dict) else {}, } - self._timeout = timeout + self._retry_timeout_secs = retry_timeout_secs self._retry_on_timeout = retry_on_timeout self.set_model_name(model) self._client = self.create_client( @@ -197,11 +197,12 @@ class BaseOpenAILLMService(LLMService): if self._retry_on_timeout: try: chunks = await asyncio.wait_for( - self._client.chat.completions.create(**params), timeout=self._timeout + self._client.chat.completions.create(**params), timeout=self._retry_timeout_secs ) return chunks except (APITimeoutError, asyncio.TimeoutError): # Retry, this time without a timeout so we get a response + logger.debug(f"{self}: Retrying chat completion due to timeout") chunks = await self._client.chat.completions.create(**params) return chunks else: