cotxetj commited on
Commit
4166423
1 Parent(s): 65c21fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -138,7 +138,7 @@ def gpt_predict(inputs, request:gr.Request=gr.State([]), top_p = 1, temperature
138
  #if response_code.strip() != "<Response [200]>":
139
  # #print(f"response code - {response}")
140
  # raise Exception(f"Sorry, hitting rate limit. Please try again later. {response}")
141
-
142
  for chunk in response.iter_lines():
143
  #Skipping first chunk
144
  if counter == 0:
@@ -152,15 +152,17 @@ def gpt_predict(inputs, request:gr.Request=gr.State([]), top_p = 1, temperature
152
  if len(chunk) > 12 and "content" in json.loads(chunk[6:])['choices'][0]['delta']:
153
  partial_words = partial_words + json.loads(chunk[6:])['choices'][0]["delta"]["content"]
154
  print(partial_words)
 
155
  if token_counter == 0:
156
  history.append(" " + partial_words)
157
  else:
158
  history[-1] = partial_words
159
  token_counter += 1
160
- return [(parse_codeblock(history[i]), parse_codeblock(history[i + 1])) for i in range(0, len(history) - 1, 2) ], history, chat_counter, response, gr.update(interactive=False), gr.update(interactive=False) # resembles {chatbot: chat, state: history}
161
  except Exception as e:
162
  print (f'error found: {e}')
163
  print(json.dumps({"chat_counter": chat_counter, "payload": payload, "partial_words": partial_words, "token_counter": token_counter, "counter": counter}))
 
164
  return [(parse_codeblock(history[i]), parse_codeblock(history[i + 1])) for i in range(0, len(history) - 1, 2) ], history, chat_counter, response, gr.update(interactive=True), gr.update(interactive=True)
165
 
166
 
 
138
  #if response_code.strip() != "<Response [200]>":
139
  # #print(f"response code - {response}")
140
  # raise Exception(f"Sorry, hitting rate limit. Please try again later. {response}")
141
+ out = []
142
  for chunk in response.iter_lines():
143
  #Skipping first chunk
144
  if counter == 0:
 
152
  if len(chunk) > 12 and "content" in json.loads(chunk[6:])['choices'][0]['delta']:
153
  partial_words = partial_words + json.loads(chunk[6:])['choices'][0]["delta"]["content"]
154
  print(partial_words)
155
+ print(response)
156
  if token_counter == 0:
157
  history.append(" " + partial_words)
158
  else:
159
  history[-1] = partial_words
160
  token_counter += 1
161
+ out.append([(parse_codeblock(history[i]), parse_codeblock(history[i + 1])) for i in range(0, len(history) - 1, 2) ], history, chat_counter, response, gr.update(interactive=False), gr.update(interactive=False) # resembles {chatbot: chat, state: history}
162
  except Exception as e:
163
  print (f'error found: {e}')
164
  print(json.dumps({"chat_counter": chat_counter, "payload": payload, "partial_words": partial_words, "token_counter": token_counter, "counter": counter}))
165
+ return response["choices"]["message"]["content"]
166
  return [(parse_codeblock(history[i]), parse_codeblock(history[i + 1])) for i in range(0, len(history) - 1, 2) ], history, chat_counter, response, gr.update(interactive=True), gr.update(interactive=True)
167
 
168