Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -135,33 +135,36 @@ def respond(message, history: list[tuple[str, str]], domain_table):
|
|
| 135 |
# Agregar la nueva pregunta del usuario
|
| 136 |
messages.append({"role": "user", "content": message})
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
with client.responses.stream(
|
| 141 |
model="gpt-5-mini",
|
| 142 |
input=messages,
|
| 143 |
-
tools=[
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
"allowed_domains": domain_table
|
| 147 |
-
},
|
| 148 |
-
}],
|
| 149 |
-
) as stream: # ✅ el bloque with maneja correctamente el flujo
|
| 150 |
-
|
| 151 |
response = ""
|
| 152 |
-
|
| 153 |
-
for event in stream: # ✅ ahora sí es iterable dentro del context manager
|
| 154 |
if event.type == "response.output_text.delta":
|
| 155 |
response += event.delta
|
| 156 |
yield response
|
| 157 |
elif event.type == "response.completed":
|
| 158 |
response_stream = stream.get_final_response()
|
| 159 |
citations = extract_unique_citations_paragraph(response_stream)
|
| 160 |
-
response += "\n\n
|
| 161 |
yield response
|
| 162 |
break
|
| 163 |
-
|
| 164 |
-
|
| 165 |
|
| 166 |
|
| 167 |
def add_domain(domains, new_domain):
|
|
|
|
| 135 |
# Agregar la nueva pregunta del usuario
|
| 136 |
messages.append({"role": "user", "content": message})
|
| 137 |
|
| 138 |
+
# --- Construir dinámicamente la tool ---
|
| 139 |
+
web_search_tool = {
|
| 140 |
+
"type": "web_search",
|
| 141 |
+
"search_context_size": "high",
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
if allowed_domains: # 👈 Solo agregar si hay dominios
|
| 145 |
+
web_search_tool["filters"] = {"allowed_domains": allowed_domains}
|
| 146 |
+
|
| 147 |
+
# --- Configurar include dinámico ---
|
| 148 |
+
include_params = ["web_search_call.action.sources"] if allowed_domains else []
|
| 149 |
+
|
| 150 |
+
# --- Llamada a la API con streaming ---
|
| 151 |
with client.responses.stream(
|
| 152 |
model="gpt-5-mini",
|
| 153 |
input=messages,
|
| 154 |
+
tools=[web_search_tool],
|
| 155 |
+
include=include_params, # 👈 también condicional
|
| 156 |
+
) as stream:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
response = ""
|
| 158 |
+
for event in stream:
|
|
|
|
| 159 |
if event.type == "response.output_text.delta":
|
| 160 |
response += event.delta
|
| 161 |
yield response
|
| 162 |
elif event.type == "response.completed":
|
| 163 |
response_stream = stream.get_final_response()
|
| 164 |
citations = extract_unique_citations_paragraph(response_stream)
|
| 165 |
+
response += "\n\nFuentes:\n" + citations
|
| 166 |
yield response
|
| 167 |
break
|
|
|
|
|
|
|
| 168 |
|
| 169 |
|
| 170 |
def add_domain(domains, new_domain):
|