diff --git a/frontend/README.md b/frontend/README.md new file mode 100644 index 00000000..f0f52287 --- /dev/null +++ b/frontend/README.md @@ -0,0 +1 @@ +***Note: This frontend is a minimal frontend app to make local development easier. Do not use in production*** \ No newline at end of file diff --git a/frontend/chat.py b/frontend/chat.py index c8946e58..c44cc595 100644 --- a/frontend/chat.py +++ b/frontend/chat.py @@ -77,13 +77,14 @@ async def handle_interview(codex_client, interview_response, user_message): future_time = datetime.now(timezone.utc) + timedelta(minutes=15) future_timestamp = int(future_time.timestamp()) st.session_state.messages.append( - f"Okay starting developing app... Expected completion time: {future_timestamp}" + f"{interview_response.say_to_user}. Expected completion time: {future_timestamp}" ) st.session_state.progress = 2 elif interview_response.phase == "FEATURES": st.session_state.messages.append(interview_response.say_to_user) - interview_response = await codex_client.interview_next("") st.session_state.interview_response = interview_response + interview_response = await codex_client.interview_next("") + st.session_state.messages.append(interview_response.say_to_user) except Exception as e: logger.error(f"Failed to handle interview: {e}") st.error(f"Failed to handle interview: {e}") diff --git a/frontend/codex_client.py b/frontend/codex_client.py index eabea781..4e02aa65 100644 --- a/frontend/codex_client.py +++ b/frontend/codex_client.py @@ -11,14 +11,13 @@ SpecificationResponse, DeliverableResponse, DeploymentResponse, + UserResponse, ) logger = logging.getLogger(__name__) -# Hardcoded user data -HARDCODED_USER_ID = "7b3a9e01-4ede-4a56-919b-d7063ba3c6e3" -HARDCODED_CODEX_ID = "7b3a9e01-4ede-4a56-919b-d7063ba3c6e3" -HARDCODED_DISCORD_ID = "hardcoded_discord_id" +CLOUD_SERVICES_ID = "7b3a9e01-4ede-4a56-919b-d7063ba3c6e3" +DISCORD_ID = "6984891672811274234" class CodexClient: @@ -35,8 +34,9 @@ def __init__( auth_key (str, optional): the authorization key for the codex service. Defaults to None. """ # Set the base url for codex + self.user = None if not base_url: - self.base_url = "https://codegen-xca4qjgx4a-uc.a.run.app/api/v1" + self.base_url = "http://localhost:8080/api/v1" else: self.base_url = base_url @@ -70,14 +70,23 @@ async def init( cloud_services_user_id (str): the id of the user in the cloud services codex_user_id (str): the id of the user in the codex service """ - # Using hardcoded values - self.codex_user_id = HARDCODED_CODEX_ID - self.user_id = HARDCODED_USER_ID - self.user = { - "id": HARDCODED_USER_ID, - "codexId": HARDCODED_CODEX_ID, - "discordId": HARDCODED_DISCORD_ID, - } + async with aiohttp.ClientSession() as session: + async with session.post( + "http://localhost:8080/api/v1/user", + params={ + "cloud_services_id": CLOUD_SERVICES_ID, + "discord_id": DISCORD_ID, + }, + headers={"accept": "application/json"}, + ) as response: + if response.status == 200: + data = await response.json() + user_response = UserResponse(**data) + self.user = user_response + self.codex_user_id = self.user.id + else: + # Handle error case + raise Exception(f"Failed to fetch/create user: {response.status}") if app_id: self.app_id = app_id