This commit is contained in:
Muzhen Gaming
2025-10-15 17:40:40 +08:00
parent bf764fe683
commit 30200bf3bc
5 changed files with 97 additions and 6 deletions

View File

@@ -108,9 +108,10 @@ def send_to_openai(state: State):
logging.info("Send requested but input buffer is empty.")
return
api_key = os.environ.get("OPENAI_API_KEY") or os.environ.get("BG_AGENT_OPENAI_API_KEY")
# Prefer config; fallback to env vars for convenience
api_key = state.cfg.api_key or os.environ.get("OPENAI_API_KEY") or os.environ.get("BG_AGENT_OPENAI_API_KEY")
if not api_key:
logging.error("OPENAI_API_KEY not set. Cannot send.")
logging.error("No API key configured. Set in config.py or OPENAI_API_KEY.")
return
# Lazy import to keep startup quick
@@ -120,7 +121,8 @@ def send_to_openai(state: State):
logging.exception(f"OpenAI SDK not available: {e}")
return
client = OpenAI(api_key=api_key)
base = state.cfg.endpoint_base or "https://api.openai.com/v1"
client = OpenAI(api_key=api_key, base_url=base)
# Build chat message with multiple images
content_items = [{"type": "text", "text": state.cfg.prompt}]