feat: Implement translation prompt history injection for Chat/Mic/Speaker

- Added a history management system in model.py to store and retrieve recent messages from Chat, Mic, and Speaker.
- Updated controller.py to automatically add messages to the translation history after processing.
- Enhanced translation clients (OpenAI, Gemini, Groq, etc.) to accept and utilize context history for improved translation quality.
- Introduced YAML configuration options for enabling history injection and customizing its behavior across different translation models.
- Ensured that only original messages are stored in history to optimize token usage during translation.
This commit is contained in:
misyaguziya
2025-12-15 01:15:47 +09:00
parent 9e88cff889
commit dac903e07c
18 changed files with 734 additions and 7 deletions

View File

@@ -292,6 +292,8 @@ class Controller:
"data": None
},
)
else:
pass
except Exception as e:
# VRAM不足エラーの検出
is_vram_error, error_message = model.detectVRAMError(e)
@@ -412,6 +414,8 @@ class Controller:
translation_text = f" ({'/'.join(translation)})" if translation else ""
model.logger.info(f"[SENT] {message}{translation_text}")
model.addTranslationHistory("mic", message)
def speakerMessage(self, result:dict) -> None:
message = result["text"]
language = result["language"]
@@ -452,6 +456,8 @@ class Controller:
"data": None
},
)
else:
pass
except Exception as e:
# VRAM不足エラーの検出
is_vram_error, error_message = model.detectVRAMError(e)
@@ -594,6 +600,8 @@ class Controller:
translation_text = f" ({'/'.join(translation)})" if translation else ""
model.logger.info(f"[RECEIVED] {message}{translation_text}")
model.addTranslationHistory("speaker", message)
def chatMessage(self, data) -> dict:
id = data["id"]
message = data["message"]
@@ -625,6 +633,8 @@ class Controller:
"data": None
},
)
else:
pass
except Exception as e:
# VRAM不足エラーの検出
is_vram_error, error_message = model.detectVRAMError(e)
@@ -744,6 +754,8 @@ class Controller:
translation_text = f" ({'/'.join(translation)})" if translation else ""
model.logger.info(f"[CHAT] {message}{translation_text}")
model.addTranslationHistory("chat", message)
return {
"status":200,
"result":{