yizhangliu commited on
Commit
6d441fa
β€’
1 Parent(s): d5be88e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -360,6 +360,7 @@ def set_openai_api_key(api_key):
360
  openai.api_key = api_key
361
 
362
  def get_response_from_openai(input, chat_history, model_radio):
 
363
  def openai_create(input_list, model_radio):
364
  try:
365
  # print(f'input_list={input_list}')
@@ -370,6 +371,9 @@ def get_response_from_openai(input, chat_history, model_radio):
370
  out_prompt = 'AI:'
371
  for i in range(input_list_len):
372
  input = input_list[input_list_len-i-1].replace("<br>", '\n\n')
 
 
 
373
  if input.startswith("☝:"):
374
  if model_radio == 'GPT-3.0':
375
  out_prompt = input.replace("☝:", "AI:") + '\n' + out_prompt
@@ -418,18 +422,16 @@ def get_response_from_openai(input, chat_history, model_radio):
418
  ret = ret.replace("\n\n", '')
419
  ret = ret.replace('\n', '<br>')
420
  if ret == '':
421
- ret = f"Openai said: I'm too tired(1)."
422
  return ret, response.usage
423
  except Exception as e:
424
  logger.info(f"openai_create_error__{e}")
425
- ret = f"Openai said: I'm too tired(2)."
426
  return ret, {"completion_tokens": -1, "prompt_tokens": -1, "total_tokens": -1}
427
 
428
  print(f'chat_history = {chat_history}')
429
  chat_history_list = []
430
  chat_history = chat_history.replace("<p>", "").replace("</p>", "")
431
- chat_history = chat_history.replace("Openai said: I'm too tired(1).", "")
432
- chat_history = chat_history.replace("Openai said: I'm too tired(2).", "")
433
  if chat_history != '':
434
  chat_history_list = json.loads(chat_history)
435
  chat_history_list.append(f'☟:{input}')
 
360
  openai.api_key = api_key
361
 
362
  def get_response_from_openai(input, chat_history, model_radio):
363
+ error_1 = 'You exceeded your current quota, please check your plan and billing details.'
364
  def openai_create(input_list, model_radio):
365
  try:
366
  # print(f'input_list={input_list}')
 
371
  out_prompt = 'AI:'
372
  for i in range(input_list_len):
373
  input = input_list[input_list_len-i-1].replace("<br>", '\n\n')
374
+ if input.startswith("Openai said:"):
375
+ input = "☝:"
376
+
377
  if input.startswith("☝:"):
378
  if model_radio == 'GPT-3.0':
379
  out_prompt = input.replace("☝:", "AI:") + '\n' + out_prompt
 
422
  ret = ret.replace("\n\n", '')
423
  ret = ret.replace('\n', '<br>')
424
  if ret == '':
425
+ ret = f"Openai said: I'm too tired."
426
  return ret, response.usage
427
  except Exception as e:
428
  logger.info(f"openai_create_error__{e}")
429
+ ret = f"Openai said: {e} Perhaps enter your OpenAI API key."
430
  return ret, {"completion_tokens": -1, "prompt_tokens": -1, "total_tokens": -1}
431
 
432
  print(f'chat_history = {chat_history}')
433
  chat_history_list = []
434
  chat_history = chat_history.replace("<p>", "").replace("</p>", "")
 
 
435
  if chat_history != '':
436
  chat_history_list = json.loads(chat_history)
437
  chat_history_list.append(f'☟:{input}')