Skip to content

Commit

Permalink
Update: printing fix, TODO clean up flags handling for print variants
Browse files Browse the repository at this point in the history
  • Loading branch information
patham9 committed Jun 6, 2023
1 parent cce8aab commit 0347d9b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Control.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from Memory import *

def Control_cycle(RET_DICT, inp, buf, currentTime, memory, cmd, userQuestion, userGoal, PrintMemoryUpdates, PrintTruthValues, QuestionPriming, TimeHandling, ImportGPTKnowledge):
def Control_cycle(RET_DICT, inp, buf, currentTime, memory, cmd, userQuestion, userGoal, PrintAnswer, PrintMemoryUpdates, PrintTruthValues, QuestionPriming, TimeHandling, ImportGPTKnowledge):
AlreadyExecuted = set([])
for x in cmd:
if len(x) < 3:
Expand All @@ -40,7 +40,7 @@ def Control_cycle(RET_DICT, inp, buf, currentTime, memory, cmd, userQuestion, us
truth = (1.0, 0.9)
systemQuestion = x.startswith("Question(")
if userQuestion or systemQuestion:
if GetPrint():
if PrintAnswer:
print(x)
isNegated = False
if x.startswith("NegatedRelationClaim") or x.startswith("NegatedPropertyClaim"):
Expand All @@ -53,7 +53,7 @@ def Control_cycle(RET_DICT, inp, buf, currentTime, memory, cmd, userQuestion, us
if isInput and ")" in x:
sentence = x.split("(")[1].split(")")[0].replace('"','').replace("'","").replace(".", "").lower()
digested, currentTime = Memory_digest_sentence(RET_DICT, inp, currentTime, memory, sentence, truth, userGoal, PrintMemoryUpdates, TimeHandling, ImportGPTKnowledge) #currentTime updated
if digested and GetPrint():
if digested and PrintAnswer:
printsentence = sentence if isInput else x
printsentence = printsentence.replace(", ",",").replace(","," ").replace("_"," ")
if PrintTruthValues:
Expand Down
4 changes: 2 additions & 2 deletions Demo1_LearnAboutUser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
def AddInput(inp):
if not inp.endswith("?") and not inp.startswith("*") and UseLastQuestionInContext:
inp = lastquestion + " " + inp
ret = NAR.AddInput(inp, Print=False, PrintInputSentenceOverride=True, PrintInputSentenceOverrideValue=False)
ret = NAR.AddInput(inp, PrintAnswer=False, Print=False, PrintInputSentenceOverride=True, PrintInputSentenceOverrideValue=False)
if inp.endswith("?"):
print(ret["GPT_Answer"])

def RaiseQuestion():
global lastquestion
ret = NAR.AddInput(f"Raise a question about {LearnMoreAbout}, not addressed by any existing memory item?", Print=False, PrintInputSentenceOverride=True, PrintInputSentenceOverrideValue=False)
ret = NAR.AddInput(f"Raise a question about {LearnMoreAbout}, not addressed by any existing memory item?", PrintAnswer=False, Print=False, PrintInputSentenceOverride=True, PrintInputSentenceOverrideValue=False)
ret["GPT_Answer"] = ret["GPT_Answer"].split("?")[0] + "?"
print(ret["GPT_Answer"])
NAR.I_You_Exchange(ret)
Expand Down
12 changes: 6 additions & 6 deletions NarsGPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
NAR.AddInput("*currenttime=" + str(currentTime))
NAR.AddInput("*stampid=" + str(maxBaseId + 1))

def PromptProcess(RET_DICT, inp, buf, send_prompt, isQuestion, isGoal=False):
def PromptProcess(RET_DICT, inp, buf, send_prompt, isQuestion, isGoal=False, PrintAnswer=False):
if PrintGPTPrompt: print("vvvvSTART PROMPT", send_prompt, "\n^^^^END PROMPT")
while True:
try:
Expand All @@ -64,7 +64,7 @@ def PromptProcess(RET_DICT, inp, buf, send_prompt, isQuestion, isGoal=False):
time.sleep(10) #wait 10 seconds
continue
break
curTime = Control_cycle(RET_DICT, inp, buf, currentTime, memory, commands, isQuestion, isGoal, PrintMemoryUpdates, PrintTruthValues, QuestionPriming, TimeHandling, ImportGPTKnowledge)
curTime = Control_cycle(RET_DICT, inp, buf, currentTime, memory, commands, isQuestion, isGoal, PrintAnswer, PrintMemoryUpdates, PrintTruthValues, QuestionPriming, TimeHandling, ImportGPTKnowledge)
RET_DICT["GPT_Answer"] = "\n".join(commands)
return curTime

Expand All @@ -79,7 +79,7 @@ def I_You_Exchange(RET_DICT):

groundings = []
lastGoal = ""
def AddInput(inp, Print=True, PrintInputSentenceOverride=True, PrintInputSentenceOverrideValue=False):
def AddInput(inp, PrintAnswer=True, Print=True, PrintInputSentenceOverride=True, PrintInputSentenceOverrideValue=False):
global currentTime, lastGoal, memory, PrintInputSentence
SetPrint(Print)
if PrintInputSentenceOverride:
Expand Down Expand Up @@ -152,7 +152,7 @@ def AddInput(inp, Print=True, PrintInputSentenceOverride=True, PrintInputSentenc
if inp.endswith("?"):
buf, text = Memory_generate_prompt(currentTime, memory, Prompts_question_start, "\nThe question: ", relevantViewSize, recentViewSize, inp)
send_prompt = text + inp[:-1] + (Prompts_question_end_alternative if ConsiderGPTKnowledge else Prompts_question_end)
currentTime = PromptProcess(RET_DICT, inp, buf, send_prompt, True)
currentTime = PromptProcess(RET_DICT, inp, buf, send_prompt, True, PrintAnswer=PrintAnswer)
I_You_Exchange(RET_DICT)
else:
if len(inp) > 0 and not inp.isdigit():
Expand All @@ -176,7 +176,7 @@ def AddInput(inp, Print=True, PrintInputSentenceOverride=True, PrintInputSentenc
return RET_DICT
inp = bestsentence
print("//Reinterpreted as grounded goal:", inp)
currentTime = PromptProcess(RET_DICT, inp, buf, text + inp + Prompts_belief_end, False, isGoal)
currentTime = PromptProcess(RET_DICT, inp, buf, text + inp + Prompts_belief_end, False, isGoal, PrintAnswer=PrintAnswer)
else:
_, currentTime = ProcessInput(RET_DICT, currentTime, memory, "1" if len(inp) == 0 else inp)
Memory_Eternalize(currentTime, memory, eternalizationDistance)
Expand All @@ -202,7 +202,7 @@ def Shell():
inp = input().rstrip("\n").strip()
except:
exit(0)
AddInput(inp, Print=False, PrintInputSentenceOverride=True, PrintInputSentenceOverrideValue=PrintInputSentence)
AddInput(inp, PrintAnswer=True, Print=False, PrintInputSentenceOverride=True, PrintInputSentenceOverrideValue=PrintInputSentence)

if __name__ == "__main__":
Shell()

0 comments on commit 0347d9b

Please sign in to comment.