Skip to content

Commit

Permalink
Merge pull request #911 from Agenta-AI/899/remove-demo-ff-from-codebase
Browse files Browse the repository at this point in the history
Refactor - remove 'demo' ff from codebase
  • Loading branch information
mmabrouk authored Nov 17, 2023
2 parents b1c7629 + e356875 commit 094eaa4
Show file tree
Hide file tree
Showing 18 changed files with 26 additions and 38 deletions.
2 changes: 1 addition & 1 deletion agenta-backend/agenta_backend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os

if os.environ["FEATURE_FLAG"] in ["cloud", "ee", "demo"]:
if os.environ["FEATURE_FLAG"] in ["cloud", "ee"]:
import agenta_backend.cloud.__init__
4 changes: 2 additions & 2 deletions agenta-backend/agenta_backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ async def lifespan(application: FastAPI, cache=True):
allow_headers=allow_headers,
)

if os.environ["FEATURE_FLAG"] not in ["cloud", "ee", "demo"]:
if os.environ["FEATURE_FLAG"] not in ["cloud", "ee"]:
from agenta_backend.services.auth_helper import authentication_middleware

app.middleware("http")(authentication_middleware)

if os.environ["FEATURE_FLAG"] in ["cloud", "ee", "demo"]:
if os.environ["FEATURE_FLAG"] in ["cloud", "ee"]:
import agenta_backend.cloud.main as cloud

app, allow_headers = cloud.extend_main(app)
Expand Down
21 changes: 6 additions & 15 deletions agenta-backend/agenta_backend/routers/app_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
)
from agenta_backend.models import converters

if os.environ["FEATURE_FLAG"] in ["cloud", "ee", "demo"]:
if os.environ["FEATURE_FLAG"] in ["cloud", "ee"]:
from agenta_backend.cloud.services.selectors import (
get_user_and_org_id,
) # noqa pylint: disable-all
Expand Down Expand Up @@ -326,23 +326,14 @@ async def create_app_and_variant_from_template(
logger.debug("Step 1: Getting user and organization ID")
user_org_data: dict = await get_user_and_org_id(request.state.user_id)

# Check if the user has reached app limit
logger.debug("Step 2: Checking user app limit")
if os.environ["FEATURE_FLAG"] == "demo":
if await db_manager.count_apps(**user_org_data) > 2:
raise HTTPException(
status_code=500,
detail="Sorry, you can only create two Apps at this time.",
)

logger.debug("Step 3: Setting organization ID")
logger.debug("Step 2: Setting organization ID")
if payload.organization_id is None:
organization = await get_user_own_org(user_org_data["uid"])
organization_id = organization.id
else:
organization_id = payload.organization_id

logger.debug(f"Step 4: Checking if app {payload.app_name} already exists")
logger.debug(f"Step 3 Checking if app {payload.app_name} already exists")
app_name = payload.app_name.lower()
app = await db_manager.fetch_app_by_name_and_organization(
app_name, organization_id, **user_org_data
Expand All @@ -353,13 +344,13 @@ async def create_app_and_variant_from_template(
detail=f"App with name {app_name} already exists",
)

logger.debug("Step 5: Creating new app and initializing environments")
logger.debug("Step 4: Creating new app and initializing environments")
if app is None:
app = await db_manager.create_app_and_envs(
app_name, organization_id, **user_org_data
)

logger.debug("Step 5 (extra): Retrieve template from db")
logger.debug("Step 5: Retrieve template from db")
template_db = await db_manager.get_template(payload.template_id)
repo_name = os.environ.get("AGENTA_TEMPLATE_REPO", "agentaai/lambda_templates")
image_name = f"{repo_name}:{template_db.name}"
Expand Down Expand Up @@ -392,7 +383,7 @@ async def create_app_and_variant_from_template(
)

logger.debug("Step 8: Starting variant and injecting environment variables")
if os.environ["FEATURE_FLAG"] in ["cloud", "ee", "demo"]:
if os.environ["FEATURE_FLAG"] in ["cloud", "ee"]:
if not os.environ["OPENAI_API_KEY"]:
raise HTTPException(
status_code=400,
Expand Down
2 changes: 1 addition & 1 deletion agenta-backend/agenta_backend/routers/bases_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from agenta_backend.services import db_manager
from agenta_backend.models import converters

if os.environ["FEATURE_FLAG"] in ["cloud", "ee", "demo"]:
if os.environ["FEATURE_FLAG"] in ["cloud", "ee"]:
from agenta_backend.cloud.services.selectors import (
get_user_and_org_id,
) # noqa pylint: disable-all
Expand Down
2 changes: 1 addition & 1 deletion agenta-backend/agenta_backend/routers/configs_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
app_manager,
)

if os.environ["FEATURE_FLAG"] in ["cloud", "ee", "demo"]:
if os.environ["FEATURE_FLAG"] in ["cloud", "ee"]:
from agenta_backend.cloud.services.selectors import (
get_user_and_org_id,
) # noqa pylint: disable-all
Expand Down
2 changes: 1 addition & 1 deletion agenta-backend/agenta_backend/routers/container_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from fastapi import APIRouter, Request, UploadFile, HTTPException
from fastapi.responses import JSONResponse

if os.environ["FEATURE_FLAG"] in ["cloud", "ee", "demo"]:
if os.environ["FEATURE_FLAG"] in ["cloud", "ee"]:
from agenta_backend.cloud.services.selectors import (
get_user_and_org_id,
) # noqa pylint: disable-all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
DeployToEnvironmentPayload,
)

if os.environ["FEATURE_FLAG"] in ["cloud", "ee", "demo"]:
if os.environ["FEATURE_FLAG"] in ["cloud", "ee"]:
from agenta_backend.cloud.services.selectors import (
get_user_and_org_id,
) # noqa pylint: disable-all
Expand Down
2 changes: 1 addition & 1 deletion agenta-backend/agenta_backend/routers/evaluation_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from agenta_backend.models import converters
from agenta_backend.services import results_service

if os.environ["FEATURE_FLAG"] in ["cloud", "ee", "demo"]:
if os.environ["FEATURE_FLAG"] in ["cloud", "ee"]:
from agenta_backend.cloud.services.selectors import ( # noqa pylint: disable-all
get_user_and_org_id,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
UpdateTrace,
)

if os.environ["FEATURE_FLAG"] in ["cloud", "ee", "demo"]:
if os.environ["FEATURE_FLAG"] in ["cloud", "ee"]:
from agenta_backend.cloud.services.selectors import (
get_user_and_org_id,
) # noqa pylint: disable-all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from agenta_backend.services import db_manager

if os.environ["FEATURE_FLAG"] in ["cloud", "ee", "demo"]:
if os.environ["FEATURE_FLAG"] in ["cloud", "ee"]:
from agenta_backend.cloud.services.selectors import (
get_user_and_org_id,
) # noqa pylint: disable-all
Expand Down
2 changes: 1 addition & 1 deletion agenta-backend/agenta_backend/routers/testset_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
router = APIRouter()


if os.environ["FEATURE_FLAG"] in ["cloud", "ee", "demo"]:
if os.environ["FEATURE_FLAG"] in ["cloud", "ee"]:
from agenta_backend.cloud.services.selectors import (
get_user_and_org_id,
) # noqa pylint: disable-all
Expand Down
2 changes: 1 addition & 1 deletion agenta-backend/agenta_backend/routers/user_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

router = APIRouter()

if os.environ["FEATURE_FLAG"] in ["cloud", "ee", "demo"]:
if os.environ["FEATURE_FLAG"] in ["cloud", "ee"]:
from agenta_backend.cloud.services.selectors import (
get_user_and_org_id,
) # noqa pylint: disable-all
Expand Down
4 changes: 2 additions & 2 deletions agenta-backend/agenta_backend/routers/variants_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
VariantActionEnum,
)

