Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
aarushik93 committed Jun 10, 2024
1 parent 8a0d2ab commit 3583877
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 48 deletions.
42 changes: 20 additions & 22 deletions frontend/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
st.set_page_config(layout="wide")

if not st.session_state.process_complete:

st.title("AutoGPT Coding Ability")

# Input fields
Expand All @@ -46,19 +45,17 @@
if "messages" not in st.session_state:
st.session_state.messages = []


async def init_codex_client(user_id, codex_id, client_url):
codex_client = CodexClient(base_url=client_url)
await codex_client.init(cloud_services_user_id=user_id, codex_user_id=codex_id)
st.session_state.codex_client = codex_client


async def create_app_and_start_interview(codex_client):
try:
app = await codex_client.create_app(app_name=project_name, description=task)
st.session_state.app_id = app.id
logger.info(f"Application Created: {app.id}")
st.session_state.messages.append(f"App creation started! Let's gooo")
st.session_state.messages.append("App creation started! Let's gooo")

interview = await codex_client.start_interview(name=project_name, task=task)
st.session_state.interview_id = interview.id
Expand All @@ -69,7 +66,6 @@ async def create_app_and_start_interview(codex_client):
logger.error(f"Failed to create app: {e}")
st.error(f"Failed to create app: {e}")


async def handle_interview(codex_client, interview_response, user_message):
try:
interview_response = await codex_client.interview_next(user_message)
Expand All @@ -81,7 +77,8 @@ 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"Okay starting developing app... 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)
Expand All @@ -91,41 +88,38 @@ async def handle_interview(codex_client, interview_response, user_message):
logger.error(f"Failed to handle interview: {e}")
st.error(f"Failed to handle interview: {e}")


async def generate_spec(codex_client):
try:
spec_response = await codex_client.generate_spec()
st.session_state.spec_id = spec_response.id
logger.info(f"Spec Generated: {spec_response.id}")
st.session_state.messages.append(f"Specification Generated!")
st.session_state.messages.append("Specification Generated!")
st.session_state.progress = 3
st.experimental_rerun()
return spec_response
except Exception as e:
logger.error(f"Failed to generate spec: {e}")
st.error(f"Failed to generate spec: {e}")


async def generate_deliverable(codex_client):
try:
deliverable_response = await codex_client.generate_deliverable()
st.session_state.deliverable_id = deliverable_response.id
logger.info(f"Deliverable Generated: {deliverable_response.id}")
st.session_state.messages.append(f"Deliverable Generated!")
st.session_state.messages.append("Deliverable Generated!")
st.session_state.progress = 4
st.experimental_rerun()
return deliverable_response
except Exception as e:
logger.error(f"Failed to generate deliverable: {e}")
st.error(f"Failed to generate deliverable: {e}")


async def create_deployment(codex_client):
try:
deployment_response = await codex_client.create_deployment()
st.session_state.deployment_id = deployment_response.id
logger.info(f"Deployment Generated: {deployment_response.id}")
st.session_state.messages.append(f"Deployment Created!")
st.session_state.messages.append("Deployment Created!")
st.session_state.messages.append(f"GitHub Repo: {deployment_response.repo}")
st.session_state.progress = 5
st.session_state.github_repo = deployment_response.repo
Expand All @@ -136,7 +130,6 @@ async def create_deployment(codex_client):
logger.error(f"Failed to create deployment: {e}")
st.error(f"Failed to create deployment: {e}")


async def main():
if st.session_state.codex_client is None:
await init_codex_client(user_id, codex_id, client_url)
Expand All @@ -145,9 +138,14 @@ async def main():
await create_app_and_start_interview(st.session_state.codex_client)

if st.session_state.progress == 1 and st.session_state.user_message:
await handle_interview(st.session_state.codex_client, st.session_state.interview_response,
st.session_state.user_message)
st.session_state.user_message = "" # Reset the user message after handling it
await handle_interview(
st.session_state.codex_client,
st.session_state.interview_response,
st.session_state.user_message,
)
st.session_state.user_message = (
"" # Reset the user message after handling it
)

if st.session_state.progress == 2:
st.write("Generating Specification...")
Expand All @@ -161,11 +159,6 @@ async def main():
st.write("Creating Deployment...")
await create_deployment(st.session_state.codex_client)

if st.session_state.progress == 5:
st.write("Loading GitHub Repo...")
await load_github_repo()


