DeepLearning101 commited on
Commit
e9d86b2
·
verified ·
1 Parent(s): 583bd83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -27,23 +27,23 @@ def send_chat_message(LLM_URL, LLM_API, user_input):
27
  return f"Error: {response.status_code}"
28
 
29
  # Handle the stream of events
30
- last_thought = None
31
  try:
32
  for line in response.iter_lines(decode_unicode=True):
33
  if line:
34
  try:
35
  print("Received line:", line) # Debug information
36
  data = json.loads(line.split("data: ")[1])
37
- if data.get("event") == "agent_thought":
38
- last_thought = data.get("thought")
39
  except (IndexError, json.JSONDecodeError) as e:
40
  print(f"Error parsing line: {line}, error: {e}") # Debug information
41
  continue
42
  except json.JSONDecodeError:
43
  return "Error: Invalid JSON response"
44
 
45
- if last_thought:
46
- return last_thought.strip()
47
  else:
48
  return "Error: No thought found in the response"
49
 
@@ -56,7 +56,7 @@ def handle_input(user_input):
56
  user_input = gr.Textbox(label='歡迎問我加密貨幣交易所的各種疑難雜症')
57
  examples = [
58
  ["MAX 帳號刪除關戶後,又重新註冊 MAX 後要怎辦?"],
59
- ["我要如何開通約定帳號"],
60
  ["客服專線?"],
61
  ["客服信箱?"]
62
  ]
 
27
  return f"Error: {response.status_code}"
28
 
29
  # Handle the stream of events
30
+ full_response = []
31
  try:
32
  for line in response.iter_lines(decode_unicode=True):
33
  if line:
34
  try:
35
  print("Received line:", line) # Debug information
36
  data = json.loads(line.split("data: ")[1])
37
+ if "answer" in data:
38
+ full_response.append(data["answer"])
39
  except (IndexError, json.JSONDecodeError) as e:
40
  print(f"Error parsing line: {line}, error: {e}") # Debug information
41
  continue
42
  except json.JSONDecodeError:
43
  return "Error: Invalid JSON response"
44
 
45
+ if full_response:
46
+ return ''.join(full_response).strip()
47
  else:
48
  return "Error: No thought found in the response"
49
 
 
56
  user_input = gr.Textbox(label='歡迎問我加密貨幣交易所的各種疑難雜症')
57
  examples = [
58
  ["MAX 帳號刪除關戶後,又重新註冊 MAX 後要怎辦?"],
59
+ ["開通約定帳號"],
60
  ["客服專線?"],
61
  ["客服信箱?"]
62
  ]