Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -45,15 +45,17 @@ def process_response(response, history):
|
|
45 |
partial_words = ""
|
46 |
for chunk in response.iter_lines():
|
47 |
if chunk:
|
48 |
-
# Removendo 'data:' do in铆cio do chunk
|
49 |
chunk_str = chunk.decode('utf-8').lstrip('data: ')
|
|
|
|
|
|
|
50 |
try:
|
51 |
chunk_json = json.loads(chunk_str)
|
52 |
-
print("Chunk JSON:", chunk_json) # Log para diagn贸stico
|
53 |
if 'choices' in chunk_json and len(chunk_json['choices']) > 0:
|
54 |
chunk_data = chunk_json['choices'][0].get('delta', {})
|
55 |
if 'content' in chunk_data:
|
56 |
-
|
|
|
57 |
if token_counter == 0:
|
58 |
history.append(" " + partial_words)
|
59 |
else:
|
@@ -61,12 +63,15 @@ def process_response(response, history):
|
|
61 |
token_counter += 1
|
62 |
except json.JSONDecodeError as e:
|
63 |
print("Error decoding JSON response:", e)
|
64 |
-
print("Raw chunk:", chunk_str)
|
|
|
|
|
65 |
chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2)]
|
66 |
return chat, history, token_counter
|
67 |
|
68 |
|
69 |
|
|
|
70 |
def setup_ui():
|
71 |
with gr.Blocks() as demo:
|
72 |
with gr.Column():
|
|
|
45 |
partial_words = ""
|
46 |
for chunk in response.iter_lines():
|
47 |
if chunk:
|
|
|
48 |
chunk_str = chunk.decode('utf-8').lstrip('data: ')
|
49 |
+
# Verificar se a transmiss茫o est谩 conclu铆da
|
50 |
+
if "[DONE]" in chunk_str:
|
51 |
+
break
|
52 |
try:
|
53 |
chunk_json = json.loads(chunk_str)
|
|
|
54 |
if 'choices' in chunk_json and len(chunk_json['choices']) > 0:
|
55 |
chunk_data = chunk_json['choices'][0].get('delta', {})
|
56 |
if 'content' in chunk_data:
|
57 |
+
content = chunk_data['content']
|
58 |
+
partial_words += content
|
59 |
if token_counter == 0:
|
60 |
history.append(" " + partial_words)
|
61 |
else:
|
|
|
63 |
token_counter += 1
|
64 |
except json.JSONDecodeError as e:
|
65 |
print("Error decoding JSON response:", e)
|
66 |
+
print("Raw chunk:", chunk_str)
|
67 |
+
|
68 |
+
# Finalizar a constru莽茫o da resposta
|
69 |
chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2)]
|
70 |
return chat, history, token_counter
|
71 |
|
72 |
|
73 |
|
74 |
+
|
75 |
def setup_ui():
|
76 |
with gr.Blocks() as demo:
|
77 |
with gr.Column():
|