Skip to content
Draft
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
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,18 @@ For a complete production setup with custom images:
```shell
# 1a. Generate the Production 1 image
python3 ./scripts/docker-composer.py --prod \
-f docker/compose/docker-compose.nilai-prod-1.yml \
--image 'nillion/nilai-api:latest=public.ecr.aws/k5d9x2g2/nilai-api:v0.2.0-alpha2' \
--image 'nillion/nilai-vllm:latest=public.ecr.aws/k5d9x2g2/nilai-vllm:v0.2.0-alpha2' \
--image 'nillion/nilai-attestation:latest=public.ecr.aws/k5d9x2g2/nilai-attestation:v0.2.0-alpha2' \
--testnet \
-f docker/compose/docker-compose.nilai-prod-2.yml \
--image 'nillion/nilai-api:latest=public.ecr.aws/k5d9x2g2/nilai-api:v0.2.0-rc0' \
--image 'nillion/nilai-attestation:latest=public.ecr.aws/k5d9x2g2/nilai-attestation:v0.2.0-rc0' \
--image 'nillion/nilai-vllm:latest=public.ecr.aws/k5d9x2g2/nilai-vllm:v0.2.0-rc0' \
-o production-compose.yml

# 1b. Generate the Production 2 image
python3 ./scripts/docker-composer.py --prod \
-f docker/compose/docker-compose.nilai-prod-2.yml \
--image 'nillion/nilai-api:latest=public.ecr.aws/k5d9x2g2/nilai-api:v0.2.0-alpha2' \
--image 'nillion/nilai-vllm:latest=public.ecr.aws/k5d9x2g2/nilai-vllm:v0.2.0-alpha2' \
--image 'nillion/nilai-attestation:latest=public.ecr.aws/k5d9x2g2/nilai-attestation:v0.2.0-alpha2' \
-f docker/compose/docker-compose.nilai-prod-1.yml \
--image 'nillion/nilai-api:latest=public.ecr.aws/k5d9x2g2/nilai-api:v0.2.0-rc0' \
--image 'nillion/nilai-attestation:latest=public.ecr.aws/k5d9x2g2/nilai-attestation:v0.2.0-rc0' \
--testnet \
-o production-compose.yml


Expand Down
2 changes: 1 addition & 1 deletion docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
env_file:
- .env.mainnet
environment:
- POSTGRES_DB=nuc-nilai-mainnet2
- POSTGRES_DB=${POSTGRES_DB_NUC}
volumes:
- ${FILES}/nilai-api/config.yaml:/app/nilai-api/src/nilai_api/config/config.yaml
caddy:
Expand Down
1 change: 0 additions & 1 deletion docker-compose.testnet.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ services:
- .env.testnet
environment:
- AUTH_STRATEGY=nuc
- POSTGRES_DB=${POSTGRES_DB_TESTNET}
volumes:
- ${FILES}/testnet/nilai-api/config.yaml:/app/nilai-api/src/nilai_api/config/config.yaml
grafana:
Expand Down
2 changes: 1 addition & 1 deletion docker/compose/docker-compose.nilai-prod-1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
memlock: -1
stack: 67108864
env_file:
- .env
- .env.mainnet
restart: unless-stopped
depends_on:
etcd:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"query_logs", sa.Column("web_search_calls", sa.Integer(), nullable=False)
"query_logs",
sa.Column(
"web_search_calls",
sa.Integer(),
server_default=sa.text("0"),
nullable=False,
),
)
op.add_column("users", sa.Column("rate_limits", sa.JSON(), nullable=True))
op.drop_column("users", "web_search_ratelimit_minute")
Expand Down
16 changes: 7 additions & 9 deletions nilai-api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ authors = [
]
requires-python = ">=3.12"
dependencies = [
"accelerate>=1.1.1",
"alembic>=1.14.1",
"cryptography>=43.0.1",
"fastapi[standard]>=0.115.5",
"gunicorn>=23.0.0",
"nilai-common",
Expand All @@ -22,20 +20,22 @@ dependencies = [
"httpx>=0.27.2",
"nilrag>=0.1.11",
"openai>=1.59.9",
"pg8000>=1.31.2",
"prometheus_fastapi_instrumentator>=7.0.2",
"asyncpg>=0.30.0",
"greenlet>=3.1.1",
"redis>=5.2.1",
"authlib>=1.4.1",
"verifier",
"redis>=6.4.0",
"web3>=7.8.0",
"click>=8.1.8",
"nuc-helpers",
"nuc>=0.1.0",
"pyyaml>=6.0.1",
"trafilatura>=1.7.0",
"secretvaults",
"pydantic>=2.0.0",
"ecdsa>=0.19.0",
"secp256k1>=0.14.0",
"hexbytes>=1.2.0",
"eth-account>=0.13.0",
"sentence-transformers>=5.1.1",
]


Expand All @@ -46,6 +46,4 @@ build-backend = "hatchling.build"
[tool.uv.sources]
nilai-common = { workspace = true }
nuc-helpers = { workspace = true }

# TODO: Remove this once the secretvaults package is released with the fix
secretvaults = { git = "https://github.com/jcabrero/secretvaults-py", rev = "main" }
31 changes: 31 additions & 0 deletions nilai-api/src/nilai_api/config/config-a779.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Web Search Configuration
web_search:
api_key: null
api_path: "https://api.search.brave.com/res/v1/web/search"
count: 3
lang: "en"
country: "us"
timeout: 20.0
max_concurrent_requests: 20
rps: 20

# Rate Limiting Configuration
rate_limiting:
user_rate_limit: null # For-good rate limit
user_rate_limit_minute: 10
user_rate_limit_hour: 100
user_rate_limit_day: 500
web_search_rate_limit_minute: null
web_search_rate_limit_hour: null
web_search_rate_limit_day: null
web_search_rate_limit: 100 # For-good rate limit
model_concurrent_rate_limit:
meta-llama/Llama-3.2-1B-Instruct: 45
meta-llama/Llama-3.2-3B-Instruct: 50
meta-llama/Llama-3.1-8B-Instruct: 30
cognitivecomputations/Dolphin3.0-Llama3.1-8B: 30
deepseek-ai/DeepSeek-R1-Distill-Qwen-14B: 5
hugging-quants/Meta-Llama-3.1-70B-Instruct-AWQ-INT4: 5
openai/gpt-oss-20b: 50
google/gemma-3-27b-it: 50
default: 50
35 changes: 35 additions & 0 deletions nilai-api/src/nilai_api/config/config-e176.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# In production, this file is automatically generated by the `ansible` playbook.
# Configuration with structured sections and default values


# Web Search Configuration
web_search:
api_key: null
api_path: "https://api.search.brave.com/res/v1/web/search"
count: 3
lang: "en"
country: "us"
timeout: 20.0
max_concurrent_requests: 20
rps: 20

# Rate Limiting Configuration
rate_limiting:
user_rate_limit: null # For-good rate limit
user_rate_limit_minute: 100
user_rate_limit_hour: 1000
user_rate_limit_day: 10000
web_search_rate_limit_minute: null
web_search_rate_limit_hour: null
web_search_rate_limit_day: 500
web_search_rate_limit: null # For-good rate limit
model_concurrent_rate_limit:
meta-llama/Llama-3.2-1B-Instruct: 45
meta-llama/Llama-3.2-3B-Instruct: 50
meta-llama/Llama-3.1-8B-Instruct: 30
cognitivecomputations/Dolphin3.0-Llama3.1-8B: 30
deepseek-ai/DeepSeek-R1-Distill-Qwen-14B: 5
hugging-quants/Meta-Llama-3.1-70B-Instruct-AWQ-INT4: 5
openai/gpt-oss-20b: 50
google/gemma-3-27b-it: 50
default: 50
35 changes: 35 additions & 0 deletions nilai-api/src/nilai_api/config/config-f910.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# In production, this file is automatically generated by the `ansible` playbook.
# Configuration with structured sections and default values


# Web Search Configuration
web_search:
api_key: null
api_path: "https://api.search.brave.com/res/v1/web/search"
count: 3
lang: "en"
country: "us"
timeout: 20.0
max_concurrent_requests: 20
rps: 20

# Rate Limiting Configuration
rate_limiting:
user_rate_limit: null # For-good rate limit
user_rate_limit_minute: 100
user_rate_limit_hour: 1000
user_rate_limit_day: 10000
web_search_rate_limit_minute: 1
web_search_rate_limit_hour: 3
web_search_rate_limit_day: 72
web_search_rate_limit: null # For-good rate limit
model_concurrent_rate_limit:
meta-llama/Llama-3.2-1B-Instruct: 45
meta-llama/Llama-3.2-3B-Instruct: 50
meta-llama/Llama-3.1-8B-Instruct: 30
cognitivecomputations/Dolphin3.0-Llama3.1-8B: 30
deepseek-ai/DeepSeek-R1-Distill-Qwen-14B: 5
hugging-quants/Meta-Llama-3.1-70B-Instruct-AWQ-INT4: 5
openai/gpt-oss-20b: 50
google/gemma-3-27b-it: 50
default: 50
29 changes: 7 additions & 22 deletions nilai-api/src/nilai_api/config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
# In production, this file is automatically generated by the `ansible` playbook.
# Configuration with structured sections and default values

# Environment Configuration
environment: "mainnet"

# Authentication Configuration
auth:
strategy: "api_key"
nilauth_trusted_root_issuers: []

# Documentation Configuration
docs:
token: null

# Web Search Configuration
web_search:
api_key: null
Expand All @@ -27,13 +12,13 @@ web_search:
# Rate Limiting Configuration
rate_limiting:
user_rate_limit: null # For-good rate limit
user_rate_limit_minute: 100
user_rate_limit_hour: 1000
user_rate_limit_day: 10000
web_search_rate_limit_minute: 1
web_search_rate_limit_hour: 3
web_search_rate_limit_day: 72
web_search_rate_limit: null # For-good rate limit
user_rate_limit_minute: 10
user_rate_limit_hour: 100
user_rate_limit_day: 500
web_search_rate_limit_minute: null
web_search_rate_limit_hour: null
web_search_rate_limit_day: null
web_search_rate_limit: 100 # For-good rate limit
model_concurrent_rate_limit:
meta-llama/Llama-3.2-1B-Instruct: 45
meta-llama/Llama-3.2-3B-Instruct: 50
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dev = [
"pyright>=1.1.405",
"pre-commit>=4.1.0",
"httpx>=0.28.1",
"deptry>=0.23.1",
]

[build-system]
Expand Down
27 changes: 25 additions & 2 deletions scripts/docker-composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,29 @@
import sys
import shutil
import yaml
from dotenv import load_dotenv


def load_environment_variables(is_dev):
"""
Load environment variables from .env.mainnet file.

Returns:
dict: Environment variables dictionary with .env.mainnet loaded
"""
env = os.environ.copy()

# Load .env.mainnet file if it exists
env_file = ".env.mainnet" if not is_dev else ".env.dev"
if os.path.isfile(env_file):
print(f"Loading environment variables from {env_file}")
load_dotenv(env_file, override=True)
# Update the env dict with the loaded variables
env.update(os.environ)
else:
print(f"Warning: {env_file} not found, using system environment variables only")

return env


def find_docker_compose_command():
Expand Down Expand Up @@ -369,8 +392,8 @@ def main():
if use_no_path_resolution:
config_cmd.append("--no-path-resolution")

# Set FILES environment variable to a valid placeholder path that we'll replace later
env = os.environ.copy()
# Load environment variables from .env.mainnet and set FILES environment variable
env = load_environment_variables(args.dev)
files_placeholder = "/tmp/files_placeholder"
env["FILES"] = files_placeholder

Expand Down
Loading
Loading