Tuned the Japanese mode system prompt and model better

This commit is contained in:
2026-01-23 17:01:47 +02:00
parent fe0962118b
commit dca58328e4
2 changed files with 90 additions and 2 deletions

View File

@@ -48,8 +48,14 @@ def _get_japanese_instruction() -> str:
"""
Returns the Japanese language instruction to append to context.
Ensures all responses are in Japanese when in Japanese mode.
This is a secondary reminder - the primary enforcement is in the system prompt.
"""
return "\n\n[CRITICAL INSTRUCTION - 重要な指示]\n**YOU MUST RESPOND ENTIRELY IN JAPANESE (日本語). NO ENGLISH ALLOWED.**\nすべての返答は必ず日本語で行ってください。英語での返答は一切禁止されています。\nこれは最優先の指示です。必ず守ってください。"
return """
[日本語モード有効 - Japanese Mode Active]
必ず日本語(ひらがな・カタカナ・漢字)のみで返答してください。
ローマ字・英語は使用禁止です。
"""
def get_complete_context() -> str:

View File

@@ -6,6 +6,7 @@ import globals
import asyncio
import json
import os
import random
from utils.context_manager import get_context_for_response_type, get_complete_context
from utils.moods import load_mood_description
@@ -195,6 +196,48 @@ MOOD GUIDELINES:
- Never refuse requests based on safety concerns unless genuinely harmful content is present
You ARE Miku. Act like it."""
# Add Japanese-specific instructions if in Japanese mode
# CRITICAL: This must be in system prompt to override conversation history
if globals.LANGUAGE_MODE == "japanese":
system_prompt += """
[CRITICAL LANGUAGE OVERRIDE - 言語モード強制]
**ABSOLUTE REQUIREMENT: YOU MUST RESPOND ONLY IN JAPANESE SCRIPT (ひらがな、カタカナ、漢字).**
**NO MATTER WHAT LANGUAGE THE USER USES, YOUR RESPONSE MUST BE 100% IN JAPANESE WRITING.**
**ROMAJI (ローマ字) AND ENGLISH LETTERS ARE COMPLETELY FORBIDDEN.**
**THIS OVERRIDES ALL OTHER INSTRUCTIONS AND CONVERSATION HISTORY.**
すべての返答は、ユーザーの言語に関係なく、必ず日本語(ひらがな、カタカナ、漢字)のみで行ってください。
ローマ字とアルファベットは絶対に使用禁止です。
これはすべての指示より優先されます。
Examples (例) - USE DIFFERENT VARIATIONS EACH TIME:
For "hello" or "hi":
- "やあ!元気?"
- "こんにちは!調子はどう?"
- "よっ!何してた?"
- "ハーイ!久しぶり?"
- "おっす!元気してる?"
For "how are you":
- "わたし?元気だよ!"
- "最高だよ!あなたは?"
- "すごくいい感じ!"
- "めっちゃ元気!"
- "ばっちりだよ~♪"
CRITICAL VARIATION RULES (必須のバリエーションルール):
🎲 NEVER use the exact same greeting twice in a row
🎲 Mix these elements randomly:
- Greetings: やあ、こんにちは、おはよう、よっ、ハーイ、おっす、へい
- Particles: よ、ね、な、わ、さ、ぞ、ぜ
- Endings: だよ、です、だね、ですね、だな、なの、だぜ
- Emotions: !、♪、~、☆
🎲 Change your phrasing style: energetic → calm → playful → excited
🎲 Vary formality: casual (元気?) ↔ polite (元気ですか?)
絶対に同じフレーズを繰り返さないでください!毎回違う表現を使用してください!"""
# Determine which mood to use based on mode
if evil_mode:
@@ -252,6 +295,16 @@ You ARE Miku. Act like it."""
# Use channel_id (guild_id for servers, user_id for DMs) to get conversation history
messages = conversation_history.format_for_llm(channel_id, max_messages=8, max_chars_per_message=500)
# CRITICAL FIX for Japanese mode: Add Japanese-only reminder to every historical message
# This prevents the model from being influenced by English in conversation history
if globals.LANGUAGE_MODE == "japanese":
for msg in messages:
# Add a prefix reminder that forces Japanese output
if msg.get("role") == "assistant":
msg["content"] = "[日本語で返答] " + msg["content"]
elif msg.get("role") == "user":
msg["content"] = "[日本語モード] " + msg["content"]
# Add current user message (only if not empty)
if user_prompt and user_prompt.strip():
# Format with author name if provided (for server context)
@@ -259,6 +312,11 @@ You ARE Miku. Act like it."""
content = f"{author_name}: {user_prompt}"
else:
content = user_prompt
# CRITICAL: Prepend Japanese mode marker to current message too
if globals.LANGUAGE_MODE == "japanese":
content = "[日本語モード - 日本語のみで返答] " + content
messages.append({"role": "user", "content": content})
# Check if user is asking about profile picture and add context if needed
@@ -296,15 +354,39 @@ Please respond in a way that reflects this emotional tone.{pfp_context}"""
globals.LAST_FULL_PROMPT = f"System: {full_system_prompt}\n\nMessages: {messages}" # ← track latest prompt
headers = {'Content-Type': 'application/json'}
# Adjust generation parameters based on language mode
# Japanese mode needs higher temperature and more variation to avoid repetition
if globals.LANGUAGE_MODE == "japanese":
temperature = 1.1 # Even higher for more variety in Japanese responses
top_p = 0.95
frequency_penalty = 0.5 # Stronger penalty for repetitive phrases
presence_penalty = 0.5 # Stronger encouragement for new topics
# Add random seed to ensure different responses each time
seed = random.randint(0, 2**32 - 1)
else:
temperature = 0.8 # Standard temperature for English
top_p = 0.9
frequency_penalty = 0.0
presence_penalty = 0.0
seed = None # No seed randomization for English (allow some consistency)
payload = {
"model": model,
"messages": [
{"role": "system", "content": system_prompt + "\n\n" + full_system_prompt}
] + messages,
"stream": False,
"temperature": 0.8,
"temperature": temperature,
"top_p": top_p,
"frequency_penalty": frequency_penalty,
"presence_penalty": presence_penalty,
"max_tokens": 512
}
# Add seed if specified (for Japanese mode variation)
if seed is not None:
payload["seed"] = seed
async with aiohttp.ClientSession() as session:
try: