File size: 1,692 Bytes
abb6d23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
from pathlib import Path


def csv_env(name: str, default: str):
    return [x.strip() for x in os.getenv(name, default).split(",") if x.strip()]

port = int(os.getenv("PORT", "7860"))
model = os.getenv("DEFAULT_MODEL", "chat-model-reasoning")
models = csv_env("ALLOWED_MODELS", model)
client_keys = csv_env("CLIENT_API_KEYS", os.getenv("PROXY_API_KEY", "sk-change-me"))
log_level = os.getenv("LOG_LEVEL", "INFO").upper()
timeout = int(os.getenv("REQUEST_TIMEOUT", "180"))

config = f"""server:
  port: {port}
  host: "0.0.0.0"
  timeout: {timeout}
  upstream_retry_attempts: 2
  upstream_retry_base_delay: 0.5

upstream_services:
  - name: "unlimitedai-internal"
    base_url: "http://127.0.0.1:9000/v1"
    api_key: "internal-only"
    description: "Internal UnlimitedAI OpenAI-compatible upstream"
    is_default: true
    models:
"""
for item in models:
    config += f"      - \"{item}\"\n"

config += "\nclient_authentication:\n  allowed_keys:\n"
for key in client_keys:
    config += f"    - \"{key}\"\n"

config += f"""
features:
  enable_function_calling: true
  log_level: "{log_level}"
  convert_developer_to_system: true
  key_passthrough: false
  model_passthrough: false
  enable_fc_error_retry: true
  fc_error_retry_max_attempts: 2
"""

Path("/app/toolify/config.yaml").write_text(config, encoding="utf-8")
print("[OK] wrote /app/toolify/config.yaml")
print(f"[INFO] Public Toolify port: {port}")
print(f"[INFO] Models: {', '.join(models)}")
print(f"[INFO] Client API keys configured: {len(client_keys)}")
if client_keys == ["sk-change-me"]:
    print("[WARN] PROXY_API_KEY/CLIENT_API_KEYS not set. Default API key is sk-change-me. Set a secret before public use.")