Implemented new Japanese only text mode with WebUI toggle, utilizing a llama3.1 swallow dataset model. Next up is Japanese TTS.

This commit is contained in:
2026-01-23 15:02:36 +02:00
parent eb03dfce4d
commit fe0962118b
8 changed files with 318 additions and 44 deletions

View File

@@ -3,8 +3,12 @@
Structured context management for Miku's personality and knowledge.
Replaces the vector search system with organized, complete context.
Preserves original content files in their entirety.
When LANGUAGE_MODE is "japanese", appends a Japanese instruction to ensure
all responses are in Japanese without requiring separate files.
"""
import globals
from utils.logger import get_logger
logger = get_logger('core')
@@ -40,60 +44,96 @@ def get_original_miku_lyrics() -> str:
return "## MIKU LYRICS\n[File could not be loaded]"
def _get_japanese_instruction() -> str:
"""
Returns the Japanese language instruction to append to context.
Ensures all responses are in Japanese when in Japanese mode.
"""
return "\n\n[CRITICAL INSTRUCTION - 重要な指示]\n**YOU MUST RESPOND ENTIRELY IN JAPANESE (日本語). NO ENGLISH ALLOWED.**\nすべての返答は必ず日本語で行ってください。英語での返答は一切禁止されています。\nこれは最優先の指示です。必ず守ってください。"
def get_complete_context() -> str:
"""Returns all essential Miku context using original files in their entirety"""
return f"""## MIKU LORE (Complete Original)
{get_original_miku_lore()}
"""
Returns all essential Miku context using original files in their entirety.
If LANGUAGE_MODE is "japanese", appends a Japanese instruction to ensure
all responses are in Japanese.
"""
lore = get_original_miku_lore()
prompt = get_original_miku_prompt()
lyrics = get_original_miku_lyrics()
combined = f"""## MIKU LORE (Complete Original)
{lore}
## MIKU PERSONALITY & GUIDELINES (Complete Original)
{get_original_miku_prompt()}
{prompt}
## MIKU SONG LYRICS (Complete Original)
{get_original_miku_lyrics()}"""
{lyrics}"""
# Append Japanese instruction if in Japanese mode
if globals.LANGUAGE_MODE == "japanese":
combined += _get_japanese_instruction()
logger.info(f"[core] Context loaded in {globals.LANGUAGE_MODE} mode")
return combined
def get_context_for_response_type(response_type: str) -> str:
"""Returns appropriate context based on the type of response being generated"""
"""
Returns appropriate context based on the type of response being generated.
# Core context always includes the complete original files
If LANGUAGE_MODE is "japanese", appends Japanese instruction to all contexts
to ensure responses are in Japanese.
"""
lore = get_original_miku_lore()
prompt = get_original_miku_prompt()
lyrics = get_original_miku_lyrics()
# Build core context (always in English source files)
core_context = f"""## MIKU LORE (Complete Original)
{get_original_miku_lore()}
{lore}
## MIKU PERSONALITY & GUIDELINES (Complete Original)
{get_original_miku_prompt()}"""
{prompt}"""
# Return context based on response type
if response_type == "autonomous_general":
# For general autonomous messages, include everything
return f"""{core_context}
context = f"""{core_context}
## MIKU SONG LYRICS (Complete Original)
{get_original_miku_lyrics()}"""
{lyrics}"""
elif response_type == "autonomous_tweet":
# For tweet responses, include lyrics for musical context
return f"""{core_context}
context = f"""{core_context}
## MIKU SONG LYRICS (Complete Original)
{get_original_miku_lyrics()}"""
{lyrics}"""
elif response_type == "dm_response" or response_type == "server_response":
# For conversational responses, include everything
return f"""{core_context}
context = f"""{core_context}
## MIKU SONG LYRICS (Complete Original)
{get_original_miku_lyrics()}"""
{lyrics}"""
elif response_type == "conversation_join":
# For joining conversations, include everything
return f"""{core_context}
context = f"""{core_context}
## MIKU SONG LYRICS (Complete Original)
{get_original_miku_lyrics()}"""
{lyrics}"""
elif response_type == "emoji_selection":
# For emoji reactions, no context needed - the prompt has everything
return ""
# For emoji reactions, minimal context needed
context = ""
else:
# Default: comprehensive context
return get_complete_context()
context = get_complete_context()
# Append Japanese instruction if in Japanese mode
if globals.LANGUAGE_MODE == "japanese" and context:
context += _get_japanese_instruction()
return context