Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ===== 语言配置 =====
# 界面和提示词语言,可选: zh (中文, 默认), en (English), de (Deutsch)
LANGUAGE=zh

# LLM API配置(支持 OpenAI SDK 格式的任意 LLM API)
# 推荐使用阿里百炼平台qwen-plus模型:https://bailian.console.aliyun.com/
# 注意消耗较大,可先进行小于40轮的模拟尝试
Expand Down
2 changes: 2 additions & 0 deletions backend/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ def log_response(response):

# 注册蓝图
from .api import graph_bp, simulation_bp, report_bp
from .api.config_api import config_bp
app.register_blueprint(graph_bp, url_prefix='/api/graph')
app.register_blueprint(simulation_bp, url_prefix='/api/simulation')
app.register_blueprint(report_bp, url_prefix='/api/report')
app.register_blueprint(config_bp, url_prefix='/api/config')

# 健康检查
@app.route('/health')
Expand Down
12 changes: 12 additions & 0 deletions backend/app/api/config_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from flask import Blueprint, jsonify
from app.i18n import get_all_patterns, get_language

config_bp = Blueprint('config', __name__)

@config_bp.route('/language', methods=['GET'])
def get_lang():
return jsonify({'language': get_language()})

@config_bp.route('/patterns', methods=['GET'])
def get_patterns():
return jsonify({'patterns': get_all_patterns()})
3 changes: 2 additions & 1 deletion backend/app/api/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
from ..services.simulation_runner import SimulationRunner, RunnerStatus
from ..utils.logger import get_logger
from ..models.project import ProjectManager
from ..i18n import get_prompt, get_format, get_string

logger = get_logger('mirofish.api.simulation')


# Interview prompt 优化前缀
# 添加此前缀可以避免Agent调用工具,直接用文本回复
INTERVIEW_PROMPT_PREFIX = "结合你的人设、所有的过往记忆与行动,不调用任何工具直接用文本回复我:"
INTERVIEW_PROMPT_PREFIX = get_prompt('interview_api_prefix')


def optimize_interview_prompt(prompt: str) -> str:
Expand Down
5 changes: 4 additions & 1 deletion backend/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@

class Config:
"""Flask配置类"""

# Flask配置
SECRET_KEY = os.environ.get('SECRET_KEY', 'mirofish-secret-key')
DEBUG = os.environ.get('FLASK_DEBUG', 'True').lower() == 'true'

# 语言配置 (zh=中文, en=English, de=Deutsch)
LANGUAGE = os.environ.get('LANGUAGE', 'zh')

# JSON配置 - 禁用ASCII转义,让中文直接显示(而不是 \uXXXX 格式)
JSON_AS_ASCII = False
Expand Down
45 changes: 45 additions & 0 deletions backend/app/i18n/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""
MiroFish i18n - Internationalisierung
Unterstützt mehrere Sprachen über die LANGUAGE Umgebungsvariable.
Verfügbare Sprachen: zh (Standard), en, de
"""
import os
import importlib
from typing import Dict, Any

LANGUAGE = os.getenv('LANGUAGE', 'zh')
_cache = {}

def _get_module():
if LANGUAGE not in _cache:
try:
_cache[LANGUAGE] = importlib.import_module(f'.{LANGUAGE}', package='app.i18n')
except ModuleNotFoundError:
_cache[LANGUAGE] = importlib.import_module('.zh', package='app.i18n')
return _cache[LANGUAGE]

def get_prompt(key: str) -> str:
"""Get a prompt template by key."""
return _get_module().PROMPTS[key]

def get_format(key: str) -> str:
"""Get a format string by key."""
return _get_module().FORMATS[key]

def get_string(key: str, **kwargs) -> str:
"""Get a UI/status string, optionally with format args."""
s = _get_module().STRINGS[key]
return s.format(**kwargs) if kwargs else s

def get_pattern(key: str) -> str:
"""Get a regex pattern by key (for frontend)."""
return _get_module().PATTERNS[key]

def get_all_formats() -> Dict[str, str]:
return dict(_get_module().FORMATS)

def get_all_patterns() -> Dict[str, str]:
return dict(_get_module().PATTERNS)

def get_language() -> str:
return LANGUAGE
997 changes: 997 additions & 0 deletions backend/app/i18n/de.py

Large diffs are not rendered by default.

Loading