Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -58,19 +58,19 @@ def generate_search(query: str, stream: bool = True) -> str:
|
|
58 |
# Collect streamed text content
|
59 |
streaming_text = ""
|
60 |
for value in response.iter_lines(decode_unicode=True):
|
61 |
-
# Ensure the value
|
62 |
-
if value.startswith("data: "):
|
63 |
try:
|
64 |
json_modified_value = json.loads(value[6:]) # Remove 'data: ' prefix
|
65 |
content = json_modified_value.get("choices", [{}])[0].get("delta", {}).get("content", "")
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
except json.JSONDecodeError:
|
71 |
continue # Skip lines that are not valid JSON
|
72 |
|
73 |
-
# If not streaming, yield the full
|
74 |
if not stream:
|
75 |
yield streaming_text
|
76 |
|
|
|
58 |
# Collect streamed text content
|
59 |
streaming_text = ""
|
60 |
for value in response.iter_lines(decode_unicode=True):
|
61 |
+
# Ensure the value starts with 'data: ' and process it
|
62 |
+
if value.startswith("data: "):
|
63 |
try:
|
64 |
json_modified_value = json.loads(value[6:]) # Remove 'data: ' prefix
|
65 |
content = json_modified_value.get("choices", [{}])[0].get("delta", {}).get("content", "")
|
66 |
+
# Include everything, even if it's just whitespace
|
67 |
+
if stream:
|
68 |
+
yield f"data: {json.dumps({'response': content})}\n\n"
|
69 |
+
streaming_text += content
|
70 |
except json.JSONDecodeError:
|
71 |
continue # Skip lines that are not valid JSON
|
72 |
|
73 |
+
# If not streaming, yield the full collected content
|
74 |
if not stream:
|
75 |
yield streaming_text
|
76 |
|