Skip to content

Commit

Permalink
[#77] Settle test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
uogbuji committed May 1, 2024
1 parent 529dc76 commit f84996b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pylib/word_loom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
27 changes: 18 additions & 9 deletions resources/wordloom/sample.toml
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
# 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}
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"
12 changes: 6 additions & 6 deletions test/test_word_loom.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ 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
loom1 = word_loom.load(SAMPLE_TOML_STR, lang='en')
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'


Expand Down

0 comments on commit f84996b

Please sign in to comment.