yuntian-deng commited on
Commit
bca8716
1 Parent(s): 60e8ed8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -27,7 +27,7 @@ def predict(inputs, top_p, temperature, chat_counter, chatbot=[], history=[]):
27
  "Authorization": f"Bearer {OPENAI_API_KEY}"
28
  }
29
 
30
- print(f"chat_counter - {chat_counter}")
31
  if chat_counter != 0 :
32
  messages=[]
33
  for data in chatbot:
@@ -58,13 +58,14 @@ def predict(inputs, top_p, temperature, chat_counter, chatbot=[], history=[]):
58
  chat_counter+=1
59
 
60
  history.append(inputs)
61
- #print(f"payload is - {payload}")
62
  # make a POST request to the API endpoint using the requests.post method, passing in stream=True
63
  response = requests.post(API_URL, headers=headers, json=payload, stream=True)
64
- print(f"response code - {response}")
 
 
65
  token_counter = 0
66
  partial_words = ""
67
-
68
  counter=0
69
  for chunk in response.iter_lines():
70
  #Skipping first chunk
@@ -87,7 +88,7 @@ def predict(inputs, top_p, temperature, chat_counter, chatbot=[], history=[]):
87
  chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ] # convert to tuples of list
88
  token_counter+=1
89
  yield chat, history, chat_counter, response # resembles {chatbot: chat, state: history}
90
- print(json.dumps({"payload": payload, "partial_words": partial_words}))
91
 
92
 
93
  def reset_textbox():
 
27
  "Authorization": f"Bearer {OPENAI_API_KEY}"
28
  }
29
 
30
+ # print(f"chat_counter - {chat_counter}")
31
  if chat_counter != 0 :
32
  messages=[]
33
  for data in chatbot:
 
58
  chat_counter+=1
59
 
60
  history.append(inputs)
61
+ # print(f"payload is - {payload}")
62
  # make a POST request to the API endpoint using the requests.post method, passing in stream=True
63
  response = requests.post(API_URL, headers=headers, json=payload, stream=True)
64
+ response_code = f"{response}"
65
+ if response_code.strip() != "<Response [200]>":
66
+ print(f"response code - {response}")
67
  token_counter = 0
68
  partial_words = ""
 
69
  counter=0
70
  for chunk in response.iter_lines():
71
  #Skipping first chunk
 
88
  chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ] # convert to tuples of list
89
  token_counter+=1
90
  yield chat, history, chat_counter, response # resembles {chatbot: chat, state: history}
91
+ print(json.dumps({"chat_counter": chat_counter, "payload": payload, "partial_words": partial_words, "token_counter": token_counter, "counter": counter}))
92
 
93
 
94
  def reset_textbox():