Skip to content

Commit 028dc61

Browse files
authored
Merge pull request #157 from NillionNetwork/feat/config_settings_improvements
feat: added configs and improved dependency checks
2 parents 1fa4377 + b3871aa commit 028dc61

File tree

11 files changed

+375
-126
lines changed

11 files changed

+375
-126
lines changed

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,18 @@ For a complete production setup with custom images:
140140
```shell
141141
# 1a. Generate the Production 1 image
142142
python3 ./scripts/docker-composer.py --prod \
143-
-f docker/compose/docker-compose.nilai-prod-1.yml \
144-
--image 'nillion/nilai-api:latest=public.ecr.aws/k5d9x2g2/nilai-api:v0.2.0-alpha2' \
145-
--image 'nillion/nilai-vllm:latest=public.ecr.aws/k5d9x2g2/nilai-vllm:v0.2.0-alpha2' \
146-
--image 'nillion/nilai-attestation:latest=public.ecr.aws/k5d9x2g2/nilai-attestation:v0.2.0-alpha2' \
147-
--testnet \
143+
-f docker/compose/docker-compose.nilai-prod-2.yml \
144+
--image 'nillion/nilai-api:latest=public.ecr.aws/k5d9x2g2/nilai-api:v0.2.0-rc0' \
145+
--image 'nillion/nilai-attestation:latest=public.ecr.aws/k5d9x2g2/nilai-attestation:v0.2.0-rc0' \
146+
--image 'nillion/nilai-vllm:latest=public.ecr.aws/k5d9x2g2/nilai-vllm:v0.2.0-rc0' \
148147
-o production-compose.yml
149148

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

158157

docker-compose.prod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ services:
2121
env_file:
2222
- .env.mainnet
2323
environment:
24-
- POSTGRES_DB=nuc-nilai-mainnet2
24+
- POSTGRES_DB=${POSTGRES_DB_NUC}
2525
volumes:
2626
- ${FILES}/nilai-api/config.yaml:/app/nilai-api/src/nilai_api/config/config.yaml
2727
caddy:

docker-compose.testnet.prod.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ services:
88
- .env.testnet
99
environment:
1010
- AUTH_STRATEGY=nuc
11-
- POSTGRES_DB=${POSTGRES_DB_TESTNET}
1211
volumes:
1312
- ${FILES}/testnet/nilai-api/config.yaml:/app/nilai-api/src/nilai_api/config/config.yaml
1413
grafana:

docker/compose/docker-compose.nilai-prod-1.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ services:
1313
memlock: -1
1414
stack: 67108864
1515
env_file:
16-
- .env
16+
- .env.mainnet
1717
restart: unless-stopped
1818
depends_on:
1919
etcd:

nilai-api/alembic/versions/9ddf28cf6b6f_feat_new_user_config_and_web_rate_limits.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@
2222
def upgrade() -> None:
2323
# ### commands auto generated by Alembic - please adjust! ###
2424
op.add_column(
25-
"query_logs", sa.Column("web_search_calls", sa.Integer(), nullable=False)
25+
"query_logs",
26+
sa.Column(
27+
"web_search_calls",
28+
sa.Integer(),
29+
server_default=sa.text("0"),
30+
nullable=False,
31+
),
2632
)
2733
op.add_column("users", sa.Column("rate_limits", sa.JSON(), nullable=True))
2834
op.drop_column("users", "web_search_ratelimit_minute")

nilai-api/pyproject.toml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ authors = [
1010
]
1111
requires-python = ">=3.12"
1212
dependencies = [
13-
"accelerate>=1.1.1",
1413
"alembic>=1.14.1",
15-
"cryptography>=43.0.1",
1614
"fastapi[standard]>=0.115.5",
1715
"gunicorn>=23.0.0",
1816
"nilai-common",
@@ -22,20 +20,22 @@ dependencies = [
2220
"httpx>=0.27.2",
2321
"nilrag>=0.1.11",
2422
"openai>=1.99.2",
25-
"pg8000>=1.31.2",
2623
"prometheus_fastapi_instrumentator>=7.0.2",
2724
"asyncpg>=0.30.0",
28-
"greenlet>=3.1.1",
29-
"redis>=5.2.1",
30-
"authlib>=1.4.1",
31-
"verifier",
25+
"redis>=6.4.0",
3226
"web3>=7.8.0",
3327
"click>=8.1.8",
3428
"nuc-helpers",
3529
"nuc>=0.1.0",
3630
"pyyaml>=6.0.1",
3731
"trafilatura>=1.7.0",
3832
"secretvaults",
33+
"pydantic>=2.0.0",
34+
"ecdsa>=0.19.0",
35+
"secp256k1>=0.14.0",
36+
"hexbytes>=1.2.0",
37+
"eth-account>=0.13.0",
38+
"sentence-transformers>=5.1.1",
3939
"e2b-code-interpreter>=1.0.3",
4040
]
4141

@@ -47,6 +47,4 @@ build-backend = "hatchling.build"
4747
[tool.uv.sources]
4848
nilai-common = { workspace = true }
4949
nuc-helpers = { workspace = true }
50-
51-
# TODO: Remove this once the secretvaults package is released with the fix
5250
secretvaults = { git = "https://github.com/jcabrero/secretvaults-py", rev = "main" }
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Web Search Configuration
2+
web_search:
3+
api_key: null
4+
api_path: "https://api.search.brave.com/res/v1/web/search"
5+
count: 3
6+
lang: "en"
7+
country: "us"
8+
timeout: 20.0
9+
max_concurrent_requests: 20
10+
rps: 20
11+
12+
# Rate Limiting Configuration
13+
rate_limiting:
14+
user_rate_limit: null # For-good rate limit
15+
user_rate_limit_minute: 10
16+
user_rate_limit_hour: 100
17+
user_rate_limit_day: 500
18+
web_search_rate_limit_minute: null
19+
web_search_rate_limit_hour: null
20+
web_search_rate_limit_day: null
21+
web_search_rate_limit: 100 # For-good rate limit
22+
model_concurrent_rate_limit:
23+
meta-llama/Llama-3.2-1B-Instruct: 45
24+
meta-llama/Llama-3.2-3B-Instruct: 50
25+
meta-llama/Llama-3.1-8B-Instruct: 30
26+
cognitivecomputations/Dolphin3.0-Llama3.1-8B: 30
27+
deepseek-ai/DeepSeek-R1-Distill-Qwen-14B: 5
28+
hugging-quants/Meta-Llama-3.1-70B-Instruct-AWQ-INT4: 5
29+
openai/gpt-oss-20b: 50
30+
google/gemma-3-27b-it: 50
31+
default: 50
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# In production, this file is automatically generated by the `ansible` playbook.
2+
# Configuration with structured sections and default values
3+
4+
5+
# Web Search Configuration
6+
web_search:
7+
api_key: null
8+
api_path: "https://api.search.brave.com/res/v1/web/search"
9+
count: 3
10+
lang: "en"
11+
country: "us"
12+
timeout: 20.0
13+
max_concurrent_requests: 20
14+
rps: 20
15+
16+
# Rate Limiting Configuration
17+
rate_limiting:
18+
user_rate_limit: null # For-good rate limit
19+
user_rate_limit_minute: 100
20+
user_rate_limit_hour: 1000
21+
user_rate_limit_day: 10000
22+
web_search_rate_limit_minute: null
23+
web_search_rate_limit_hour: null
24+
web_search_rate_limit_day: 500
25+
web_search_rate_limit: null # For-good rate limit
26+
model_concurrent_rate_limit:
27+
meta-llama/Llama-3.2-1B-Instruct: 45
28+
meta-llama/Llama-3.2-3B-Instruct: 50
29+
meta-llama/Llama-3.1-8B-Instruct: 30
30+
cognitivecomputations/Dolphin3.0-Llama3.1-8B: 30
31+
deepseek-ai/DeepSeek-R1-Distill-Qwen-14B: 5
32+
hugging-quants/Meta-Llama-3.1-70B-Instruct-AWQ-INT4: 5
33+
openai/gpt-oss-20b: 50
34+
google/gemma-3-27b-it: 50
35+
default: 50
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# In production, this file is automatically generated by the `ansible` playbook.
2+
# Configuration with structured sections and default values
3+
4+
5+
# Web Search Configuration
6+
web_search:
7+
api_key: null
8+
api_path: "https://api.search.brave.com/res/v1/web/search"
9+
count: 3
10+
lang: "en"
11+
country: "us"
12+
timeout: 20.0
13+
max_concurrent_requests: 20
14+
rps: 20
15+
16+
# Rate Limiting Configuration
17+
rate_limiting:
18+
user_rate_limit: null # For-good rate limit
19+
user_rate_limit_minute: 100
20+
user_rate_limit_hour: 1000
21+
user_rate_limit_day: 10000
22+
web_search_rate_limit_minute: 1
23+
web_search_rate_limit_hour: 3
24+
web_search_rate_limit_day: 72
25+
web_search_rate_limit: null # For-good rate limit
26+
model_concurrent_rate_limit:
27+
meta-llama/Llama-3.2-1B-Instruct: 45
28+
meta-llama/Llama-3.2-3B-Instruct: 50
29+
meta-llama/Llama-3.1-8B-Instruct: 30
30+
cognitivecomputations/Dolphin3.0-Llama3.1-8B: 30
31+
deepseek-ai/DeepSeek-R1-Distill-Qwen-14B: 5
32+
hugging-quants/Meta-Llama-3.1-70B-Instruct-AWQ-INT4: 5
33+
openai/gpt-oss-20b: 50
34+
google/gemma-3-27b-it: 50
35+
default: 50

scripts/docker-composer.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,29 @@
1818
import sys
1919
import shutil
2020
import yaml
21+
from dotenv import load_dotenv
22+
23+
24+
def load_environment_variables(is_dev):
25+
"""
26+
Load environment variables from .env.mainnet file.
27+
28+
Returns:
29+
dict: Environment variables dictionary with .env.mainnet loaded
30+
"""
31+
env = os.environ.copy()
32+
33+
# Load .env.mainnet file if it exists
34+
env_file = ".env.mainnet" if not is_dev else ".env.dev"
35+
if os.path.isfile(env_file):
36+
print(f"Loading environment variables from {env_file}")
37+
load_dotenv(env_file, override=True)
38+
# Update the env dict with the loaded variables
39+
env.update(os.environ)
40+
else:
41+
print(f"Warning: {env_file} not found, using system environment variables only")
42+
43+
return env
2144

2245

2346
def find_docker_compose_command():
@@ -369,8 +392,8 @@ def main():
369392
if use_no_path_resolution:
370393
config_cmd.append("--no-path-resolution")
371394

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

0 commit comments

Comments
 (0)