Update app.py
Browse files
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 |
-
|
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
|
38 |
-
|
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
|
46 |
-
return
|
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 |
]
|