Skip to content

Commit

Permalink
Added more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Aug 14, 2021
1 parent 7e531b2 commit fda968c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
TOP_P = config_data["top-p"]


class Agent:
class Agent: # Agent class which pickle can dump to a file
def __init__(self, name, userName):
self.name = name
self.context = ""
Expand All @@ -22,12 +22,12 @@ def save(self): # Saves the agent object to a file
pickle.dump(self, file)
file.close()

def getLog(self, prompt):
def getLog(self, prompt): # Creates a string which is just the context of the agent, plus all of the conversations it has had with the user.
out = self.context + "\n" + self.conversation + "\n"
out += f'{self.userName}: {prompt}\n {self.name}: '
return out

def getResponse(self, prompt):
def getResponse(self, prompt): # Calls the api with all of the required parameters to generate a response
response = requests.post("https://api.ai21.com/studio/v1/j1-jumbo/complete",
headers={"Authorization": f"Bearer {API_KEY}"},
json={
Expand All @@ -43,7 +43,7 @@ def getResponse(self, prompt):

def generate(self, prompt, doTraining):
response = self.getResponse(prompt)
if doTraining:
if doTraining: # Not really training per se, more akin to memory (everything said in the 'training' mode will be remembered by the agent)
self.conversation += f'{self.userName}: {prompt}\n{agentName}: {response}'
self.save()
return response
Expand All @@ -56,7 +56,7 @@ def loadAgent(name): # Loads an agent object from a file
return agent


def doesFileExist(fileName):
def doesFileExist(fileName): # Simply tests if a file exists
try:
open(fileName, "r").close()
exists = True
Expand Down

0 comments on commit fda968c

Please sign in to comment.