if os.environ["FEATURE_FLAG"] in ["cloud", "ee", "demo"]:
if os.environ["FEATURE_FLAG"] in ["cloud", "ee"]:
from agenta_backend.cloud.services.selectors import (
get_user_and_org_id,
) # noqa pylint: disable-all
Expand Down Expand Up @@ -247,7 +247,7 @@ async def start_variant(
user_org_data: dict = await get_user_and_org_id(request.state.user_id)

# Inject env vars to docker container
if os.environ["FEATURE_FLAG"] in ["cloud", "ee", "demo"]:
if os.environ["FEATURE_FLAG"] in ["cloud", "ee"]:
if not os.environ["OPENAI_API_KEY"]:
raise HTTPException(
status_code=400,
Expand Down
4 changes: 2 additions & 2 deletions agenta-backend/agenta_backend/services/app_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
else:
from agenta_backend.services import deployment_manager

if os.environ["FEATURE_FLAG"] in ["cloud", "ee", "demo"]:
if os.environ["FEATURE_FLAG"] in ["cloud", "ee"]:
from agenta_backend.cloud.services import (
api_key_service,
) # noqa pylint: disable-all
Expand Down Expand Up @@ -77,7 +77,7 @@ async def start_variant(
env_vars.update(
{"AGENTA_BASE_ID": str(db_app_variant.base.id), "AGENTA_HOST": domain_name}
)
if os.environ["FEATURE_FLAG"] in ["cloud", "ee", "demo"]:
if os.environ["FEATURE_FLAG"] in ["cloud", "ee"]:
api_key = await api_key_service.create_api_key(
str(db_app_variant.user.uid), expiration_date=None, hidden=True
)
Expand Down
2 changes: 1 addition & 1 deletion agenta-backend/agenta_backend/services/db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ async def get_user(user_uid: str) -> UserDB:

user = await engine.find_one(UserDB, UserDB.uid == user_uid)
if user is None:
if os.environ["FEATURE_FLAG"] not in ["cloud", "ee", "demo"]:
if os.environ["FEATURE_FLAG"] not in ["cloud", "ee"]:
create_user = UserDB(uid="0")
await engine.save(create_user)

Expand Down
5 changes: 1 addition & 4 deletions agenta-backend/agenta_backend/services/deployment_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ async def remove_image(image: Image):
None
"""
try:
if (
os.environ["FEATURE_FLAG"] not in ["cloud", "ee", "demo"]
and image.deletable
):
if os.environ["FEATURE_FLAG"] not in ["cloud", "ee"] and image.deletable:
docker_utils.delete_image(image.docker_id)
logger.info(f"Image {image.docker_id} deleted")
except RuntimeError as e:
Expand Down
2 changes: 1 addition & 1 deletion agenta-web/cypress/support/commands/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Cypress.Commands.add("clickLinkAndWait", (selector) => {

export const isDemo = () => {
if (Cypress.env["NEXT_PUBLIC_FF"]) {
return ["demo", "cloud", "ee"].includes(Cypress.env["NEXT_PUBLIC_FF"])
return ["cloud", "ee"].includes(Cypress.env["NEXT_PUBLIC_FF"])
}
return false
}
2 changes: 1 addition & 1 deletion agenta-web/src/lib/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const getInitials = (str: string, limit = 2) => {

export const isDemo = () => {
if (process.env.NEXT_PUBLIC_FF) {
return ["demo", "cloud", "ee"].includes(process.env.NEXT_PUBLIC_FF)
return ["cloud", "ee"].includes(process.env.NEXT_PUBLIC_FF)
}
return false
}
Expand Down

0 comments on commit 094eaa4

Please sign in to comment.