|  | @@ -85,19 +85,24 @@ Session(application)
 | 
		
	
		
			
			| 85 | 85 |  
 | 
		
	
		
			
			| 86 | 86 |  @application.route("/", methods=['GET', 'POST'])
 | 
		
	
		
			
			| 87 | 87 |  def home():
 | 
		
	
		
			
			|  | 88 | +    is_initial = False
 | 
		
	
		
			
			| 88 | 89 |      if "messages" not in session:
 | 
		
	
		
			
			| 89 | 90 |          session["messages"] = [
 | 
		
	
		
			
			| 90 | 91 |            {"role": "system", "content": make_prompt()},
 | 
		
	
		
			
			| 91 | 92 |            {"role": "assistant", "content": file2json("static/initial-chat.json")}
 | 
		
	
		
			
			| 92 | 93 |          ]
 | 
		
	
		
			
			| 93 |  | -    if "history" not in session:
 | 
		
	
		
			
			| 94 | 94 |          session["history"] = []
 | 
		
	
		
			
			| 95 |  | -    if request.method=='POST':
 | 
		
	
		
			
			| 96 |  | -        prompt = request.form["prompt"].strip()
 | 
		
	
		
			
			| 97 |  | -        if prompt:
 | 
		
	
		
			
			| 98 |  | -            session["messages"] += [{"role": "user", "content": prompt}]
 | 
		
	
		
			
			|  | 95 | +        is_initial = True
 | 
		
	
		
			
			|  | 96 | +        prompt = ""
 | 
		
	
		
			
			|  | 97 | +    if request.method=='POST' or is_initial:
 | 
		
	
		
			
			|  | 98 | +        if is_initial:
 | 
		
	
		
			
			|  | 99 | +            session["messages"] += [{"role": "system", "content": "User has hit enter. You can begin."}]
 | 
		
	
		
			
			| 99 | 100 |          else:
 | 
		
	
		
			
			| 100 |  | -            session["messages"] += [{"role": "system", "content": "User has hit enter. Please continue."}]
 | 
		
	
		
			
			|  | 101 | +            prompt = request.form["prompt"].strip()
 | 
		
	
		
			
			|  | 102 | +            if prompt:
 | 
		
	
		
			
			|  | 103 | +                session["messages"] += [{"role": "user", "content": prompt}]
 | 
		
	
		
			
			|  | 104 | +            else:
 | 
		
	
		
			
			|  | 105 | +                session["messages"] += [{"role": "system", "content": "User has hit enter. Please continue."}]
 | 
		
	
		
			
			| 101 | 106 |          payload = None
 | 
		
	
		
			
			| 102 | 107 |          while not payload:
 | 
		
	
		
			
			| 103 | 108 |              reply = openai.ChatCompletion.create(model=os.environ["MODEL_NAME"], messages=session["messages"])
 | 
		
	
	
		
			
			|  | @@ -109,7 +114,7 @@ def home():
 | 
		
	
		
			
			| 109 | 114 |                  session["history"].append(payload)
 | 
		
	
		
			
			| 110 | 115 |              except Exception as e:
 | 
		
	
		
			
			| 111 | 116 |                  print(repr(e))
 | 
		
	
		
			
			| 112 |  | -                session["messages"] += [{"role": "system", "content": "reply was ignored because it's not a valid json. user is unaware. do not apologize to them"}]
 | 
		
	
		
			
			|  | 117 | +                session["messages"] += [{"role": "system", "content": "reply was ignored because it's not a valid json or doesn't comply with the schema. user is unaware. do not apologize to them"}]
 | 
		
	
		
			
			| 113 | 118 |              print("=====")
 | 
		
	
		
			
			| 114 | 119 |              print(reply["choices"][0]["message"]["content"])
 | 
		
	
		
			
			| 115 | 120 |              print("-----")
 |