ysharma HF staff commited on
Commit
8b15b39
1 Parent(s): 9e5ac4f

update check for chunk size

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -73,18 +73,19 @@ def predict(inputs, top_p, temperature, openai_api_key, chat_counter, chatbot=[]
73
  counter+=1
74
  # check whether each line is non-empty
75
  if chunk :
 
76
  # decode each line as response data is in bytes
77
- if len(json.loads(chunk.decode()[6:])['choices'][0]["delta"]) == 0:
78
- break
79
- #print(json.loads(chunk.decode()[6:])['choices'][0]["delta"]["content"])
80
- partial_words = partial_words + json.loads(chunk.decode()[6:])['choices'][0]["delta"]["content"]
81
- if token_counter == 0:
82
- history.append(" " + partial_words)
83
- else:
84
- history[-1] = partial_words
85
- chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ] # convert to tuples of list
86
- token_counter+=1
87
- yield chat, history, chat_counter # resembles {chatbot: chat, state: history}
88
 
89
 
90
  def reset_textbox():
 
73
  counter+=1
74
  # check whether each line is non-empty
75
  if chunk :
76
+ chunk = chunk.decode()
77
  # decode each line as response data is in bytes
78
+ if len(chunk) > 6 and "delta" in json.loads(chunk[6:])['choices'][0]:
79
+ #if len(json.loads(chunk.decode()[6:])['choices'][0]["delta"]) == 0:
80
+ # break
81
+ partial_words = partial_words + json.loads(chunk.decode()[6:])['choices'][0]["delta"]["content"]
82
+ if token_counter == 0:
83
+ history.append(" " + partial_words)
84
+ else:
85
+ history[-1] = partial_words
86
+ chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ] # convert to tuples of list
87
+ token_counter+=1
88
+ yield chat, history, chat_counter # resembles {chatbot: chat, state: history}
89
 
90
 
91
  def reset_textbox():