Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/aci/server/app_connectors/frontend_qa_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ async def _evaluate_and_update_database(url: str, evaluation_id: UUID) -> None:


async def _evaluate_website_with_browser_use(url: str) -> str | None:
if not config.ANTHROPIC_API_KEY:
return None

llm = ChatAnthropic(
model=config.ANTHROPIC_MODEL_FOR_FRONTEND_QA_AGENT, api_key=config.ANTHROPIC_API_KEY
)
Expand Down
16 changes: 9 additions & 7 deletions backend/aci/server/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from aci.common.utils import check_and_get_env_variable, construct_db_url

ENVIRONMENT = check_and_get_env_variable("SERVER_ENVIRONMENT")
Expand Down Expand Up @@ -42,7 +44,7 @@
# QUOTA
PROJECT_DAILY_QUOTA = int(check_and_get_env_variable("SERVER_PROJECT_DAILY_QUOTA"))
MAX_AGENTS_PER_PROJECT = int(check_and_get_env_variable("SERVER_MAX_AGENTS_PER_PROJECT"))
APPLICATION_LOAD_BALANCER_DNS = check_and_get_env_variable("SERVER_APPLICATION_LOAD_BALANCER_DNS")
APPLICATION_LOAD_BALANCER_DNS = os.getenv("SERVER_APPLICATION_LOAD_BALANCER_DNS")
OAUTH2_CLIENT_CREDENTIALS_FALLBACK_TTL_SECONDS = int(
check_and_get_env_variable("CLIENT_CREDENTIALS_FALLBACK_TTL_SECONDS")
)
Expand Down Expand Up @@ -75,12 +77,12 @@
DEV_PORTAL_URL = check_and_get_env_variable("SERVER_DEV_PORTAL_URL")

# LOGFIRE
LOGFIRE_WRITE_TOKEN = check_and_get_env_variable("SERVER_LOGFIRE_WRITE_TOKEN")
LOGFIRE_READ_TOKEN = check_and_get_env_variable("SERVER_LOGFIRE_READ_TOKEN")
LOGFIRE_WRITE_TOKEN = os.getenv("SERVER_LOGFIRE_WRITE_TOKEN")
LOGFIRE_READ_TOKEN = os.getenv("SERVER_LOGFIRE_READ_TOKEN")

# STRIPE
STRIPE_SECRET_KEY = check_and_get_env_variable("SERVER_STRIPE_SECRET_KEY")
STRIPE_WEBHOOK_SIGNING_SECRET = check_and_get_env_variable("SERVER_STRIPE_WEBHOOK_SIGNING_SECRET")
STRIPE_SECRET_KEY = os.getenv("SERVER_STRIPE_SECRET_KEY")
STRIPE_WEBHOOK_SIGNING_SECRET = os.getenv("SERVER_STRIPE_WEBHOOK_SIGNING_SECRET")

# HEADERS
ACI_ORG_ID_HEADER = "X-ACI-ORG-ID"
Expand All @@ -90,8 +92,8 @@
MAX_LOG_FIELD_SIZE = 8 * 1024

# Agentic Apps
ANTHROPIC_API_KEY = check_and_get_env_variable("SERVER_ANTHROPIC_API_KEY")
ANTHROPIC_API_KEY = os.getenv("SERVER_ANTHROPIC_API_KEY")
ANTHROPIC_MODEL_FOR_FRONTEND_QA_AGENT = "claude-3-5-sonnet-latest"

# Vector DB
VECTOR_DB_FULL_URL = check_and_get_env_variable("SERVER_VECTOR_DB_FULL_URL")
VECTOR_DB_FULL_URL = os.getenv("SERVER_VECTOR_DB_FULL_URL")
6 changes: 4 additions & 2 deletions backend/aci/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
environment=config.ENVIRONMENT,
)

stripe.api_key = config.STRIPE_SECRET_KEY
if config.STRIPE_SECRET_KEY:
stripe.api_key = config.STRIPE_SECRET_KEY


def custom_generate_unique_id(route: APIRoute) -> str:
Expand Down Expand Up @@ -130,7 +131,8 @@ def scrubbing_callback(m: logfire.ScrubMatch) -> Any:
allow_headers=["*"],
)
app.add_middleware(InterceptorMiddleware)
app.add_middleware(ProxyHeadersMiddleware, trusted_hosts=[config.APPLICATION_LOAD_BALANCER_DNS])
if config.APPLICATION_LOAD_BALANCER_DNS:
app.add_middleware(ProxyHeadersMiddleware, trusted_hosts=[config.APPLICATION_LOAD_BALANCER_DNS])


# NOTE: generic exception handler (type Exception) for all exceptions doesn't work
Expand Down
12 changes: 12 additions & 0 deletions backend/aci/server/routes/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ async def get_app_usage_distribution(
ORDER BY value DESC;
"""

if not config.LOGFIRE_READ_TOKEN:
return []

async with AsyncLogfireQueryClient(read_token=config.LOGFIRE_READ_TOKEN) as client:
json_rows = await client.query_json_rows(
sql=query, min_timestamp=datetime.now() - timedelta(days=7)
Expand All @@ -63,6 +66,9 @@ async def get_function_usage_distribution(
if not api_key_ids_sql_list:
return []

if not config.LOGFIRE_READ_TOKEN:
return []

query = f"""
SELECT
regexp_replace(url_path, '/v1/functions/([A-Z0-9_]+)/execute', '\\1') AS name,
Expand Down Expand Up @@ -92,6 +98,9 @@ async def get_app_usage_timeseries(
if not api_key_ids_sql_list:
return []

if not config.LOGFIRE_READ_TOKEN:
return []

query = f"""
SELECT
time_bucket('1d', start_timestamp)::DATE AS x,
Expand Down Expand Up @@ -137,6 +146,9 @@ async def get_function_usage_timeseries(
if not api_key_ids_sql_list:
return []

if not config.LOGFIRE_READ_TOKEN:
return []

query = f"""
SELECT
time_bucket('1d', start_timestamp)::DATE AS x,
Expand Down
3 changes: 3 additions & 0 deletions backend/aci/server/routes/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ async def handle_stripe_webhook(
db_session: Annotated[Session, Depends(deps.yield_db_session)],
stripe_signature: str = Header(None),
) -> None:
if not config.STRIPE_WEBHOOK_SIGNING_SECRET:
raise BillingError(error_code=status.HTTP_503_SERVICE_UNAVAILABLE)

payload = await request.body()
event = None

Expand Down
3 changes: 3 additions & 0 deletions backend/aci/server/routes/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ async def query(
if not q or not q.strip():
raise ACIException(title="Invalid query", message="Query cannot be empty", error_code=400)

if not config.VECTOR_DB_FULL_URL:
raise ACIException(title="Not configured", message="Vector DB is not configured", error_code=503)

try:
with utils.create_db_session(config.VECTOR_DB_FULL_URL) as db_session:
try:
Expand Down