|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- from cli_Context import *
- from llm import *
- from memory import *
-
- # Greet the user
- @llm_by_value
- def cli_greetUser(
- c: cli_Context
- ) -> cli_Context:
- c.outputGreeting = "OGS Memory Command Line Interface"
- c.recentField = "outputGreeting"
- return c
- #}
-
- # Select item
- #
- # Conditions:
- # 1. Id is digit, in bounds and not hidden
- @llm_by_value
- def cli_selectItem(
- c: cli_Context
- ) -> cli_Context:
- if (
- c.input.isdigit()
- ):
- # User ids start with 1 while memory module has ids starting with 0
- # Convert cli item id to memory item id
- c.cMemory.selectedId = int(c.input) - 1
- c.cMemory = memory_selectItem(c.cMemory)
- c.recentField = "cMemory"
- return c
- #}
- c.recentField = "none"
- return c
- #}
-
- # Ask user to select another item to have a pair of selected items
- @llm_by_value
- def cli_shouldPromptSelection(
- c: cli_Context
- ) -> cli_Context:
- if (
- c.recentField == "cMemory" and
- c.cMemory.recentField == "selectedItems" and
- len(c.cMemory.selectedItems) == 1
- ):
- c.outputPromptSelection = "Select the second item now:"
- c.recentField = "outputPromptSelection"
- return c
- #}
- c.recentField = "none"
- return c
- #}
-
- # Report matched items
- @llm_by_value
- def cli_shouldReportMatchedItems(
- c: cli_Context
- ) -> cli_Context:
- if (
- c.recentField == "cMemory" and
- c.cMemory.recentField == "hiddenItems"
- ):
- c.outputMatchedItems = "Items matched! Go on:"
- c.recentField = "outputMatchedItems"
- return c
- #}
- c.recentField = "none"
- return c
- #}
-
- # Report mismatched items
- @llm_by_value
- def cli_shouldReportMismatchedItems(
- c: cli_Context
- ) -> cli_Context:
- if (
- c.recentField == "cMemory" and
- c.cMemory.recentField == "mismatchedItems"
- ):
- c.outputMatchedItems = "Wrong! Try again:"
- c.recentField = "outputMismatchedItems"
- return c
- #}
- c.recentField = "none"
- return c
- #}
-
- # Report selection of invalid item ids
- #
- # Conditions:
- # 1. Index out of bounds: less than minimum
- # 2. Index out of bounds: greater than maximum
- # 3. Item is already hidden
- #@llm_by_value
- #def cli_shouldReportInvalidItemSelection(
- # c: cli_Context
- #) -> cli_Context:
- # if (
- # c.recentField == "cMemory" and
- # c.cMemory.recentField == "selectedItems" and
- # len(c.cMemory.selectedItems) == 1
- # ):
- # c.outputPromptSelection = "Select the second item now:"
- # c.recentField = "outputPromptSelection"
- # return c
- # #}
- # c.recentField = "none"
- # return c
- ##}
-
- # Show help (aka commands)
- @llm_by_value
- def cli_showHelp(
- c: cli_Context
- ) -> cli_Context:
- if (
- c.input == "h" or
- c.input == "help"
- ):
- c.outputHelp = "Commands:\n\te, exit, q, quit\n\t\tExit\n\th, help\n\t\tList commands\n\t1, 2, 3, ...\n\t\tSelect item\nEnter your choice:"
- c.recentField = "outputHelp"
- return c
- #}
- c.recentField = "none"
- return c
- #}
|