- Introducing translation service prompts
- Ensure Traicie Role Definition Specialist complies to latest technical requirements - Ensure that empty historical messages do not cause a crash in eveai_client - take into account empty customisation options - make was not processed in the system dynamic attribute tenant_make - ensure only relevant makes are shown when creating magic links - refresh partner info when editing or adding Partner Services$
This commit is contained in:
21
common/utils/translation_utils.py
Normal file
21
common/utils/translation_utils.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import xxhash
|
||||
import json
|
||||
|
||||
from common.utils.model_utils import get_template, replace_variable_in_template
|
||||
|
||||
|
||||
def generate_cache_key(text: str, target_lang: str, source_lang: str = None, context: str = None) -> str:
|
||||
cache_data = {
|
||||
"text": text.strip(),
|
||||
"target_lang": target_lang.lower(),
|
||||
"source_lang": source_lang.lower() if source_lang else None,
|
||||
"context": context.strip() if context else ""
|
||||
}
|
||||
|
||||
cache_string = json.dumps(cache_data, sort_keys=True, ensure_ascii=False)
|
||||
return xxhash.xxh64(cache_string.encode('utf-8')).hexdigest()
|
||||
|
||||
def translate_text(text: str, target_lang: str, source_lang: str = None, context: str = None) -> str:
|
||||
if context:
|
||||
prompt_text = get_template("translation_with_context")
|
||||
prompt_text = replace_variable_in_template(prompt_text, "context", context)
|
||||
Reference in New Issue
Block a user