Replies: 1 comment
-
|
Interesting, could this be added as a pre-processing step outside of semantic router? from langdetect import detect
from collections import defaultdict
# Your list of mixed language strings
mixed_lang_strings = [
"This is an English sentence.",
"這是一個中文(繁體)句子。",
"Das ist ein deutscher Satz.",
"Another English sentence.",
"又一个中文句子。",
"Noch ein deutscher Satz."
]
# Create a dictionary to hold lists of strings by language
lang_dict = defaultdict(list)
# Detect the language of each string and append to the respective list
for string in mixed_lang_strings:
try:
lang = detect(string)
if lang == "zh-cn" or lang == "zh-tw": # Combining Simplified and Traditional Chinese
lang = "zh"
lang_dict[lang].append(string)
except Exception as e:
print(f"Error detecting language for '{string}': {e}")We can then programatically create Routes: from semantic_router import Route
routes = [Route(name=lang, utterances=lang_dict[lang]) for lang in lang_dict]Would this solve your issue? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm wondering if something standardized like i18n or similar could be implemented such that a meta routing layer directs to the correct languange, and then, utterances are defined in a given languange
Beta Was this translation helpful? Give feedback.
All reactions