Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -89,25 +89,31 @@ def respond(message, history: list[tuple[str, str]], system_message, max_tokens,
|
|
| 89 |
# Agregar la nueva pregunta del usuario
|
| 90 |
messages.append({"role": "user", "content": message})
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
|
|
|
| 94 |
model="gpt-5-mini",
|
| 95 |
-
|
| 96 |
-
#max_tokens=max_tokens,
|
| 97 |
-
stream=True,
|
| 98 |
-
#temperature=temperature,
|
| 99 |
-
#top_p=top_p,
|
| 100 |
tools=[{"type": "web_search", "search_context_size": "high"}],
|
| 101 |
)
|
| 102 |
-
|
| 103 |
response = ""
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
| 107 |
yield response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
|
|
|
| 109 |
citations = extract_unique_citations(response)
|
| 110 |
-
response = response + "\
|
|
|
|
| 111 |
|
| 112 |
# Configuraci贸n de la interfaz Gradio
|
| 113 |
demo = gr.ChatInterface(
|
|
|
|
| 89 |
# Agregar la nueva pregunta del usuario
|
| 90 |
messages.append({"role": "user", "content": message})
|
| 91 |
|
| 92 |
+
|
| 93 |
+
# Llamar a la API con streaming usando `responses`
|
| 94 |
+
stream = client.responses.stream(
|
| 95 |
model="gpt-5-mini",
|
| 96 |
+
input=messages,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
tools=[{"type": "web_search", "search_context_size": "high"}],
|
| 98 |
)
|
| 99 |
+
|
| 100 |
response = ""
|
| 101 |
+
|
| 102 |
+
# Recibir los fragmentos del stream
|
| 103 |
+
for event in stream:
|
| 104 |
+
if event.type == "response.output_text.delta":
|
| 105 |
+
response += event.delta
|
| 106 |
yield response
|
| 107 |
+
elif event.type == "response.completed":
|
| 108 |
+
break # 馃毃 Importante: terminar cuando el modelo indique fin del stream
|
| 109 |
+
|
| 110 |
+
# Cerrar el stream correctamente
|
| 111 |
+
stream.close()
|
| 112 |
|
| 113 |
+
# Procesar el texto final
|
| 114 |
citations = extract_unique_citations(response)
|
| 115 |
+
response = response + "\nFuentes: " + citations
|
| 116 |
+
yield response
|
| 117 |
|
| 118 |
# Configuraci贸n de la interfaz Gradio
|
| 119 |
demo = gr.ChatInterface(
|