feat: compose follows the selected language#688
Conversation
📝 WalkthroughWalkthroughThis PR adds language selection support to the compose (in-character generation) feature. The backend now accepts a language parameter in the compose request and uses it to instruct the LLM's output language. The frontend form passes the selected language when calling compose, and the API client relays it in the request body. ChangesLanguage parameter for composition
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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 |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
backend/services/personality.py (1)
76-90:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winGuard optional
databefore readinglanguage.Line 76 allows
datato beNone, but Line 90 readsdata.languageunconditionally. PassingNonewill raiseAttributeErrorand fail compose unexpectedly.Suggested fix
async def compose_as_profile( personality: str | None, - data: models.ComposeRequest | None = models.ComposeRequest(language="en"), + data: models.ComposeRequest | None = None, model_size: str | None = None, ) -> PersonalityResult: @@ - system_prompt = f"{_build_system_prompt(text, _COMPOSE_TASK)}. Output language: {LANGUAGE_CODE_TO_NAME.get(data.language if data.language else 'en')}" + language_code = data.language if data and data.language else "en" + language_name = LANGUAGE_CODE_TO_NAME.get(language_code, "English") + system_prompt = f"{_build_system_prompt(text, _COMPOSE_TASK)}. Output language: {language_name}"🤖 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/services/personality.py` around lines 76 - 90, The code reads data.language without guarding for an optional data parameter; update the compose function to handle data being None by computing the language with a safe expression (e.g., language = data.language if data and data.language else 'en') and use that variable in the system_prompt construction when calling _build_system_prompt and looking up LANGUAGE_CODE_TO_NAME (referencing the data parameter, models.ComposeRequest, system_prompt, _build_system_prompt, _COMPOSE_TASK). Ensure you do not access data.language directly when data may be None.
🤖 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.
Outside diff comments:
In `@backend/services/personality.py`:
- Around line 76-90: The code reads data.language without guarding for an
optional data parameter; update the compose function to handle data being None
by computing the language with a safe expression (e.g., language = data.language
if data and data.language else 'en') and use that variable in the system_prompt
construction when calling _build_system_prompt and looking up
LANGUAGE_CODE_TO_NAME (referencing the data parameter, models.ComposeRequest,
system_prompt, _build_system_prompt, _COMPOSE_TASK). Ensure you do not access
data.language directly when data may be None.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 97c36508-4f8f-4ff9-bcb6-bc3c4224d5ee
📒 Files selected for processing (5)
app/src/components/Generation/FloatingGenerateBox.tsxapp/src/lib/api/client.tsbackend/models.pybackend/routes/profiles.pybackend/services/personality.py
The original 'compose' could only generate English. Now, as picture, it can follows the selected language.
Summary by CodeRabbit
New Features