Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -148,12 +148,12 @@ root_agent = LlmAgent(
|
|
148 |
session_service = InMemorySessionService()
|
149 |
|
150 |
# Esta funci贸n se conecta a ChatInterface
|
151 |
-
def
|
152 |
-
|
153 |
-
|
|
|
154 |
user_id = str(uuid.uuid4())
|
155 |
session_id = str(uuid.uuid4())
|
156 |
-
state = {"user_id": user_id, "session_id": session_id}
|
157 |
print(f"馃攧 Nueva sesi贸n: {session_id}")
|
158 |
|
159 |
async def create_session():
|
@@ -163,9 +163,16 @@ def wrapped_respond(message, history, state=None):
|
|
163 |
session_id=session_id
|
164 |
)
|
165 |
asyncio.run(create_session())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
|
167 |
-
user_id = state["user_id"]
|
168 |
-
session_id = state["session_id"]
|
169 |
runner = Runner(agent=root_agent, app_name=APP_NAME, session_service=session_service)
|
170 |
|
171 |
def call_agent_text(query):
|
@@ -217,6 +224,6 @@ def wrapped_respond(message, history, state=None):
|
|
217 |
return "Escribe algo para que pueda contestarte."
|
218 |
|
219 |
# Inicializamos demo sin el argumento state
|
220 |
-
demo = gr.ChatInterface(fn=
|
221 |
|
222 |
demo.launch(debug=True)
|
|
|
148 |
session_service = InMemorySessionService()
|
149 |
|
150 |
# Esta funci贸n se conecta a ChatInterface
|
151 |
+
def respond(message, history):
|
152 |
+
# Detectar si es inicio de conversaci贸n (history vac铆o o con 0 mensajes)
|
153 |
+
print("HISTORY",history)
|
154 |
+
if history is None or len(history) == 0:
|
155 |
user_id = str(uuid.uuid4())
|
156 |
session_id = str(uuid.uuid4())
|
|
|
157 |
print(f"馃攧 Nueva sesi贸n: {session_id}")
|
158 |
|
159 |
async def create_session():
|
|
|
163 |
session_id=session_id
|
164 |
)
|
165 |
asyncio.run(create_session())
|
166 |
+
# Guardar en alg煤n lado user_id y session_id para usar en las pr贸ximas llamadas
|
167 |
+
# Por simplicidad ac谩 lo guardamos en variables globales
|
168 |
+
global CURRENT_USER_ID, CURRENT_SESSION_ID
|
169 |
+
CURRENT_USER_ID = user_id
|
170 |
+
CURRENT_SESSION_ID = session_id
|
171 |
+
else:
|
172 |
+
# Usar IDs existentes
|
173 |
+
user_id = CURRENT_USER_ID
|
174 |
+
session_id = CURRENT_SESSION_ID
|
175 |
|
|
|
|
|
176 |
runner = Runner(agent=root_agent, app_name=APP_NAME, session_service=session_service)
|
177 |
|
178 |
def call_agent_text(query):
|
|
|
224 |
return "Escribe algo para que pueda contestarte."
|
225 |
|
226 |
# Inicializamos demo sin el argumento state
|
227 |
+
demo = gr.ChatInterface(fn=respond, title="Agente Revisor", multimodal=True)
|
228 |
|
229 |
demo.launch(debug=True)
|