Spaces:
Sleeping
Sleeping
[email protected]
commited on
Commit
·
18107fd
1
Parent(s):
5480e8d
Reset daily message count at the start of a new day
Browse files- apis/LangSmith.py +18 -7
apis/LangSmith.py
CHANGED
@@ -1,9 +1,8 @@
|
|
1 |
import requests
|
2 |
import json
|
3 |
import os
|
4 |
-
from time import sleep
|
5 |
from dotenv import load_dotenv
|
6 |
-
from datetime import datetime
|
7 |
|
8 |
|
9 |
load_dotenv()
|
@@ -11,6 +10,8 @@ load_dotenv()
|
|
11 |
API_BASE_URL = "https://api.smith.langchain.com/api/v1"
|
12 |
|
13 |
class LangSmithAPI:
|
|
|
|
|
14 |
|
15 |
def __init__(self):
|
16 |
self.base_url = API_BASE_URL
|
@@ -20,6 +21,10 @@ class LangSmithAPI:
|
|
20 |
|
21 |
self.getSessionId()
|
22 |
|
|
|
|
|
|
|
|
|
23 |
def getSessionId(self):
|
24 |
|
25 |
payload = {}
|
@@ -59,14 +64,20 @@ class LangSmithAPI:
|
|
59 |
|
60 |
|
61 |
def getDailyMessages(self, id_request: str = ""):
|
62 |
-
|
63 |
trace = self.getLastTraces(id_request)
|
64 |
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
|
|
67 |
for t in trace:
|
68 |
start_time = datetime.fromisoformat(t['start_time'])
|
69 |
-
if start_time.date() ==
|
70 |
-
|
71 |
|
72 |
-
return
|
|
|
1 |
import requests
|
2 |
import json
|
3 |
import os
|
|
|
4 |
from dotenv import load_dotenv
|
5 |
+
from datetime import datetime, timedelta
|
6 |
|
7 |
|
8 |
load_dotenv()
|
|
|
10 |
API_BASE_URL = "https://api.smith.langchain.com/api/v1"
|
11 |
|
12 |
class LangSmithAPI:
|
13 |
+
_daily_count = 0
|
14 |
+
_last_count_date = None
|
15 |
|
16 |
def __init__(self):
|
17 |
self.base_url = API_BASE_URL
|
|
|
21 |
|
22 |
self.getSessionId()
|
23 |
|
24 |
+
if self._last_count_date != datetime.today().date():
|
25 |
+
self._daily_count = 0
|
26 |
+
self._last_count_date = datetime.today().date()
|
27 |
+
|
28 |
def getSessionId(self):
|
29 |
|
30 |
payload = {}
|
|
|
64 |
|
65 |
|
66 |
def getDailyMessages(self, id_request: str = ""):
|
|
|
67 |
trace = self.getLastTraces(id_request)
|
68 |
|
69 |
+
current_date = datetime.today().date()
|
70 |
+
# current_date = current_date - timedelta(days=1) # Yesterday
|
71 |
+
|
72 |
+
# Reset counter if it's a new day
|
73 |
+
if self._last_count_date != current_date:
|
74 |
+
self._daily_count = 0
|
75 |
+
self._last_count_date = current_date
|
76 |
|
77 |
+
# Count only new messages from the current day
|
78 |
for t in trace:
|
79 |
start_time = datetime.fromisoformat(t['start_time'])
|
80 |
+
if start_time.date() == current_date:
|
81 |
+
self._daily_count += 1
|
82 |
|
83 |
+
return self._daily_count
|