DeepLearning101 commited on
Commit
efe5287
·
verified ·
1 Parent(s): 2eff9bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -32,16 +32,19 @@ async def send_chat_message(LLM_URL, LLM_API, user_input):
32
  # Handle the stream of events
33
  full_response = []
34
  async for line in response.content:
35
- line = line.decode('utf-8')
36
- if line:
37
- try:
38
- print("Received line:", line) # Debug information
39
- data = json.loads(line.split("data: ")[1])
40
- if "answer" in data:
41
- full_response.append(data["answer"])
42
- except (IndexError, json.JSONDecodeError) as e:
43
- print(f"Error parsing line: {line}, error: {e}") # Debug information
44
- continue
 
 
 
45
 
46
  if full_response:
47
  return ''.join(full_response).strip()
 
32
  # Handle the stream of events
33
  full_response = []
34
  async for line in response.content:
35
+ line = line.decode('utf-8').strip()
36
+ if not line:
37
+ continue
38
+ if "data: " not in line:
39
+ continue
40
+ try:
41
+ print("Received line:", line) # Debug information
42
+ data = json.loads(line.split("data: ")[1])
43
+ if "answer" in data:
44
+ full_response.append(data["answer"])
45
+ except (IndexError, json.JSONDecodeError) as e:
46
+ print(f"Error parsing line: {line}, error: {e}") # Debug information
47
+ continue
48
 
49
  if full_response:
50
  return ''.join(full_response).strip()