Spaces:
Runtime error
Runtime error
jiarongqiu commited on
Commit ·
6226c78
1
Parent(s): 5e8c185
logger
Browse files- service/api.py +8 -0
- service/logger.py +54 -0
service/api.py
CHANGED
|
@@ -5,6 +5,7 @@ import requests
|
|
| 5 |
from typing import Any
|
| 6 |
from .llm import search_bot
|
| 7 |
from .vector_store import vector_store
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
class API():
|
|
@@ -24,6 +25,7 @@ class API():
|
|
| 24 |
if name == '' or url == '':
|
| 25 |
continue
|
| 26 |
res.append({"name":name,"url":url})
|
|
|
|
| 27 |
return res
|
| 28 |
|
| 29 |
|
|
@@ -48,6 +50,12 @@ class API():
|
|
| 48 |
for i in answer:
|
| 49 |
text += i
|
| 50 |
yield i
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
def get_filecoin_price(self):
|
| 53 |
url="https://api.spacescope.io/v2/price/realtime"
|
|
|
|
| 5 |
from typing import Any
|
| 6 |
from .llm import search_bot
|
| 7 |
from .vector_store import vector_store
|
| 8 |
+
from .logger import logger
|
| 9 |
|
| 10 |
|
| 11 |
class API():
|
|
|
|
| 25 |
if name == '' or url == '':
|
| 26 |
continue
|
| 27 |
res.append({"name":name,"url":url})
|
| 28 |
+
logger.write_log({"query":query,"api":'auto_complete',"result":res})
|
| 29 |
return res
|
| 30 |
|
| 31 |
|
|
|
|
| 50 |
for i in answer:
|
| 51 |
text += i
|
| 52 |
yield i
|
| 53 |
+
logger.write_log({
|
| 54 |
+
"query":query,
|
| 55 |
+
"api":'search',
|
| 56 |
+
"source":source,
|
| 57 |
+
'answer':text})
|
| 58 |
+
|
| 59 |
|
| 60 |
def get_filecoin_price(self):
|
| 61 |
url="https://api.spacescope.io/v2/price/realtime"
|
service/logger.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import json
|
| 3 |
+
from typing import Any
|
| 4 |
+
import pytz
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from huggingface_hub import CommitScheduler
|
| 7 |
+
from datetime import datetime
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class Logger:
|
| 11 |
+
|
| 12 |
+
DIR = os.path.join(os.path.dirname(__file__),"..","data")
|
| 13 |
+
|
| 14 |
+
def __init__(self):
|
| 15 |
+
self.scheduler = CommitScheduler(
|
| 16 |
+
repo_id="Jarvis-Log",
|
| 17 |
+
repo_type="dataset",
|
| 18 |
+
folder_path=self.DIR,
|
| 19 |
+
path_in_repo="data",
|
| 20 |
+
token=os.getenv("HF_TOKEN")
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
def current_time(self):
|
| 24 |
+
beijing_tz = pytz.timezone('Asia/Shanghai')
|
| 25 |
+
beijing_time = datetime.now(beijing_tz)
|
| 26 |
+
format_time = beijing_time.strftime('%Y-%m-%d %H:%M:%S')
|
| 27 |
+
return format_time
|
| 28 |
+
|
| 29 |
+
def current_date(self):
|
| 30 |
+
beijing_tz = pytz.timezone('Asia/Shanghai')
|
| 31 |
+
beijing_time = datetime.now(beijing_tz)
|
| 32 |
+
format_date = beijing_time.strftime('%Y-%m-%d')
|
| 33 |
+
return format_date
|
| 34 |
+
|
| 35 |
+
def _write_log(self, data, dir_name):
|
| 36 |
+
path = Path(self.DIR,dir_name)
|
| 37 |
+
path.mkdir(parents=True, exist_ok=True)
|
| 38 |
+
path = path/f'{self.current_date()}.json'
|
| 39 |
+
data['datetime'] = self.current_time()
|
| 40 |
+
data = json.dumps(data)+"\n"
|
| 41 |
+
with self.scheduler.lock:
|
| 42 |
+
with path.open("a") as f:
|
| 43 |
+
f.write(data)
|
| 44 |
+
|
| 45 |
+
def write_dataset(self,data):
|
| 46 |
+
self._write_log(data,"dataset")
|
| 47 |
+
|
| 48 |
+
def write_log(self,data):
|
| 49 |
+
self._write_log(data,"log")
|
| 50 |
+
|
| 51 |
+
def __call__(self,data):
|
| 52 |
+
print(f"[{self.current_time()}]{data}")
|
| 53 |
+
|
| 54 |
+
logger = Logger()
|