Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
import os
|
3 |
from dotenv import load_dotenv
|
4 |
from fastapi import FastAPI, HTTPException, Request
|
@@ -59,17 +58,15 @@ def generate_search(query: str, stream: bool = True) -> str:
|
|
59 |
# Collect streamed text content
|
60 |
streaming_text = ""
|
61 |
for value in response.iter_lines(decode_unicode=True, chunk_size=12):
|
62 |
-
|
|
|
63 |
try:
|
64 |
-
|
65 |
-
content =
|
66 |
-
|
67 |
-
# Stream the raw content directly (no 'data:' prefix)
|
68 |
if stream:
|
69 |
-
yield content
|
70 |
-
|
71 |
streaming_text += content
|
72 |
-
except
|
73 |
continue
|
74 |
|
75 |
if not stream:
|
|
|
|
|
1 |
import os
|
2 |
from dotenv import load_dotenv
|
3 |
from fastapi import FastAPI, HTTPException, Request
|
|
|
58 |
# Collect streamed text content
|
59 |
streaming_text = ""
|
60 |
for value in response.iter_lines(decode_unicode=True, chunk_size=12):
|
61 |
+
modified_value = re.sub("data:", "", value)
|
62 |
+
if modified_value:
|
63 |
try:
|
64 |
+
json_modified_value = json.loads(modified_value)
|
65 |
+
content = json_modified_value["choices"][0]["delta"]["content"]
|
|
|
|
|
66 |
if stream:
|
67 |
+
yield f"data: {content}\n\n"
|
|
|
68 |
streaming_text += content
|
69 |
+
except:
|
70 |
continue
|
71 |
|
72 |
if not stream:
|