Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions backend/app/models/llm/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def normalize_bcp47_language(value: str) -> str:


DEFAULT_STT_MODEL = "gemini-2.5-pro"
DEFAULT_TTS_MODEL = "gemini-3.1-flash-tts-preview"
DEFAULT_TTS_MODEL = "gemini-3.8-flash-tts"
DEFAULT_TTS_VOICE = "Kore"
DEFAULT_RAG_MODEL = "gpt-4o"

Expand All @@ -199,21 +199,24 @@ def normalize_bcp47_language(value: str) -> str:
DEFAULT_ELEVENLABS_STT_MODEL = "scribe_v2"
DEFAULT_ELEVENLABS_TTS_MODEL = "eleven_v3"

# BCP-47 to language tag -> Gemini ISO 639-1 code (Indic + English)
# Kaapi BCP-47 tag -> Gemini TTS language. Full locales, not bare ISO codes:
# en-IN keeps the Indian accent where "en" does not. Unlisted tags fall back
# to auto-detect.
BCP47_LOCALE_TO_GEMINI_LANG: dict[str, str] = {
"en-IN": "en",
"hi-IN": "hi",
"bn-IN": "bn",
"ta-IN": "ta",
"te-IN": "te",
"mr-IN": "mr",
"gu-IN": "gu",
"kn-IN": "kn",
"ml-IN": "ml",
"pa-IN": "pa",
"od-IN": "or",
# "as-IN": "as", //not supported by Gemini
"sd-IN": "sd",
"en-IN": "en-IN",
"hi-IN": "hi-IN",
"bn-IN": "bn-IN",
"ta-IN": "ta-IN",
"te-IN": "te-IN",
"mr-IN": "mr-IN",
"gu-IN": "gu-IN",
"kn-IN": "kn-IN",
"ml-IN": "ml-IN",
"pa-IN": "pa-IN",
# Kaapi uses the non-standard "od-IN" for Odia; the real tag is "or-IN".
"od-IN": "or-IN",
# "as-IN": not supported by Gemini
"sd-IN": "sd-IN",
}

# BCP-47 language tag → ElevenLabs ISO 639-1 code (Indic + English)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/models/llm/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class TextLLMParams(ParamSerialization, SQLModel):
"(e.g. {'type': 'enabled', 'budget_tokens': 4096})"
),
)
thinking_level: Literal["low", "medium", "high"] | None = Field(
thinking_level: Literal["minimal", "low", "medium", "high"] | None = Field(
default=None,
description="Google thinking level for thinking-capable Gemini models",
)
Expand Down
23 changes: 6 additions & 17 deletions backend/app/services/llm/mappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,9 @@ def map_kaapi_to_google_params(
Supported Mapping:
- model → model
- instructions → instructions (for STT prompts, if available)
- temperature -> temperature parameter (0-2)
- top_p / max_output_tokens → same name (text only)
- temperature / top_p → not sent (deprecated by Gemini)
- max_output_tokens → same name (text only)
- language → full Gemini locale via BCP47_LOCALE_TO_GEMINI_LANG; unsupported → auto-detect (TTS only)
- thinking_level → thinking_config.thinking_level (text only)
- output_schema → output_schema, converted to Gemini's shape (text only)
- knowledge_base_ids → FileSearch tool store names (text only)
Expand Down Expand Up @@ -296,19 +297,11 @@ def map_kaapi_to_google_params(
google_params["model"] = model

if completion_type == CompletionType.TEXT:
# Text completion - instructions, temperature, reasoning, knowledge_base_ids
# Text completion - instructions, reasoning, knowledge_base_ids
instructions = params.get("instructions")
if instructions:
google_params["instructions"] = instructions

temperature = params.get("temperature")
if temperature is not None:
google_params["temperature"] = temperature

top_p = params.get("top_p")
if top_p is not None:
google_params["top_p"] = top_p

max_output_tokens = params.get("max_output_tokens")
if max_output_tokens is not None:
google_params["max_output_tokens"] = max_output_tokens
Expand Down Expand Up @@ -353,7 +346,7 @@ def map_kaapi_to_google_params(
# Language: Only set if explicitly provided (None/missing = auto-detect)
language = params.get("language")
if language:
google_lang = BCP47_LOCALE_TO_GEMINI_LANG.get(language) or None
google_lang = BCP47_LOCALE_TO_GEMINI_LANG.get(language)
if not google_lang:
warnings.append(
f"Unsupported language '{language}' for Gemini TTS, using auto-detect"
Expand All @@ -362,7 +355,7 @@ def map_kaapi_to_google_params(
google_params["language"] = google_lang

elif completion_type == CompletionType.STT:
# STT mode - instructions, temperature, input_language, output_language, response_format
# STT mode - instructions, input_language, output_language, response_format
# Apply smart default for input_language
input_language = params.get("input_language") or "auto"
google_params["input_language"] = input_language
Expand All @@ -372,10 +365,6 @@ def map_kaapi_to_google_params(
if instructions:
google_params["instructions"] = instructions

temperature = params.get("temperature")
if temperature is not None:
google_params["temperature"] = temperature

output_language = params.get("output_language")
if output_language:
google_params["output_language"] = output_language
Expand Down
Loading
Loading