HiyokoLogcat: Building Consistent Gemini Responses with Target-Language Prompts
Build system prompts in the target language to avoid inconsistent responses from Gemini.
Implement target‑language system prompts in your Gemini integration to ensure consistent responses.
Summary
HiyokoLogcat supports Japanese and English by writing the system prompt in the target language, which eliminates inconsistent responses from Gemini that occur when appending “Respond in Japanese” to an English prompt. The Rust code defines a Lang enum with Japanese, English, and Korean variants, and a build_system_prompt function that returns a static string in the chosen language. The diagnose function uses this system prompt and passes the context to Gemini without post‑processing, ensuring that the response is always in the desired language. The approach removes the need for translation APIs, cutting cost and latency. The code also demonstrates how to read the frontend locale string and map it to the Lang enum, making it easy to add new languages. Consistent responses are achieved by matching the prompt language to the desired output language.
Key changes
- System prompts are written in the target language to avoid inconsistent responses from Gemini.
- Rust enum Lang includes Japanese, English, and Korean variants for prompt selection.
- build_system_prompt returns a static string in the chosen language, ensuring deterministic prompts.
- diagnose function uses the system prompt and passes the context to Gemini without post‑processing.
- The approach eliminates the need for translation APIs, reducing cost and latency.
- Consistent responses are achieved by matching the prompt language to the desired output language.