diff --git a/pylib/word_loom.py b/pylib/word_loom.py index 04bab31..2e7ecd2 100644 --- a/pylib/word_loom.py +++ b/pylib/word_loom.py @@ -27,7 +27,7 @@ class text_item(str): def __new__(cls, value, deflang, altlangs=None, meta=None, markers=None): assert isinstance(value, str) self = super(text_item, cls).__new__(cls, value) - self.deflang = deflang # Default language + self.lang = deflang # Default language self.meta = meta or {} self.markers = markers or {} self.altlangs = altlangs or {} diff --git a/resources/wordloom/sample.toml b/resources/wordloom/sample.toml index ea00bc2..df62c3c 100644 --- a/resources/wordloom/sample.toml +++ b/resources/wordloom/sample.toml @@ -1,23 +1,23 @@ # Sample word loom file (toml format): https://github.com/OoriData/OgbujiPT/wiki/Word-Loom:-A-format-for-managing-language-for-AI-LLMs-(including-prompts) # Warning: there is a difference between single & double quotes in TOML. Former is not escaped. # Since in the root table, all prompts in this file will default to English -# Can use more precise values, such as "en_UK" +# Can use more precise values, such as "en_UK". lang = "en" [davinci3_instruct_system] -text = """ +_ = """ Obey the instruction below, based on the provided context. If you cannot obey the instruction based on the provided context, respond: "I don't have enough information to comply". """ [i18n_context] -text = """ +_ = """ Internationalization is a corporate strategy that involves making products and services as adaptable as possible, so they can easily enter different national markets. This often requires the assistance of subject matter experts. Internationalization is sometimes shortened to "i18n", where 18 represents the number of characters in the word. """ source = "https://www.lionbridge.com/blog/translation-localization/localization-globalization-internationalization-whats-the-difference/" [write_i18n_advocacy] -text = """ +_ = """ {davinci3_instruct_system} CONTEXT: {i18n_context} @@ -25,13 +25,22 @@ CONTEXT: {i18n_context} INSTRUCTION: Write a corporate memo encouraging our company to take i18n seriously """ # Declare template vars, for introspection in code. Presence of markers signals that this is a template. -markers = ["davinci3_instruct_system", "i18n_context"] +_m = ["davinci3_instruct_system", "i18n_context"] [translate_request] -text = "Comment dit-on en anglais: {hardcoded_food}?" -lang = "fr" -markers = ["hardcoded_food"] +_ = "Comment dit-on en anglais: {hardcoded_food}?" +lang = "fr" # Override default language code for this item +_m = ["hardcoded_food"] [hardcoded_food] -text = "pomme de terre" +_ = "pomme de terre" lang = "fr" + +[hello_translated] +_ = "Hello" +_fr = "Salut" + +[goodbye_translated] +_ = "Adieu" +lang = "fr" # Override default language code for this item +_en = "Goodbye" \ No newline at end of file diff --git a/test/test_word_loom.py b/test/test_word_loom.py index b349fd0..b4cb741 100644 --- a/test/test_word_loom.py +++ b/test/test_word_loom.py @@ -49,9 +49,9 @@ def test_load_fp_vs_str(SAMPLE_TOML_STR, SAMPLE_TOML_FP): def test_sample_texts_check(SAMPLE_TOML_STR): # print(SAMPLE_TOML) loom = word_loom.load(SAMPLE_TOML_STR) - assert list(sorted(loom.keys())) == ['davinci3_instruct_system', 'i18n_context', 'write_i18n_advocacy'] - assert list(sorted([v[:20] for v in loom.values()])) == ['Internationalization', 'Obey the instruction', '{davinci3_instruct_s'] - assert [v.markers or [] for v in loom.values()] == [[], [], ['davinci3_instruct_system', 'i18n_context']] + assert list(sorted(loom.keys())) == ['davinci3_instruct_system', 'hello_translated', 'i18n_context', 'write_i18n_advocacy'] + assert list(sorted([v[:20] for v in loom.values()])) == ['Hello', 'Internationalization', 'Obey the instruction', '{davinci3_instruct_s'] + assert [v.markers or [] for v in loom.values()] == [[], [], ['davinci3_instruct_system', 'i18n_context'], []] assert loom['davinci3_instruct_system'].lang == 'en' # Default language is English @@ -59,9 +59,9 @@ def test_sample_texts_check(SAMPLE_TOML_STR): assert loom1 == loom loom = word_loom.load(SAMPLE_TOML_STR, lang='fr') - assert list(sorted(loom.keys())) == ['hardcoded_food', 'translate_request'] - assert list(sorted([v[:20] for v in loom.values()])) == ['Comment dit-on en an', 'pomme de terre'] - assert [v.markers or [] for v in loom.values()] == [['hardcoded_food'], []] + assert list(sorted(loom.keys())) == ['goodbye_translated', 'hardcoded_food', 'translate_request'] + assert list(sorted([v[:20] for v in loom.values()])) == ['Adieu', 'Comment dit-on en an', 'pomme de terre'] + assert [v.markers or [] for v in loom.values()] == [['hardcoded_food'], [], []] assert loom['hardcoded_food'].lang == 'fr'