Daniel00611 commited on
Commit
fbb2dde
verified
1 Parent(s): 7d9e88c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -12
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
- # Llamar a la API de OpenAI con streaming
93
- stream = client.chat.completions.create(
 
94
  model="gpt-5-mini",
95
- messages=messages,
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
- for chunk in stream:
105
- if chunk.choices and chunk.choices[0].delta.content:
106
- response += chunk.choices[0].delta.content
 
 
107
  yield response
 
 
 
 
 
108
 
 
109
  citations = extract_unique_citations(response)
110
- response = response + "\n Fuentes:" + citations
 
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(