mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-13 16:53:24 +00:00
loki
This commit is contained in:
11
README.md
11
README.md
@ -41,9 +41,14 @@ env:
|
||||
port: 8000
|
||||
|
||||
log:
|
||||
level: debug
|
||||
time_format: "%Y-%m-%d %H:%M:%S"
|
||||
filename: "D:/Workspace/Logging/jarvis/jarvis-models.log"
|
||||
handlers:
|
||||
- type: loki
|
||||
url: "<loki url>"
|
||||
x-odin-auth: "<odin token>"
|
||||
labels:
|
||||
app: jarvis-model
|
||||
env: dev
|
||||
localation: "mo"
|
||||
|
||||
melotts:
|
||||
mode: local # or docker
|
||||
|
||||
21
main.py
21
main.py
@ -1,11 +1,18 @@
|
||||
import uvicorn
|
||||
import logging
|
||||
from injector import Injector,inject
|
||||
from src.configuration import LogConf, singleton
|
||||
from injector import Injector
|
||||
from src.configuration import singleton
|
||||
|
||||
# TODO: 當 skip_ssl 功能加入主分支後移除複制的代嗎,改為使用pip安裝依賴。
|
||||
from src.loki_logger_handler.loki_logger_handler import LokiLoggerHandler
|
||||
import argparse
|
||||
|
||||
import yaml
|
||||
|
||||
@singleton
|
||||
class Main():
|
||||
|
||||
def __init__(self) -> None:
|
||||
|
||||
with open(".env.yaml", "r") as file:
|
||||
config = yaml.safe_load(file)
|
||||
log_handler_confg = config["log"]["handlers"]
|
||||
@ -22,17 +29,9 @@ with open(".env.yaml", "r") as file:
|
||||
loki_metadata={"service": "user-service", "version": "1.0.0"},
|
||||
insecure_ssl_verify=False
|
||||
))
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG, handlers=log_handlers)
|
||||
logging.info("logging init finish")
|
||||
|
||||
@singleton
|
||||
class Main():
|
||||
|
||||
@inject
|
||||
def __init__(self, logConf: LogConf) -> None:
|
||||
logging.basicConfig(level=logConf.level,filename=logConf.filename,format="%(asctime)s %(levelname)s %(message)s")
|
||||
|
||||
def run(self):
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.info("jarvis-models start", extra={"version": "0.0.1"})
|
||||
|
||||
BIN
output.wav
BIN
output.wav
Binary file not shown.
19
server.py
19
server.py
@ -6,6 +6,8 @@ from fastapi.responses import JSONResponse
|
||||
from src.blackbox.blackbox_factory import BlackboxFactory
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from injector import Injector
|
||||
import contextvars
|
||||
import asyncio
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@ -29,3 +31,20 @@ async def blackbox(blackbox_name: Union[str, None] = None, request: Request = No
|
||||
except ValueError:
|
||||
return await JSONResponse(content={"error": "value error"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||
return await box.fast_api_handler(request)
|
||||
|
||||
user_id_var = contextvars.ContextVar('user_id')
|
||||
|
||||
async def perform_action():
|
||||
user_id1 = user_id_var.get()
|
||||
await asyncio.sleep(5)
|
||||
user_id = user_id_var.get()
|
||||
# Perform action based on user ID
|
||||
print(f"{user_id1}:{user_id}")
|
||||
|
||||
@app.post("/llm")
|
||||
async def llm(request: Request = None):
|
||||
|
||||
user_id_var.set(request.headers["context-id"])
|
||||
|
||||
print(request.headers["context-id"])
|
||||
# await perform_action()
|
||||
|
||||
@ -99,35 +99,6 @@ class SenseVoiceConf():
|
||||
self.language = config.get("sensevoiceasr.language")
|
||||
self.speaker = config.get("sensevoiceasr.speaker")
|
||||
|
||||
# 'CRITICAL': CRITICAL,
|
||||
# 'FATAL': FATAL,
|
||||
# 'ERROR': ERROR,
|
||||
# 'WARN': WARNING,
|
||||
# 'WARNING': WARNING,
|
||||
# 'INFO': INFO,
|
||||
# 'DEBUG': DEBUG,
|
||||
# 'NOTSET': NOTSET,
|
||||
DEFAULT_LEVEL="WARNING"
|
||||
DEFAULT_TIME_FORMAT="%Y-%m-%d %H:%M:%S"
|
||||
|
||||
@singleton
|
||||
class LogConf():
|
||||
level: int
|
||||
time_format = "%Y-%m-%d %H:%M:%S"
|
||||
filename: str | None
|
||||
@inject
|
||||
def __init__(self, config: Configuration) -> None:
|
||||
self.level = config.get("log.level")
|
||||
c = config.get("log.level", default=DEFAULT_LEVEL).upper()
|
||||
level=logging._nameToLevel.get(c)
|
||||
if level is None:
|
||||
self.level = logging.WARNING
|
||||
else:
|
||||
self.level = level
|
||||
self.filename = config.get("log.filename")
|
||||
self.time_format = config.get("log.time_format", default=DEFAULT_TIME_FORMAT)
|
||||
|
||||
|
||||
@singleton
|
||||
class EnvConf():
|
||||
version: str
|
||||
|
||||
Reference in New Issue
Block a user