This commit is contained in:
Михаил Капелько
2024-05-09 22:33:20 +03:00
parent 5fbc03fd87
commit a574f57699
4 changed files with 56 additions and 2 deletions

View File

@@ -1,16 +1,52 @@
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 Textual UI"
c.outputGreeting = "OGS Memory Command Line Interface"
c.recentField = "outputGreeting"
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
#}
# Select item
@llm_by_value
def cli_selectItem(
c: cli_Context
) -> cli_Context:
if (
c.input.isdigit()
):
id = int(c.input)
c.cMemory = memory_selectItem(c.cMemory)
c.recentField = "cMemory"
return c
#}
c.recentField = "none"
return c
#}
# Show help (aka commands)
@llm_by_value
def cli_showHelp(
@@ -20,7 +56,7 @@ def cli_showHelp(
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"
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\n"
c.recentField = "outputHelp"
return c
#}

View File

@@ -1,5 +1,6 @@
class cli_Context:
def __init__(self):
self.cMemory = None
self.input = ""
self.outputGreeting = ""
self.outputHelp = ""

View File

@@ -19,6 +19,7 @@ print(cli_test_showHelp_help())
c = shell_createContext()
c.cCLI = cli_createContext()
c.cCLI.cMemory = memory_createContext()
c = shell_launch(c)
print(c.output)

View File

@@ -24,6 +24,7 @@ def shell_launch(
def shell_processInput(
c: shell_Context
) -> shell_Context:
# Exit
if (
c.input == "e" or
c.input == "exit" or
@@ -37,6 +38,7 @@ def shell_processInput(
c.cCLI.input = c.input
c.output = ""
# Help (aka commands)
c.cCLI = cli_showHelp(c.cCLI)
if (
c.cCLI.recentField == "outputHelp"
@@ -44,5 +46,19 @@ def shell_processInput(
c.output += c.cCLI.outputHelp
#}
c.cCLI = cli_selectItem(c.cCLI)
# Game actions.
if (
c.cCLI.recentField == "cMemory"
):
psCLI = cli_shouldPromptSelection(c.cCLI)
if (
psCLI.recentField == "outputPromptSelection"
):
c.output += psCLI.outputPromptSelection
#}
#}
return c
#}