Skip to content

Commit

Permalink
Merge pull request #31 from Significant-Gravitas/swiftyos/agpt-280
Browse files Browse the repository at this point in the history
Various fixes, pushed to the wrong branch...
  • Loading branch information
Swiftyos authored Feb 15, 2024
2 parents 8f4b98c + d059610 commit 14fb3c5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
1 change: 0 additions & 1 deletion codex/api_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ def from_specification(specification):
apiRoutes=routes,
)

print("success")
return ret_obj


Expand Down
27 changes: 17 additions & 10 deletions codex/deploy/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import black
import isort
from prisma.fields import Base64
from prisma.models import CompiledRoute as CompiledRouteDBModel
from prisma.models import CompletedApp, Deployment
from prisma.types import DeploymentCreateInput
Expand All @@ -25,15 +24,23 @@ async def create_deployment(
zip_file = create_zip_file(app)
file_name = completedApp.name.replace(" ", "_")

deployment = await Deployment.prisma().create(
data=DeploymentCreateInput(
completedApp={"connect": {"id": completedApp.id}},
User={"connect": {"id": ids.user_id}},
fileName=f"{file_name}.zip",
fileSize=len(zip_file),
fileBytes=Base64(zip_file),
try:
base64.b64encode(zip_file)
logger.info(f"Creating deployment for {completedApp.name}")
encoded_file_bytes = base64.b64encode(zip_file).decode("utf-8")
deployment = await Deployment.prisma().create(
data=DeploymentCreateInput(
completedApp={"connect": {"id": completedApp.id}},
User={"connect": {"id": ids.user_id}},
fileName=f"{file_name}.zip",
fileSize=len(zip_file),
# I need to do this as the Base64 type in prisma is not working
fileBytes=encoded_file_bytes, # type: ignore
)
)
)
except Exception as e:
logger.exception("Error creating deployment in database")
raise ValueError(f"Error creating deployment in database: {e}")
return deployment


Expand Down Expand Up @@ -111,7 +118,7 @@ def create_server_code(application: Application) -> Application:
logger.info(f"Creating route for {route_path}")
# import the main function from the service file
compiled_route_module = compiled_route.service_file_name.replace(".py", "")
service_import = "from project.{compiled_route_module} import *"
service_import = f"from project.{compiled_route_module} import *"
server_code_imports.append(service_import)

# Write the api endpoint
Expand Down
4 changes: 3 additions & 1 deletion codex/deploy/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def create_zip_file(application: Application) -> bytes:
)
with open(service_file_path, "w") as service_file:
service_file.write(compiled_route.service_code)

logger.info("Created server code")
# Create a zip file of the directory
zip_file_path = os.path.join(app_dir, "server.zip")
with zipfile.ZipFile(zip_file_path, "w") as zipf:
Expand All @@ -83,8 +83,10 @@ def create_zip_file(application: Application) -> bytes:
if file == "server.zip":
continue
file_path = os.path.join(root, file)
print(file_path)
zipf.write(file_path, os.path.relpath(file_path, temp_dir))

logger.info("Created zip file")
# Read and return the bytes of the zip file
with open(zip_file_path, "rb") as zipf:
zip_bytes = zipf.read()
Expand Down
6 changes: 4 additions & 2 deletions codex/deploy/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async def create_deployment(
spec_id=spec_id,
completed_app_id=deliverable_id,
)

deployment = await deploy_agent.create_deployment(ids, completedApp)

return DeploymentResponse(
Expand Down Expand Up @@ -175,14 +176,15 @@ async def download_deployment(deployment_id: int):
"""
Download the zip file for a specific deployment.
"""
# Retrieve deployment details, assuming this returns an object that includes the file bytes
# Retrieve deployment details, assuming this
# returns an object that includes the file bytes
deployment_details = await codex.deploy.database.get_deployment(
deployment_id=deployment_id
)
if not deployment_details:
raise HTTPException(status_code=404, detail="Deployment not found")

logger.info(f"Downloading deployment: {deployment_details}")
logger.info(f"Downloading deployment: {deployment_id}")

# Decode the base64-encoded file bytes
try:
Expand Down

0 comments on commit 14fb3c5

Please sign in to comment.