Code review fixes

This commit is contained in:
Mark Backman
2025-08-12 14:44:34 -04:00
parent 4c029fcfa7
commit 8714c9137f
2 changed files with 10 additions and 14 deletions

View File

@@ -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 Gemini model can be prompted to insert styled speech to control the TTS
output. 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 - 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 using the runner with `uv run bot.py -t exotel` and an ngrok connection to
HTTP port 7860. 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 - Fixed an issue that would cause system frames to not be processed with higher
priority than other frames. This could cause slower interruption times. priority than other frames. This could cause slower interruption times.
### Fixed
- Fixed an issue where retrying a websocket connection error would result in an - Fixed an issue where retrying a websocket connection error would result in an
error. error.
@@ -106,14 +109,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`LLMUserContextAggregator` and `LLMAssistantResponseAggregator` (or `LLMUserContextAggregator` and `LLMAssistantResponseAggregator` (or
LLM-specific subclasses thereof) instead. 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 ## [0.0.78] - 2025-08-07
### Added ### Added

View File

@@ -93,7 +93,7 @@ class BaseOpenAILLMService(LLMService):
project=None, project=None,
default_headers: Optional[Mapping[str, str]] = None, default_headers: Optional[Mapping[str, str]] = None,
params: Optional[InputParams] = None, params: Optional[InputParams] = None,
timeout: Optional[float] = 5.0, retry_timeout_secs: Optional[float] = 5.0,
retry_on_timeout: Optional[bool] = False, retry_on_timeout: Optional[bool] = False,
**kwargs, **kwargs,
): ):
@@ -107,7 +107,7 @@ class BaseOpenAILLMService(LLMService):
project: OpenAI project ID. project: OpenAI project ID.
default_headers: Additional HTTP headers to include in requests. default_headers: Additional HTTP headers to include in requests.
params: Input parameters for model configuration and behavior. 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. retry_on_timeout: Whether to retry the request once if it times out.
**kwargs: Additional arguments passed to the parent LLMService. **kwargs: Additional arguments passed to the parent LLMService.
""" """
@@ -125,7 +125,7 @@ class BaseOpenAILLMService(LLMService):
"max_completion_tokens": params.max_completion_tokens, "max_completion_tokens": params.max_completion_tokens,
"extra": params.extra if isinstance(params.extra, dict) else {}, "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._retry_on_timeout = retry_on_timeout
self.set_model_name(model) self.set_model_name(model)
self._client = self.create_client( self._client = self.create_client(
@@ -197,11 +197,12 @@ class BaseOpenAILLMService(LLMService):
if self._retry_on_timeout: if self._retry_on_timeout:
try: try:
chunks = await asyncio.wait_for( 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 return chunks
except (APITimeoutError, asyncio.TimeoutError): except (APITimeoutError, asyncio.TimeoutError):
# Retry, this time without a timeout so we get a response # 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) chunks = await self._client.chat.completions.create(**params)
return chunks return chunks
else: else: