xiaofeifei commited on
Commit
49470f9
1 Parent(s): fcaf14a

add chat history

Browse files

Signed-off-by: vax521 <13263397018@163.com>

Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -16,13 +16,20 @@ def ask_gpt(prompt):
16
  print(response)
17
  return response.choices[0].message.content.strip()
18
 
 
 
 
 
 
 
 
19
 
20
  async def predict(input, history):
21
  """
22
  Predict the response of the chatbot and complete a running list of chat history.
23
  """
24
  history.append({"role": "user", "content": input})
25
- response = ask_gpt(history)
26
  history.append({"role": "assistant", "content": response})
27
  messages = [(history[i]["content"], history[i + 1]["content"]) for i in range(0, len(history) - 1, 2)]
28
  return messages, history
 
16
  print(response)
17
  return response.choices[0].message.content.strip()
18
 
19
+ def ask_gpt_with_history(history):
20
+ response = openai.ChatCompletion.create(
21
+ model="gpt-3.5-turbo", # here we use `gpt-3.5-turbo` model, while Stanford-Alpaca uses `text-davinci-003`
22
+ messages=history
23
+ )
24
+ print(response)
25
+ return response.choices[0].message.content.strip()
26
 
27
  async def predict(input, history):
28
  """
29
  Predict the response of the chatbot and complete a running list of chat history.
30
  """
31
  history.append({"role": "user", "content": input})
32
+ response = ask_gpt_with_history(history)
33
  history.append({"role": "assistant", "content": response})
34
  messages = [(history[i]["content"], history[i + 1]["content"]) for i in range(0, len(history) - 1, 2)]
35
  return messages, history