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

@@ -4,4 +4,13 @@ system_prompt: |
{supported_languages}
Translate the user provided text from {input_lang} to {output_lang}.
Return ONLY the translated text. Do not add quotes or extra commentary.
Return ONLY the translated text. Do not add quotes or extra commentary.
history:
use_history: true
sources: [chat, mic, speaker]
max_messages: 5
max_chars: 4000
header_template: |
Conversation context (recent {max_messages} messages):
{history}
item_template: "[{timestamp}][{source}] {text}"

View File

@@ -5,3 +5,12 @@ system_prompt: |
Translate the user provided text from {input_lang} to {output_lang}.
Return ONLY the translated text. Do not add quotes or extra commentary.
history:
use_history: true
sources: [chat, mic, speaker]
max_messages: 5
max_chars: 4000
header_template: |
Conversation context (recent {max_messages} messages):
{history}
item_template: "[{timestamp}][{source}] {text}"

View File

@@ -4,4 +4,13 @@ system_prompt: |
{supported_languages}
Translate the user provided text from {input_lang} to {output_lang}.
Return ONLY the translated text. Do not add quotes or extra commentary.
Return ONLY the translated text. Do not add quotes or extra commentary.
history:
use_history: true
sources: [chat, mic, speaker]
max_messages: 5
max_chars: 4000
header_template: |
Conversation context (recent {max_messages} messages):
{history}
item_template: "[{timestamp}][{source}] {text}"

View File

@@ -4,4 +4,13 @@ system_prompt: |
{supported_languages}
Translate the user provided text from {input_lang} to {output_lang}.
Return ONLY the translated text. Do not add quotes or extra commentary.
Return ONLY the translated text. Do not add quotes or extra commentary.
history:
use_history: true
sources: [chat, mic, speaker]
max_messages: 5
max_chars: 4000
header_template: |
Conversation context (recent {max_messages} messages):
{history}
item_template: "[{timestamp}][{source}] {text}"

View File

@@ -4,4 +4,13 @@ system_prompt: |
{supported_languages}
Translate the user provided text from {input_lang} to {output_lang}.
Return ONLY the translated text. Do not add quotes or extra commentary.
Return ONLY the translated text. Do not add quotes or extra commentary.
history:
use_history: true
sources: [chat, mic, speaker] # 取り込み対象の履歴種別
max_messages: 5 # 注入する履歴件数の上限(新しい順)
max_chars: 4000 # 履歴整形後の最大文字数(超過時は先頭を切り捨て)
header_template: |
Conversation context (recent {max_messages} messages):
{history}
item_template: "[{timestamp}][{source}] {text}"

View File

@@ -5,3 +5,12 @@ system_prompt: |
Translate the user provided text from {input_lang} to {output_lang}.
Return ONLY the translated text. Do not add quotes or extra commentary.
history:
use_history: true
sources: [chat, mic, speaker]
max_messages: 5
max_chars: 4000
header_template: |
Conversation context (recent {max_messages} messages):
{history}
item_template: "[{timestamp}][{source}] {text}"

View File

@@ -4,4 +4,13 @@ system_prompt: |
{supported_languages}
Translate the following text from {input_lang} to {output_lang}.
output only the translated text without any additional commentary.
output only the translated text without any additional commentary.
history:
use_history: true
sources: [chat, mic, speaker]
max_messages: 5
max_chars: 4000
header_template: |
Conversation context (recent {max_messages} messages):
{history}
item_template: "[{timestamp}][{source}] {text}"