if st.button("Start Building"):
asyncio.run(main())

Expand All @@ -178,7 +171,12 @@ async def main():
if st.button("Submit Response"):
st.session_state.user_message = user_message
asyncio.run(
handle_interview(st.session_state.codex_client, st.session_state.interview_response, user_message))
handle_interview(
st.session_state.codex_client,
st.session_state.interview_response,
user_message,
)
)
st.experimental_rerun()

if st.session_state.progress in [2, 3, 4, 5]:
Expand Down
47 changes: 22 additions & 25 deletions frontend/codex_client.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
from typing import Tuple

import logging
import aiohttp
from pydantic import ValidationError

from codex_model import *
from typing import Optional
from codex_model import (
ApplicationResponse,
ApplicationCreate,
InterviewResponse,
InterviewNextRequest,
SpecificationResponse,
DeliverableResponse,
DeploymentResponse,
)

logger = logging.getLogger(__name__)

Expand All @@ -12,6 +20,7 @@
HARDCODED_CODEX_ID = "7b3a9e01-4ede-4a56-919b-d7063ba3c6e3"
HARDCODED_DISCORD_ID = "hardcoded_discord_id"


class CodexClient:
def __init__(
self,
Expand Down Expand Up @@ -177,9 +186,7 @@ async def start_interview(
logger.exception(f"Error parsing interview: {e}")
raise e
except Exception as e:
logger.exception(
f"Unknown Error when trying to start the interview: {e}"
)
logger.exception(f"Unknown Error when trying to start the interview: {e}")
raise e

async def interview_next(self, user_message: str) -> InterviewResponse:
Expand Down Expand Up @@ -274,9 +281,7 @@ async def generate_deliverable(self) -> DeliverableResponse:
url, headers=self.headers, timeout=3000
) as response:
response.raise_for_status()
deliverable_response = DeliverableResponse(
**await response.json()
)
deliverable_response = DeliverableResponse(**await response.json())
self.deliverable_id = deliverable_response.id
return deliverable_response

Expand Down Expand Up @@ -310,14 +315,10 @@ async def create_deployment(self) -> DeploymentResponse:
async with aiohttp.ClientSession() as session:
async with session.post(url, headers=self.headers) as response:
if response.status != 200:
logger.error(
f"Error creating deployment: {response.status}"
)
logger.error(f"Error creating deployment: {response.status}")
logger.error(await response.text())
response.raise_for_status()
deployment_response = DeploymentResponse(
**await response.json()
)
deployment_response = DeploymentResponse(**await response.json())
self.deployment_id = deployment_response.id
return deployment_response
except aiohttp.ClientError as e:
Expand All @@ -327,9 +328,7 @@ async def create_deployment(self) -> DeploymentResponse:
logger.exception(f"Error parsing app deployment: {e}")
raise e
except Exception as e:
logger.exception(
f"Unknown Error when trying to create the deployment: {e}"
)
logger.exception(f"Unknown Error when trying to create the deployment: {e}")
raise e

async def download_zip(self) -> Tuple[bytes, str]:
Expand All @@ -342,18 +341,16 @@ async def download_zip(self) -> Tuple[bytes, str]:
Tuple[bytes, str]: The bytes of the zip file and the name of the file.
"""
if not self.deployment_id:
raise ValueError(
"You must create a deployment before downloading a zip"
)
raise ValueError("You must create a deployment before downloading a zip")
url = f"{self.base_url}/deployments/{self.deployment_id}/download"
try:
async with aiohttp.ClientSession() as session:
async with session.get(url, headers=self.headers) as response:
response.raise_for_status()
content = await response.read()
filename = response.headers.get(
"Content-Disposition", ""
).split("filename=")[1]
filename = response.headers.get("Content-Disposition", "").split(
"filename="
)[1]
return content, filename
except aiohttp.ClientError as e:
logger.exception(f"HTTP error occurred: {e}")
Expand Down Expand Up @@ -412,4 +409,4 @@ async def build_codex_client(
codex.deliverable_id = deliverable_id
codex.deployment_id = deployment_id

return codex
return codex
2 changes: 1 addition & 1 deletion frontend/codex_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import datetime
from typing import List, Optional

from pydantic import BaseModel, ConfigDict, EmailStr, Field
from pydantic import BaseModel, Field

logger = logging.getLogger(__name__)

Expand Down

0 comments on commit 3583877

Please sign in to comment.