fix: use VERCEL_AI_GATEWAY_KEY, fix infisical_fetch call in deploy

This commit is contained in:
Andre Kamarudin 2026-04-16 08:11:38 +08:00
parent 2555d9a17e
commit 92ae862c2d
3 changed files with 15 additions and 9 deletions

View file

@ -1,4 +1,4 @@
TG_BOT_TOKEN=CHANGE_ME TG_BOT_TOKEN=CHANGE_ME
OPENAI_API_KEY=CHANGE_ME VERCEL_AI_GATEWAY_KEY=CHANGE_ME
OPENAI_BASE_URL=https://api.openai.com/v1 OPENAI_BASE_URL=https://ai-gateway.vercel.sh/v1
MODEL=gpt-4.1 MODEL=anthropic/claude-sonnet-4

14
main.py
View file

@ -17,14 +17,16 @@ from telegram.ext import (
filters, filters,
) )
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s %(levelname)s %(message)s") logging.basicConfig(
level=logging.INFO, format="%(asctime)s %(name)s %(levelname)s %(message)s"
)
log = logging.getLogger("betterbot") log = logging.getLogger("betterbot")
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Config # Config
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
TG_BOT_TOKEN = os.environ["TG_BOT_TOKEN"] TG_BOT_TOKEN = os.environ["TG_BOT_TOKEN"]
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"] OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY") or os.environ["VERCEL_AI_GATEWAY_KEY"]
OPENAI_BASE_URL = os.environ.get("OPENAI_BASE_URL", "https://api.openai.com/v1") OPENAI_BASE_URL = os.environ.get("OPENAI_BASE_URL", "https://api.openai.com/v1")
MODEL = os.environ.get("MODEL", "gpt-4.1") MODEL = os.environ.get("MODEL", "gpt-4.1")
SITE_DIR = pathlib.Path(os.environ.get("SITE_DIR", "/site")) SITE_DIR = pathlib.Path(os.environ.get("SITE_DIR", "/site"))
@ -209,7 +211,9 @@ async def handle_message(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None
for tc in msg.tool_calls: for tc in msg.tool_calls:
import json import json
args = json.loads(tc.function.arguments) if tc.function.arguments else {} args = (
json.loads(tc.function.arguments) if tc.function.arguments else {}
)
log.info("Tool call: %s(%s)", tc.function.name, list(args.keys())) log.info("Tool call: %s(%s)", tc.function.name, list(args.keys()))
try: try:
result = handle_tool_call(tc.function.name, args) result = handle_tool_call(tc.function.name, args)
@ -235,7 +239,9 @@ async def handle_message(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None
await update.message.reply_text(msg.content) await update.message.reply_text(msg.content)
return return
await update.message.reply_text("I ran out of steps — please try again with a simpler request.") await update.message.reply_text(
"I ran out of steps — please try again with a simpler request."
)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------

View file

@ -22,8 +22,8 @@ fi
# Fetch secrets from Infisical if available # Fetch secrets from Infisical if available
if [ -f /opt/config/infisical-agent.env ] && [ -f /opt/src/self_hosting/infra/scripts/infisical-env.sh ]; then if [ -f /opt/config/infisical-agent.env ] && [ -f /opt/src/self_hosting/infra/scripts/infisical-env.sh ]; then
source /opt/config/infisical-agent.env source /opt/src/self_hosting/infra/scripts/infisical-env.sh
bash /opt/src/self_hosting/infra/scripts/infisical-env.sh racknerd-betterbot prod "$STACK_DIR/.env" infisical_fetch racknerd-betterbot "$STACK_DIR/.env"
fi fi
cd "$STACK_DIR" cd "$STACK_DIR"