Skip to content

feat: compose follows the selected language#688

Open
xorss wants to merge 1 commit into
jamiepine:mainfrom
xorss:feat-v0.0.1
Open

feat: compose follows the selected language#688
xorss wants to merge 1 commit into
jamiepine:mainfrom
xorss:feat-v0.0.1

Conversation

@xorss
Copy link
Copy Markdown

@xorss xorss commented May 22, 2026

The original 'compose' could only generate English. Now, as picture, it can follows the selected language.

Snipaste_2026-05-22_16-34-23

Summary by CodeRabbit

New Features

  • Added language selection for text generation. Users can now choose their preferred output language when generating content, with English as the default option.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

📝 Walkthrough

Walkthrough

This 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.

Changes

Language parameter for composition

Layer / File(s) Summary
Compose request model and personality service language support
backend/models.py, backend/services/personality.py
ComposeRequest model adds a validated language field (defaulting to "en"). The compose_as_profile function now accepts this request data and appends an "Output language" instruction to the system prompt using the language code.
Backend route accepts and passes request data
backend/routes/profiles.py
The compose_in_character endpoint handler now receives ComposeRequest as a parameter and passes it to compose_as_profile instead of calling the service without request data.
Frontend API client and form integration
app/src/lib/api/client.ts, app/src/components/Generation/FloatingGenerateBox.tsx
The API client's composeWithPersonality method now accepts a language parameter and sends it in the request body. The FloatingGenerateBox form passes the currently selected language from form values when invoking the mutation.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A language for every voice to sing,
From form to service, parameters wing,
East to west, words now flow just right,
Personality speaks in each tongue's delight! 🌍

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: the compose feature now respects the user's selected language preference instead of generating only English output.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Guard optional data before reading language.

Line 76 allows data to be None, but Line 90 reads data.language unconditionally. Passing None will raise AttributeError and 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

📥 Commits

Reviewing files that changed from the base of the PR and between b35b909 and 2645de5.

📒 Files selected for processing (5)
  • app/src/components/Generation/FloatingGenerateBox.tsx
  • app/src/lib/api/client.ts
  • backend/models.py
  • backend/routes/profiles.py
  • backend/services/personality.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant