Skip to content

Commit

Permalink
feat(gateway,agents-api): Add scalar for documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Diwank Tomer <[email protected]>
  • Loading branch information
Diwank Tomer committed Aug 28, 2024
1 parent 2bf6359 commit 617ad83
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 51 deletions.
6 changes: 4 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ TEMPORAL_POSTGRES_PASSWORD=<your_temporal_postgres_password>
LITELLM_POSTGRES_PASSWORD=<your_litellm_postgres_password>
LITELLM_MASTER_KEY=<your_litellm_master_key>
LITELLM_REDIS_PASSWORD=<your_litellm_redis_password>
SKIP_CHECK_DEVELOPER_HEADERS=true
EMBEDDING_SERVICE_BASE=http://text-embeddings-inference-<gpu|cpu> # Use the 'gpu' profile to run on GPU

# Memory Store
Expand All @@ -16,7 +15,7 @@ EMBEDDING_SERVICE_BASE=http://text-embeddings-inference-<gpu|cpu> # Use the 'gp
# COZO_HOST=http://memory-store:9070
# COZO_PORT=9070
# COZO_ROCKSDB_DIR=cozo.db
# COZO_BACKUP_DIR=backup
# COZO_BACKUP_DIR=/backup
# COZO_MNT_DIR=/data

# Gateway
Expand All @@ -28,6 +27,9 @@ EMBEDDING_SERVICE_BASE=http://text-embeddings-inference-<gpu|cpu> # Use the 'gp
# Agents API
# ---------

# AGENTS_API_MULTI_TENANT_MODE=false
# AGENTS_API_HOSTNAME=localhost
# AGENTS_API_PREFIX=""
# AGENTS_API_KEY_HEADER_NAME=Authorization
# AGENTS_API_URL=http://agents-api:8080
# TRUNCATE_EMBED_TEXT=true
Expand Down
4 changes: 2 additions & 2 deletions agents-api/agents_api/dependencies/developer_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


async def get_developer_id(
x_developer_id: Annotated[UUID | None, Header()] = None,
x_developer_id: Annotated[UUID | None, Header(include_in_schema=False)] = None,
) -> UUID:
if skip_check_developer_headers:
return x_developer_id or UUID("00000000-0000-0000-0000-000000000000")
Expand All @@ -30,7 +30,7 @@ async def get_developer_id(


async def get_developer_data(
x_developer_id: Annotated[UUID | None, Header()] = None,
x_developer_id: Annotated[UUID | None, Header(include_in_schema=False)] = None,
) -> Developer:
if skip_check_developer_headers:
x_developer_id = x_developer_id or UUID("00000000-0000-0000-0000-000000000000")
Expand Down
39 changes: 24 additions & 15 deletions agents-api/agents_api/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
# Initialize the Env object for environment variable parsing.
env: Any = Env()

# App
# ---
multi_tenant_mode: bool = env.bool("AGENTS_API_MULTI_TENANT_MODE", default=False)
hostname: str = env.str("AGENTS_API_HOSTNAME", default="localhost")
api_prefix: str = env.str("AGENTS_API_PREFIX", default="")


# Debug
# -----
Expand Down Expand Up @@ -39,7 +45,7 @@

api_key_header_name: str = env.str("AGENTS_API_KEY_HEADER_NAME", default="X-Auth-Key")
skip_check_developer_headers: bool = env.bool(
"SKIP_CHECK_DEVELOPER_HEADERS", default=False
"SKIP_CHECK_DEVELOPER_HEADERS", default=multi_tenant_mode
)


Expand All @@ -57,7 +63,7 @@
embedding_model_id: str = env.str(
"EMBEDDING_MODEL_ID", default="Alibaba-NLP/gte-large-en-v1.5"
)
truncate_embed_text: bool = env.bool("TRUNCATE_EMBED_TEXT", default=False)
truncate_embed_text: bool = env.bool("TRUNCATE_EMBED_TEXT", default=True)


# Temporal
Expand All @@ -73,14 +79,17 @@
# Consolidate environment variables
environment: Dict[str, Any] = dict(
debug=debug,
multi_tenant_mode=multi_tenant_mode,
skip_check_developer_headers=skip_check_developer_headers,
cozo_host=cozo_host,
cozo_auth=cozo_auth,
sentry_dsn=sentry_dsn,
temporal_endpoint=temporal_endpoint,
temporal_task_queue=temporal_task_queue,
api_key=api_key,
api_key_header_name=api_key_header_name,
skip_check_developer_headers=skip_check_developer_headers,
hostname=hostname,
api_prefix=api_prefix,
embedding_service_base=embedding_service_base,
truncate_embed_text=truncate_embed_text,
temporal_worker_url=temporal_worker_url,
Expand All @@ -89,15 +98,15 @@
testing=testing,
)

if debug or testing:
# Print the loaded environment variables for debugging purposes.
print("Environment variables:")
pprint(environment)
print()

# Yell if testing is enabled
print("@" * 80)
print(
f"@@@ Running in {'testing' if testing else 'debug'} mode. This should not be enabled in production. @@@"
)
print("@" * 80)
# if debug or testing:
# Print the loaded environment variables for debugging purposes.
print("Environment variables:")
pprint(environment)
print()

# Yell if testing is enabled
print("@" * 80)
print(
f"@@@ Running in {'testing' if testing else 'debug'} mode. This should not be enabled in production. @@@"
)
print("@" * 80)
25 changes: 20 additions & 5 deletions agents-api/agents_api/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from .common.exceptions import BaseCommonException
from .dependencies.auth import get_api_key
from .env import sentry_dsn
from .env import api_prefix, hostname, sentry_dsn
from .exceptions import PromptTooBigError
from .routers import (
agents,
Expand Down Expand Up @@ -84,22 +84,37 @@ def register_exceptions(app: FastAPI) -> None:
# Because some routes don't require auth
# See: https://fastapi.tiangolo.com/tutorial/bigger-applications/
#
app: Any = FastAPI(docs_url="/swagger")
app: Any = FastAPI(
docs_url="/swagger",
openapi_prefix=api_prefix,
redoc_url=None,
title="Julep Agents API",
description="API for Julep Agents",
version="0.4.0",
terms_of_service="https://www.julep.ai/terms",
contact={
"name": "Julep",
"url": "https://www.julep.ai",
"email": "[email protected]",
},
root_path=api_prefix,
)

# Create a new router for the docs
docs_router = APIRouter()
scalar_router = APIRouter()


@docs_router.get("/docs", include_in_schema=False)
@scalar_router.get("/docs", include_in_schema=False)
async def scalar_html():
return get_scalar_api_reference(
openapi_url=app.openapi_url[1:], # Remove leading '/'
title=app.title,
servers=[{"url": f"http://{hostname}{api_prefix}"}],
)


# Add the docs_router without dependencies
app.include_router(docs_router)
app.include_router(scalar_router)

# Add other routers with the get_api_key dependency
app.include_router(agents.router, dependencies=[Depends(get_api_key)])
Expand Down
23 changes: 12 additions & 11 deletions agents-api/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,25 @@ x--text-embeddings-inference: &text-embeddings-inference
# Shared environment variables
x-shared-environment: &shared-environment
AGENTS_API_KEY: ${AGENTS_API_KEY}
LITELLM_MASTER_KEY: ${LITELLM_MASTER_KEY}
COZO_AUTH_TOKEN: ${COZO_AUTH_TOKEN}
SKIP_CHECK_DEVELOPER_HEADERS: ${SKIP_CHECK_DEVELOPER_HEADERS:-True}
AGENTS_API_KEY_HEADER_NAME: ${AGENTS_API_KEY_HEADER_NAME:-Authorization}
AGENTS_API_HOSTNAME: ${AGENTS_API_HOSTNAME:-localhost}
AGENTS_API_PREFIX: ${AGENTS_API_PREFIX:-}
AGENTS_API_URL: ${AGENTS_API_URL:-http://agents-api:8080}
TRUNCATE_EMBED_TEXT: ${TRUNCATE_EMBED_TEXT:-False}
WORKER_URL: ${WORKER_URL:-temporal:7233}
COZO_AUTH_TOKEN: ${COZO_AUTH_TOKEN}
COZO_HOST: ${COZO_HOST:-http://memory-store:9070}
DEBUG: ${AGENTS_API_DEBUG:-False}
EMBEDDING_SERVICE_BASE: ${EMBEDDING_SERVICE_BASE:-http://text-embeddings-inference}
EMBEDDING_MODEL_ID: ${EMBEDDING_MODEL_ID:-Alibaba-NLP/gte-large-en-v1.5}
EMBEDDING_SERVICE_BASE: ${EMBEDDING_SERVICE_BASE:-http://text-embeddings-inference}
LITELLM_MASTER_KEY: ${LITELLM_MASTER_KEY}
LITELLM_URL: ${LITELLM_URL:-http://litellm:4000}
COZO_HOST: ${COZO_HOST:-http://memory-store:9070}
SKIP_CHECK_DEVELOPER_HEADERS: ${SKIP_CHECK_DEVELOPER_HEADERS:-True}
SUMMARIZATION_MODEL_NAME: ${SUMMARIZATION_MODEL_NAME:-gpt-4-turbo}
TEMPORAL_WORKER_URL: ${TEMPORAL_WORKER_URL:-temporal:7233}
TEMPORAL_NAMESPACE: ${TEMPORAL_NAMESPACE:-default}
TEMPORAL_ENDPOINT: ${TEMPORAL_ENDPOINT:-temporal:7233}
TEMPORAL_NAMESPACE: ${TEMPORAL_NAMESPACE:-default}
TEMPORAL_TASK_QUEUE: ${TEMPORAL_TASK_QUEUE:-julep-task-queue}
TEMPORAL_WORKER_URL: ${TEMPORAL_WORKER_URL:-temporal:7233}
TRUNCATE_EMBED_TEXT: ${TRUNCATE_EMBED_TEXT:-True}
WORKER_URL: ${WORKER_URL:-temporal:7233}

services:
agents-api:
Expand Down Expand Up @@ -121,8 +123,7 @@ services:
dockerfile: Dockerfile.migration
restart: "no" # Make sure to double quote this
environment:
- COZO_HOST=${COZO_HOST:-http://cozo:9070}
- COZO_AUTH_TOKEN=${COZO_AUTH_TOKEN:-myauthkey}
<<: *shared-environment

develop:
watch:
Expand Down
6 changes: 3 additions & 3 deletions gateway/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ services:
# - MODEL_API_URL=${MODEL_API_URL}
# - MODEL_API_KEY=${MODEL_API_KEY}
# - MODEL_API_KEY_HEADER_NAME=${MODEL_API_KEY_HEADER_NAME}
- AGENTS_API_URL=${AGENTS_API_URL}
- AGENTS_API_URL=${AGENTS_API_URL:-http://agents-api:8080}
- AGENTS_API_KEY=${AGENTS_API_KEY}
- AGENTS_API_KEY_HEADER_NAME=${AGENTS_API_KEY_HEADER_NAME}
- TRAEFIK_LOG_LEVEL=${TRAEFIK_LOG_LEVEL}
- AGENTS_API_KEY_HEADER_NAME=${AGENTS_API_KEY_HEADER_NAME:-Authorization}
- TRAEFIK_LOG_LEVEL=${TRAEFIK_LOG_LEVEL:-INFO}
container_name: gateway
depends_on:
agents-api:
Expand Down
2 changes: 1 addition & 1 deletion gateway/traefik.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ http:
agents-api-docs:
entryPoints:
- web
rule: Path(`/api/{path:docs|openapi.json}`)
rule: Path(`/api/{path:swagger|redoc|docs|scalar|openapi.json}`)
middlewares:
- agents-api-strip-prefix-api
service: service-agents-api
Expand Down
17 changes: 9 additions & 8 deletions llm-proxy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ services:
- "4000:4000"
environment:
- LITELLM_MASTER_KEY=${LITELLM_MASTER_KEY}
- LITELLM_POSTGRES_DB=${LITELLM_POSTGRES_DB}
- LITELLM_POSTGRES_USER=${LITELLM_POSTGRES_USER}
- LITELLM_POSTGRES_DB=${LITELLM_POSTGRES_DB:-litellm}
- LITELLM_POSTGRES_USER=${LITELLM_POSTGRES_USER:-llmproxy}
- LITELLM_POSTGRES_PASSWORD=${LITELLM_POSTGRES_PASSWORD}
- LITELLM_REDIS_HOST=${LITELLM_REDIS_HOST}
- LITELLM_REDIS_PORT=${LITELLM_REDIS_PORT}
- LITELLM_REDIS_HOST=${LITELLM_REDIS_HOST:-litellm-redis}
- LITELLM_REDIS_PORT=${LITELLM_REDIS_PORT:-6379}
- LITELLM_REDIS_PASSWORD=${LITELLM_REDIS_PASSWORD}
- LITELLM_DATABASE_URL=postgresql://${LITELLM_POSTGRES_USER}:${LITELLM_POSTGRES_PASSWORD}@litellm-db:5432/${LITELLM_POSTGRES_DB}
- LITELLM_DATABASE_URL=postgresql://${LITELLM_POSTGRES_USER:-llmproxy}:${LITELLM_POSTGRES_PASSWORD}@litellm-db:5432/${LITELLM_POSTGRES_DB:-litellm}
- OPENAI_API_KEY=${OPENAI_API_KEY}
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
- GROQ_API_KEY=${GROQ_API_KEY}
Expand Down Expand Up @@ -49,11 +49,12 @@ services:
ports:
- "15432:5432"
environment:
- POSTGRES_DB=${LITELLM_POSTGRES_DB}
- POSTGRES_USER=${LITELLM_POSTGRES_USER}
- POSTGRES_DB=${LITELLM_POSTGRES_DB:-litellm}
- POSTGRES_USER=${LITELLM_POSTGRES_USER:-llmproxy}
- POSTGRES_PASSWORD=${LITELLM_POSTGRES_PASSWORD}
healthcheck:
test: [ "CMD-SHELL", "pg_isready -d ${LITELLM_POSTGRES_DB} -U ${LITELLM_POSTGRES_USER}" ]
test: [ "CMD-SHELL", "pg_isready -d ${LITELLM_POSTGRES_DB:-litellm} -U ${LITELLM_POSTGRES_USER:-llmproxy}" ]

interval: 1s
timeout: 5s
retries: 10
Expand Down
9 changes: 5 additions & 4 deletions scheduler/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
- DB=postgres12
- DB_PORT=5432
- DB_HOST=temporal-db
- POSTGRES_USER=${TEMPORAL_POSTGRES_USER}
- POSTGRES_USER=${TEMPORAL_POSTGRES_USER:-temporal}
- POSTGRES_PWD=${TEMPORAL_POSTGRES_PASSWORD}
- POSTGRES_SEEDS=temporal-db
- DYNAMIC_CONFIG_FILE_PATH=config/dynamicconfig/development-sql.yaml
Expand All @@ -31,15 +31,16 @@ services:
temporal-db:
image: postgres:16
environment:
- POSTGRES_DB=${TEMPORAL_POSTGRES_DB}
- POSTGRES_USER=${TEMPORAL_POSTGRES_USER}
- POSTGRES_DB=${TEMPORAL_POSTGRES_DB:-temporal}
- POSTGRES_USER=${TEMPORAL_POSTGRES_USER:-temporal}
- POSTGRES_PASSWORD=${TEMPORAL_POSTGRES_PASSWORD}
ports:
- 25432:5432
volumes:
- temporal-db-data:/var/lib/postgresql/data
healthcheck:
test: [ "CMD-SHELL", "pg_isready -d ${TEMPORAL_POSTGRES_DB} -U ${TEMPORAL_POSTGRES_USER}" ]
test: [ "CMD-SHELL", "pg_isready -d ${TEMPORAL_POSTGRES_DB:-temporal} -U ${TEMPORAL_POSTGRES_USER:-temporal}" ]

interval: 1s
timeout: 5s
retries: 10
Expand Down

0 comments on commit 617ad83

Please sign in to comment.