exnav29 commited on
Commit
12f576f
·
1 Parent(s): d0ef483

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -1
app.py CHANGED
@@ -35,7 +35,10 @@ def chatbot(input):
35
  chat_history.append({"role": "user", "content": input})
36
 
37
  # Get AI response from OpenAI API
38
- prompt = f"{chat_history[-2]['content']}\nUser: {chat_history[-1]['content']}\nAI:"
 
 
 
39
  response = openai.Completion.create(
40
  engine="text-davinci-002",
41
  prompt=prompt,
@@ -61,6 +64,7 @@ def chatbot(input):
61
 
62
  return response
63
 
 
64
  # Define main function
65
  def main():
66
  if not os.path.isfile(CHAT_HISTORY_PATH):
 
35
  chat_history.append({"role": "user", "content": input})
36
 
37
  # Get AI response from OpenAI API
38
+ if len(chat_history) > 1:
39
+ prompt = f"{chat_history[-2]['content']}\nUser: {chat_history[-1]['content']}\nAI:"
40
+ else:
41
+ prompt = f"User: {chat_history[-1]['content']}\nAI:"
42
  response = openai.Completion.create(
43
  engine="text-davinci-002",
44
  prompt=prompt,
 
64
 
65
  return response
66
 
67
+
68
  # Define main function
69
  def main():
70
  if not os.path.isfile(CHAT_HISTORY_PATH):