Spaces:
Paused
Paused
Update admin_routes.py
Browse files- admin_routes.py +16 -1
admin_routes.py
CHANGED
|
@@ -419,11 +419,26 @@ async def update_environment(
|
|
| 419 |
"""Update environment configuration"""
|
| 420 |
config = load_config()
|
| 421 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
# Update config
|
| 423 |
config["config"]["work_mode"] = update.work_mode
|
| 424 |
config["config"]["cloud_token"] = update.cloud_token or ""
|
| 425 |
config["config"]["spark_endpoint"] = update.spark_endpoint
|
| 426 |
-
config["config"]["internal_prompt"] = update.internal_prompt or ""
|
| 427 |
config["config"]["last_update_date"] = get_timestamp()
|
| 428 |
config["config"]["last_update_user"] = username
|
| 429 |
|
|
|
|
| 419 |
"""Update environment configuration"""
|
| 420 |
config = load_config()
|
| 421 |
|
| 422 |
+
# Token validation based on mode
|
| 423 |
+
if update.work_mode in ("gpt4o", "gpt4o-mini"):
|
| 424 |
+
if not update.cloud_token:
|
| 425 |
+
raise HTTPException(status_code=400, detail="OpenAI API key is required for GPT modes")
|
| 426 |
+
# Basic format check for OpenAI key
|
| 427 |
+
if not update.cloud_token.startswith("sk-") and not update.cloud_token.startswith("enc:"):
|
| 428 |
+
raise HTTPException(status_code=400, detail="Invalid OpenAI API key format")
|
| 429 |
+
elif update.work_mode in ("hfcloud", "cloud"):
|
| 430 |
+
if not update.cloud_token:
|
| 431 |
+
raise HTTPException(status_code=400, detail="Cloud token is required for cloud modes")
|
| 432 |
+
|
| 433 |
+
# Spark endpoint validation
|
| 434 |
+
if update.work_mode not in ("gpt4o", "gpt4o-mini") and not update.spark_endpoint:
|
| 435 |
+
raise HTTPException(status_code=400, detail="Spark endpoint is required for non-GPT modes")
|
| 436 |
+
|
| 437 |
# Update config
|
| 438 |
config["config"]["work_mode"] = update.work_mode
|
| 439 |
config["config"]["cloud_token"] = update.cloud_token or ""
|
| 440 |
config["config"]["spark_endpoint"] = update.spark_endpoint
|
| 441 |
+
config["config"]["internal_prompt"] = update.internal_prompt or ""
|
| 442 |
config["config"]["last_update_date"] = get_timestamp()
|
| 443 |
config["config"]["last_update_user"] = username
|
| 444 |
|