Skip to content

Commit f76005f

Browse files
committed
working on session state
1 parent 5b1d29e commit f76005f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Backend/app.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from fastapi import FastAPI
55
from fastapi.middleware.cors import CORSMiddleware
66

7+
import uuid
8+
79
from api_models.ai_request import AIRequest
810
from cosmic_works.cosmic_works_ai_agent import CosmicWorksAIAgent
911

@@ -38,6 +40,16 @@ def run_cosmic_works_ai_agent(request: AIRequest):
3840
"""
3941
Run the Cosmic Works AI agent.
4042
"""
41-
if request.session_id not in agent_pool:
42-
agent_pool[request.session_id] = CosmicWorksAIAgent(request.session_id)
43-
return { "message": agent_pool[request.session_id].run(request.prompt) }
43+
prompt = request.prompt
44+
session_id = request.session_id
45+
46+
# If no session_id is provided or default is provided, generate a new one.
47+
if (session_id is None or session_id == "1234"):
48+
session_id = str(uuid.uuid4())
49+
50+
# If the session_id is not in the agent pool, create a new agent.
51+
if session_id not in agent_pool:
52+
agent_pool[session_id] = CosmicWorksAIAgent(session_id)
53+
54+
# Run the agent with the provided prompt.
55+
return { "message": agent_pool[session_id].run(prompt), "session_id": session_id }

0 commit comments

Comments
 (0)