Gemini TTS: Default Instructions Parsing - #1086
Conversation
📝 WalkthroughWalkthroughThe default Gemini TTS model is updated, and Google Vertex AI and AI Studio TTS requests now wrap input text in ChangesGemini TTS
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
OpenAPI changes 🟢 1 non-breaking changeTip Safe to merge from an API-contract perspective. Full changelog ·
|
| Method | Path | Change | |
|---|---|---|---|
| 🟢 | POST |
/api/v1/llm/chain/sts |
the model request property default value changed from gemini-2.5-flash-preview-tts to gemini-3.1-flash-tts-preview |
main ↔ 9beb2deb · generated by oasdiff
There was a problem hiding this comment.
🧹 Nitpick comments (2)
backend/app/services/llm/providers/google_ai.py (1)
521-525: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a Vertex-specific transcript payload assertion.
The AI Studio test covers the new wrapper, but this provider constructs a different
contentsshape. Add or verify atest_google_ai.pyassertion thatcontents[0]["parts"][0]["text"]equals the<transcript>...</transcript>value.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/app/services/llm/providers/google_ai.py` around lines 521 - 525, Add a Vertex-specific assertion in test_google_ai.py for the payload built by the provider flow around decorate_resolved_input, verifying that contents[0]["parts"][0]["text"] contains the expected <transcript>...</transcript> wrapper around resolved_input.backend/app/tests/services/llm/providers/test_google_aistudio.py (1)
526-526: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for the new default model.
The fixture pins
gemini-2.5-pro-preview-tts, so this assertion verifies tagging but never exercisesDEFAULT_TTS_MODEL. Add a test that omitsparams["model"]and asserts the request usesgemini-3.1-flash-tts-preview.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/app/tests/services/llm/providers/test_google_aistudio.py` at line 526, Add coverage near the existing TTS request test for the default-model path: omit params["model"], invoke the same request flow, and assert the generated request uses gemini-3.1-flash-tts-preview. Keep the existing explicit-model tagging assertion unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@backend/app/services/llm/providers/google_ai.py`:
- Around line 521-525: Add a Vertex-specific assertion in test_google_ai.py for
the payload built by the provider flow around decorate_resolved_input, verifying
that contents[0]["parts"][0]["text"] contains the expected
<transcript>...</transcript> wrapper around resolved_input.
In `@backend/app/tests/services/llm/providers/test_google_aistudio.py`:
- Line 526: Add coverage near the existing TTS request test for the
default-model path: omit params["model"], invoke the same request flow, and
assert the generated request uses gemini-3.1-flash-tts-preview. Keep the
existing explicit-model tagging assertion unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 60a5586a-d926-4a6b-8f67-cb7b77ea7573
📒 Files selected for processing (4)
backend/app/models/llm/constants.pybackend/app/services/llm/providers/google_ai.pybackend/app/services/llm/providers/google_aistudio.pybackend/app/tests/services/llm/providers/test_google_aistudio.py
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/app/tests/services/llm/providers/test_google_ai.py`:
- Around line 266-275: Add narrow type annotations to the
test_tts_wraps_input_in_transcript_tags method for provider, tts_config, query,
and its None return value, using the concrete types already established by the
fixture definitions or surrounding tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 4baede03-8532-4560-a05c-8a5a819df5ca
📒 Files selected for processing (1)
backend/app/tests/services/llm/providers/test_google_ai.py
| def test_tts_wraps_input_in_transcript_tags(self, provider, tts_config, query): | ||
| with patch( | ||
| "app.services.llm.providers.google_ai.requests.post", | ||
| return_value=_mock_http_ok(_tts_response()), | ||
| ) as mock_post: | ||
| provider.execute(tts_config, query, "Say this text") | ||
|
|
||
| parts = mock_post.call_args.kwargs["json"]["contents"][0]["parts"] | ||
| assert parts[0]["text"] == "<transcript>Say this text</transcript>" | ||
|
|
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add narrow type hints to the test method.
Annotate provider, tts_config, query, and the None return value, for example:
Proposed fix
- def test_tts_wraps_input_in_transcript_tags(self, provider, tts_config, query):
+ def test_tts_wraps_input_in_transcript_tags(
+ self: TestGoogleVertexAIProvider,
+ provider: GoogleVertexAIProvider,
+ tts_config: NativeCompletionConfig,
+ query: QueryParams,
+ ) -> None:As per coding guidelines, Python functions must provide narrow type hints for every parameter and return value.
🧰 Tools
🪛 ast-grep (0.44.1)
[info] 266-269: no timeout was given on call to external resource
Context: patch(
"app.services.llm.providers.google_ai.requests.post",
return_value=_mock_http_ok(_tts_response()),
)
Note: [CWE-1088] Synchronous Access of Remote Resource without Timeout.
(requests-timeout)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@backend/app/tests/services/llm/providers/test_google_ai.py` around lines 266
- 275, Add narrow type annotations to the
test_tts_wraps_input_in_transcript_tags method for provider, tts_config, query,
and its None return value, using the concrete types already established by the
fixture definitions or surrounding tests.
Source: Coding guidelines
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/app/tests/services/llm/providers/test_google_ai.py`:
- Around line 336-340: Update the NativeCompletionConfig fixture in the Google
TTS test to omit the model parameter so _execute_tts exercises DEFAULT_TTS_MODEL
resolution, or set it to gemini-3.1-flash-tts-preview. Keep the existing
provider, completion type, and voice parameters unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: cc9b9ff7-3669-4bc7-a7ba-0618b0299c4b
📒 Files selected for processing (1)
backend/app/tests/services/llm/providers/test_google_ai.py
| config = NativeCompletionConfig( | ||
| provider="google-native", | ||
| type=CompletionType.TTS, | ||
| params={"model": "gemini-2.5-flash-preview-tts", "voice": "Kore"}, | ||
| ) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== locate file =="
fd -a 'test_google_ai.py|google_ai.py|.*google.*' . | sed 's#^\./##' | head -50
echo "== target lines =="
if [ -f backend/app/tests/services/llm/providers/test_google_ai.py ]; then
wc -l backend/app/tests/services/llm/providers/test_google_ai.py
sed -n '310,360p' backend/app/tests/services/llm/providers/test_google_ai.py
fi
echo "== search default model references =="
rg -n "gemini-2\.5-flash-preview-tts|gemini-3\.1-flash-preview-tts|TTS|NativeCompletionConfig|model_defaults|defaults" backend/app -SRepository: ProjectTech4DevAI/kaapi-backend
Length of output: 50387
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== google provider relevant outline =="
ast-grep outline backend/app/services/llm/providers/google_ai.py --view expanded | sed -n '1,220p'
echo "== google provider defaults/default resolution snippets =="
rg -n -C 4 "DEFAULT|default|execute|model|params\[" backend/app/services/llm/providers/google_ai.py backend/app/services/llm/providers -g '*.py' | rg -C 3 "gemini-3\.1-flash-preview-tts|gemini-2\.5-flash-preview-tts|DEFAULT_|default"
echo "== exact relevant google_ai.py sections =="
wc -l backend/app/services/llm/providers/google_ai.py
sed -n '1,220p' backend/app/services/llm/providers/google_ai.py
sed -n '220,420p' backend/app/services/llm/providers/google_ai.py
echo "== mapper Google TTS default references =="
rg -n -C 4 "gemini-3\.1-flash-preview-tts|gemini-2\.5-flash-preview-tts" backend/app/services backend/app/api backend/app/models backend/app/crud | head -220Repository: ProjectTech4DevAI/kaapi-backend
Length of output: 34067
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== DEFAULT_TTS_MODEL definition =="
rg -n -C 5 "DEFAULT_TTS_MODEL\s*=" backend/app/models backend/app/services backend/app -g '*.py'
echo "== Google TTS execute section =="
sed -n '474,570p' backend/app/services/llm/providers/google_ai.py
echo "== mapper Google TTS implementation candidates =="
rg -n -C 3 '"gemini-3\.1-flash-preview-tts"|"gemini-2\.5-flash-preview-tts"|DEFAULT_TTS_MODEL|model.*=.*"gemini|TTSLLMParams|google' backend/app/services/llm -g '*.py' | sed -n '1,260p'
echo "== test_TTS wraps fixture config around payload assertion =="
sed -n '310,345p' backend/app/tests/services/llm/providers/test_google_ai.pyRepository: ProjectTech4DevAI/kaapi-backend
Length of output: 31313
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== gemini model refs =="
rg -n --iglob '*.py' --iglob '*.md' --iglob '*.yaml' --iglob '*.yml' "gemini-(3\.1|2\.5)-flash-preview-tts|flash-preview-tts|flash-tts-preview|DEFAULT_TTS_MODEL" backend/app tests 2>/dev/null | head -220
echo "== changed/default TTS model usage in tests =="
python3 - <<'PY'
from pathlib import Path
p = Path('backend/app/tests/services/llm/providers/test_google_ai.py')
text = p.read_text()
for needle in ['params={"model":', 'params.get("model")', 'model = params', 'gemini-2.5-flash-preview-tts', 'gemini-3.1-flash-preview-tts', 'gemini-3.1-flash-tts-preview']:
print(f'{needle}: {text.count(needle)}')
PYRepository: ProjectTech4DevAI/kaapi-backend
Length of output: 3516
Exercise the updated TTS model default.
GoogleVertexAIProvider._execute_tts uses params.get("model") or DEFAULT_TTS_MODEL. Since DEFAULT_TTS_MODEL is gemini-3.1-flash-tts-preview, this fixture should either use the new model or omit model so default resolution is covered instead of hardcoding an old model variant.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@backend/app/tests/services/llm/providers/test_google_ai.py` around lines 336
- 340, Update the NativeCompletionConfig fixture in the Google TTS test to omit
the model parameter so _execute_tts exercises DEFAULT_TTS_MODEL resolution, or
set it to gemini-3.1-flash-tts-preview. Keep the existing provider, completion
type, and voice parameters unchanged.
Issue #1054
Summary
<transcript>tag in the TTS block.Checklist
Before submitting a pull request, please ensure that you mark these task.
fastapi run --reload app/main.pyordocker compose upin the repository root and test.Summary by CodeRabbit
Summary by CodeRabbit
Improvements
<transcript>...</transcript>tags for more consistent synthesis.Tests