ysharma HF staff commited on
Commit
8a41c7d
1 Parent(s): 4bf24a9

restore to previous version

Browse files
Files changed (1) hide show
  1. app.py +13 -17
app.py CHANGED
@@ -67,29 +67,25 @@ def predict(inputs, top_p, temperature, openai_api_key, chat_counter, chatbot=[]
67
 
68
  counter=0
69
  for chunk in response.iter_lines():
70
- print(f"chunk.decode() is ^^ - {chunk.decode()}")
71
  if counter == 0:
72
  counter+=1
73
  continue
74
  counter+=1
75
  # check whether each line is non-empty
76
  if chunk :
77
- chunk_str = chunk.decode()[6:]
78
- if chunk_str:
79
- delta = json.loads(chunk_str)['choices'][0]["delta"]
80
- if len(delta) == 0:
81
- break
82
- # decode each line as response data is in bytes
83
- partial_words = partial_words + json.loads(chunk.decode()[6:])['choices'][0]["delta"]["content"]
84
- if token_counter == 0:
85
- history.append(" " + partial_words)
86
- else:
87
- history[-1] = partial_words
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 # resembles {chatbot: chat, state: history}
91
-
92
-
93
 
94
  def reset_textbox():
95
  return gr.update(value='')
 
67
 
68
  counter=0
69
  for chunk in response.iter_lines():
 
70
  if counter == 0:
71
  counter+=1
72
  continue
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():
91
  return gr.update(value='')