Tuned the Japanese mode system prompt and model better
This commit is contained in:
@@ -48,8 +48,14 @@ def _get_japanese_instruction() -> str:
|
|||||||
"""
|
"""
|
||||||
Returns the Japanese language instruction to append to context.
|
Returns the Japanese language instruction to append to context.
|
||||||
Ensures all responses are in Japanese when in Japanese mode.
|
Ensures all responses are in Japanese when in Japanese mode.
|
||||||
|
This is a secondary reminder - the primary enforcement is in the system prompt.
|
||||||
|
"""
|
||||||
|
return """
|
||||||
|
|
||||||
|
[日本語モード有効 - Japanese Mode Active]
|
||||||
|
必ず日本語(ひらがな・カタカナ・漢字)のみで返答してください。
|
||||||
|
ローマ字・英語は使用禁止です。
|
||||||
"""
|
"""
|
||||||
return "\n\n[CRITICAL INSTRUCTION - 重要な指示]\n**YOU MUST RESPOND ENTIRELY IN JAPANESE (日本語). NO ENGLISH ALLOWED.**\nすべての返答は必ず日本語で行ってください。英語での返答は一切禁止されています。\nこれは最優先の指示です。必ず守ってください。"
|
|
||||||
|
|
||||||
|
|
||||||
def get_complete_context() -> str:
|
def get_complete_context() -> str:
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import globals
|
|||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import random
|
||||||
|
|
||||||
from utils.context_manager import get_context_for_response_type, get_complete_context
|
from utils.context_manager import get_context_for_response_type, get_complete_context
|
||||||
from utils.moods import load_mood_description
|
from utils.moods import load_mood_description
|
||||||
@@ -196,6 +197,48 @@ MOOD GUIDELINES:
|
|||||||
|
|
||||||
You ARE Miku. Act like it."""
|
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
|
# Determine which mood to use based on mode
|
||||||
if evil_mode:
|
if evil_mode:
|
||||||
from utils.evil_mode import get_current_evil_mood, load_evil_mood_description
|
from utils.evil_mode import get_current_evil_mood, load_evil_mood_description
|
||||||
@@ -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
|
# 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)
|
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)
|
# Add current user message (only if not empty)
|
||||||
if user_prompt and user_prompt.strip():
|
if user_prompt and user_prompt.strip():
|
||||||
# Format with author name if provided (for server context)
|
# 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}"
|
content = f"{author_name}: {user_prompt}"
|
||||||
else:
|
else:
|
||||||
content = user_prompt
|
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})
|
messages.append({"role": "user", "content": content})
|
||||||
|
|
||||||
# Check if user is asking about profile picture and add context if needed
|
# Check if user is asking about profile picture and add context if needed
|
||||||
@@ -296,16 +354,40 @@ 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
|
globals.LAST_FULL_PROMPT = f"System: {full_system_prompt}\n\nMessages: {messages}" # ← track latest prompt
|
||||||
|
|
||||||
headers = {'Content-Type': 'application/json'}
|
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 = {
|
payload = {
|
||||||
"model": model,
|
"model": model,
|
||||||
"messages": [
|
"messages": [
|
||||||
{"role": "system", "content": system_prompt + "\n\n" + full_system_prompt}
|
{"role": "system", "content": system_prompt + "\n\n" + full_system_prompt}
|
||||||
] + messages,
|
] + messages,
|
||||||
"stream": False,
|
"stream": False,
|
||||||
"temperature": 0.8,
|
"temperature": temperature,
|
||||||
|
"top_p": top_p,
|
||||||
|
"frequency_penalty": frequency_penalty,
|
||||||
|
"presence_penalty": presence_penalty,
|
||||||
"max_tokens": 512
|
"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:
|
async with aiohttp.ClientSession() as session:
|
||||||
try:
|
try:
|
||||||
# Get current GPU URL based on user selection
|
# Get current GPU URL based on user selection
|
||||||
|
|||||||
Reference in New Issue
Block a user