Merge branch 'main' into feat/vici-dial

This commit is contained in:
Abhishek Kumar 2026-07-20 21:22:26 +05:30
commit 9458fdb67e
27 changed files with 2118 additions and 157 deletions

View file

@ -584,6 +584,20 @@ class SarvamLLMConfiguration(BaseLLMConfiguration):
OPENAI_REALTIME_MODELS = ["gpt-realtime-2"]
# ISO 639-1 codes accepted by the Realtime API's input_audio_transcription.
# Not exhaustive — the field allows custom input.
OPENAI_REALTIME_LANGUAGES = [
"en",
"es",
"pt",
"fr",
"de",
"it",
"hi",
"ja",
"ko",
"zh",
]
OPENAI_REALTIME_VOICES = [
"alloy",
"ash",
@ -618,6 +632,17 @@ class OpenAIRealtimeLLMConfiguration(BaseLLMConfiguration):
"allow_custom_input": True,
},
)
language: str | None = Field(
default=None,
description=(
"ISO 639-1 language code for input audio transcription (e.g. 'pt', 'es'). "
"Improves transcription accuracy and latency. Leave unset to auto-detect."
),
json_schema_extra={
"examples": OPENAI_REALTIME_LANGUAGES,
"allow_custom_input": True,
},
)
GROK_REALTIME_MODELS = ["grok-voice-think-fast-1.0"]

View file

@ -52,16 +52,6 @@ class AudioConfig:
)
self.pipeline_sample_rate = 16000
# Log configuration for auditing
logger.info(
f"AudioConfig initialized: "
f"transport_in={self.transport_in_sample_rate}Hz, "
f"transport_out={self.transport_out_sample_rate}Hz, "
f"vad={self.vad_sample_rate}Hz, "
f"pipeline={self.pipeline_sample_rate}Hz, "
f"buffer={self.buffer_size_seconds}s"
)
@property
def buffer_size_bytes(self) -> int:
"""Calculate buffer size in bytes based on pipeline sample rate."""

View file

@ -95,6 +95,9 @@ from pipecat.turns.user_start import (
MinWordsUserTurnStartStrategy,
ProvisionalVADUserTurnStartStrategy,
)
from pipecat.turns.user_start.transcription_user_turn_start_strategy import (
TranscriptionUserTurnStartStrategy,
)
from pipecat.turns.user_start.vad_user_turn_start_strategy import (
VADUserTurnStartStrategy,
)
@ -160,9 +163,10 @@ def _create_non_realtime_user_turn_start_strategies(
if turn_start_strategy == "provisional_vad":
return [
TranscriptionUserTurnStartStrategy(),
ProvisionalVADUserTurnStartStrategy(
pause_secs=_resolve_provisional_vad_pause_secs(run_configs)
)
),
]
if uses_external_turns:
@ -172,7 +176,7 @@ def _create_non_realtime_user_turn_start_strategies(
# confirms a real turn.
return [ExternalUserTurnStartStrategy(enable_interruptions=True)]
return [VADUserTurnStartStrategy()]
return [TranscriptionUserTurnStartStrategy(), VADUserTurnStartStrategy()]
def _create_non_realtime_user_turn_stop_strategies(

View file

@ -227,7 +227,6 @@ def create_stt_service(
# Other models than flux
# Use language from user config, defaulting to "multi" for multilingual support
language = getattr(user_config.stt, "language", None) or "multi"
logger.debug(f"Using DeepGram Model - {user_config.stt.model}")
return DeepgramSTTService(
api_key=user_config.stt.api_key,
settings=DeepgramSTTSettings(
@ -1009,6 +1008,13 @@ def create_realtime_llm_service(user_config, audio_config: "AudioConfig"):
SessionProperties,
)
# Pin the transcription language when configured. Without it the model
# auto-detects per utterance, which misfires on short/noisy telephony
# audio (e.g. Portuguese transcribed as English or Chinese).
transcription_kwargs = {}
if language:
transcription_kwargs["language"] = language
return DograhOpenAIRealtimeLLMService(
api_key=api_key,
settings=DograhOpenAIRealtimeLLMService.Settings(
@ -1016,7 +1022,9 @@ def create_realtime_llm_service(user_config, audio_config: "AudioConfig"):
session_properties=SessionProperties(
audio=AudioConfiguration(
input=AudioInput(
transcription=InputAudioTranscription(),
transcription=InputAudioTranscription(
**transcription_kwargs
),
),
output=AudioOutput(
voice=voice or "alloy",

View file

@ -8,6 +8,7 @@ import httpx
from loguru import logger
from api.db import db_client
from api.services.configuration.masking import mask_key
from api.utils.credential_auth import build_auth_header
from api.utils.template_renderer import render_template
@ -21,6 +22,19 @@ TYPE_MAP = {
}
def serialize_query_params(arguments: Dict[str, Any]) -> Dict[str, Any]:
"""JSON-stringify dict/list values so they're safe to pass as query params.
httpx (and query strings in general) only support primitive param values.
Object/array-typed tool arguments must be serialized before going out as
GET/DELETE query params, otherwise httpx raises a TypeError.
"""
return {
k: json.dumps(v) if isinstance(v, (dict, list)) else v
for k, v in arguments.items()
}
def tool_to_function_schema(tool: Any) -> Dict[str, Any]:
"""Convert a ToolModel to an LLM function schema.
@ -224,7 +238,9 @@ async def execute_http_tool(
arguments: Dict[str, Any],
call_context_vars: Optional[Dict[str, Any]] = None,
gathered_context_vars: Optional[Dict[str, Any]] = None,
preset_params: Optional[Dict[str, Any]] = None,
organization_id: Optional[int] = None,
include_request_headers: bool = False,
) -> Dict[str, Any]:
"""Execute an HTTP API tool.
@ -233,7 +249,11 @@ async def execute_http_tool(
arguments: Arguments passed by the LLM (parameter name -> value)
call_context_vars: Initial context variables available at runtime
gathered_context_vars: Variables extracted during the conversation
preset_params: Pre-resolved preset parameter values. Used by the test
endpoint; live calls omit this so configured templates are resolved.
organization_id: Organization ID for credential lookup
include_request_headers: Include a client-safe header preview in the result.
Headers supplied by a stored credential are masked.
Returns:
Result dict with response data or error
@ -248,7 +268,9 @@ async def execute_http_tool(
# Get headers from config
headers = dict(config.get("headers", {}) or {})
# Add auth header if credential is configured
# Add auth header if credential is configured. Keep track of which headers
# came from the credential so only those values are masked in test previews.
credential_headers: Dict[str, str] = {}
credential_uuid = config.get("credential_uuid")
if credential_uuid and organization_id:
try:
@ -256,8 +278,8 @@ async def execute_http_tool(
credential_uuid, organization_id
)
if credential:
auth_header = build_auth_header(credential)
headers.update(auth_header)
credential_headers = build_auth_header(credential)
headers.update(credential_headers)
logger.debug(f"Applied credential '{credential.name}' to tool request")
else:
logger.warning(
@ -266,17 +288,31 @@ async def execute_http_tool(
except Exception as e:
logger.error(f"Failed to fetch credential for tool '{tool.name}': {e}")
request_headers: Dict[str, str] = {}
if include_request_headers:
request_headers = {str(name): str(value) for name, value in headers.items()}
for header_name, header_value in credential_headers.items():
request_headers[header_name] = mask_key(str(header_value))
def build_result(result: Dict[str, Any]) -> Dict[str, Any]:
if include_request_headers:
return {**result, "request_headers": request_headers}
return result
# Get timeout
timeout_ms = config.get("timeout_ms", 5000)
timeout_seconds = timeout_ms / 1000
try:
preset_arguments = _resolve_preset_parameters(
config, call_context_vars, gathered_context_vars
)
except ValueError as e:
logger.error(f"Custom tool '{tool.name}' preset parameter error: {e}")
return {"status": "error", "error": str(e)}
if preset_params is None:
try:
preset_arguments = _resolve_preset_parameters(
config, call_context_vars, gathered_context_vars
)
except ValueError as e:
logger.error(f"Custom tool '{tool.name}' preset parameter error: {e}")
return build_result({"status": "error", "error": str(e)})
else:
preset_arguments = dict(preset_params)
resolved_arguments = {**(arguments or {}), **preset_arguments}
@ -286,7 +322,7 @@ async def execute_http_tool(
if method in ("POST", "PUT", "PATCH"):
body = resolved_arguments
elif method in ("GET", "DELETE") and resolved_arguments:
params = resolved_arguments
params = serialize_query_params(resolved_arguments)
logger.info(
f"Executing custom tool '{tool.name}' ({tool.tool_uuid}): {method} {url}"
@ -322,23 +358,29 @@ async def execute_http_tool(
logger.debug(
f"Custom tool '{tool.name}' completed with status {response.status_code}"
)
return result
return build_result(result)
except httpx.TimeoutException:
logger.error(f"Custom tool '{tool.name}' timed out after {timeout_seconds}s")
return {
"status": "error",
"error": f"Request timed out after {timeout_seconds} seconds",
}
return build_result(
{
"status": "error",
"error": f"Request timed out after {timeout_seconds} seconds",
}
)
except httpx.RequestError as e:
logger.error(f"Custom tool '{tool.name}' request failed: {e}")
return {
"status": "error",
"error": f"Request failed: {str(e)}",
}
return build_result(
{
"status": "error",
"error": f"Request failed: {str(e)}",
}
)
except Exception as e:
logger.error(f"Custom tool '{tool.name}' execution failed: {e}")
return {
"status": "error",
"error": f"Tool execution failed: {str(e)}",
}
return build_result(
{
"status": "error",
"error": f"Tool execution failed: {str(e)}",
}
)