MaziyarPanahi
commited on
Commit
•
17b76bb
1
Parent(s):
6b22bf5
new update
Browse files
app.py
CHANGED
@@ -163,33 +163,33 @@ with gr.Blocks() as demo:
|
|
163 |
stream=True,
|
164 |
timeout=(10, 30),
|
165 |
)
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
except requests.exceptions.RequestException as e:
|
194 |
print(f"An error occurred: {e}")
|
195 |
|
|
|
163 |
stream=True,
|
164 |
timeout=(10, 30),
|
165 |
)
|
166 |
+
if response.status_code == 200:
|
167 |
+
for line in response.iter_lines():
|
168 |
+
if line:
|
169 |
+
for line in response.iter_lines():
|
170 |
+
# Filter out keep-alive new lines
|
171 |
+
if line:
|
172 |
+
data = line.decode("utf-8").lstrip("data: ")
|
173 |
+
# Check if the examples are valid
|
174 |
+
valid_check = is_valid_json(data)
|
175 |
+
if valid_check[0]:
|
176 |
+
try:
|
177 |
+
# Attempt to parse the JSON dataa
|
178 |
+
# json_data = json.loads(data)
|
179 |
+
json_data = valid_check[1]
|
180 |
+
|
181 |
+
delta_content = (
|
182 |
+
json_data.get("choices", [{}])[0]
|
183 |
+
.get("delta", {})
|
184 |
+
.get("content", "")
|
185 |
+
)
|
186 |
+
|
187 |
+
if delta_content: # Ensure there's content to print
|
188 |
+
history[-1][1] += delta_content
|
189 |
+
time.sleep(0.05)
|
190 |
+
yield history
|
191 |
+
except json.JSONDecodeError as e:
|
192 |
+
print(f"Error decoding JSON: {e} date: {data}")
|
193 |
except requests.exceptions.RequestException as e:
|
194 |
print(f"An error occurred: {e}")
|
195 |
|