#966 fix - litellm_sync import + IndentationError
## Root cause: ImportError sync_health_check not defined. ## Also IndentationError on L467/L590 in nested sync blocks. ## Container stable, public URL 200 OK.
This commit is contained in:
1 parent
fd84fec5b1
commit
75be24ce9c
2 files changed
+81
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import logging, os, httpx
|
||||
logger = logging.getLogger(__name__)
|
||||
LITM = os.getenv("LITELLM_HOST", "qihu-aiflow-litellm")
|
||||
LITP = os.getenv("LITELLM_PORT", "4000")
|
||||
LITK = os.getenv("LITELLM_MASTER_KEY", "sk-litellm-master-key-aiflow-2026")
|
||||
BASE = f"http://{LITM}:{LITP}"
|
||||
_client = None
|
||||
|
||||
def _gc():
|
||||
global _client
|
||||
if _client is None:
|
||||
_client = httpx.Client(base_url=BASE, headers={"Authorization": f"Bearer {LITK}", "Content-Type": "application/json"}, timeout=15)
|
||||
return _client
|
||||
|
||||
def _ss(op, body):
|
||||
try:
|
||||
r = _gc().post(op, json=body)
|
||||
if r.status_code in (200,201):
|
||||
logger.info(f"[litellm-sync] {op} OK")
|
||||
return True
|
||||
logger.warning(f"[litellm-sync] {op} FAIL {r.status_code}")
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.error(f"[litellm-sync] {op} ERR {e}")
|
||||
return False
|
||||
|
||||
def sync_create_model(model_name, litellm_model, api_base, api_key):
|
||||
return _ss("/model/new", {"model_name":model_name, "litellm_params":{"model":litellm_model, "api_base":api_base, "api_key":api_key}})
|
||||
|
||||
def sync_update_model(old_name, new_name, litellm_model, api_base, api_key):
|
||||
if old_name != new_name:
|
||||
_ss("/model/delete", {"id":old_name})
|
||||
return sync_create_model(new_name, litellm_model, api_base, api_key)
|
||||
return _ss("/model/update", {"model_name":new_name, "litellm_params":{"model":litellm_model, "api_base":api_base, "api_key":api_key}})
|
||||
|
||||
def sync_delete_model(model_name):
|
||||
return _ss("/model/delete", {"id":model_name})
|
||||
Reference in new issue
Block a user