cdupland commited on
Commit
3c2250f
·
verified ·
2 Parent(s): 76f1467 f7289a6

Merge branch #Piloterra/ia-subvention' into 'mlcl-trading/ia-subvention'

Browse files
Files changed (3) hide show
  1. apis/LangSmith.py +7 -0
  2. app.py +11 -9
  3. subscription/index.py +8 -4
apis/LangSmith.py CHANGED
@@ -40,6 +40,10 @@ class LangSmithAPI:
40
 
41
 
42
  def getLastTraces(self, id_request: str = ''):
 
 
 
 
43
  payload = {
44
  "session": [self.session_id],
45
  "run_type":"chain",
@@ -66,6 +70,9 @@ class LangSmithAPI:
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
 
 
40
 
41
 
42
  def getLastTraces(self, id_request: str = ''):
43
+
44
+ if not hasattr(self, 'session_id') or not self.session_id:
45
+ return 0
46
+
47
  payload = {
48
  "session": [self.session_id],
49
  "run_type":"chain",
 
70
  def getDailyMessages(self, id_request: str = ""):
71
  trace = self.getLastTraces(id_request)
72
 
73
+ if trace == 0:
74
+ return 0
75
+
76
  current_date = datetime.today().date()
77
  # current_date = current_date - timedelta(days=1) # Yesterday
78
 
app.py CHANGED
@@ -5,7 +5,7 @@ from dotenv import load_dotenv
5
  from rag import Rag
6
  from vectore_store.PineconeConnector import PineconeConnector
7
  from vectore_store.VectoreStoreManager import VectoreStoreManager
8
- from subscription.index import get_usages, is_usage_limit_reached
9
 
10
  from util import getYamlConfig
11
 
@@ -51,14 +51,16 @@ def main():
51
  st.logo(LOGO)
52
  st.title(GROUP_NAME)
53
 
54
- usages = get_usages()
55
- reached = is_usage_limit_reached()
56
-
57
- st.sidebar.html(f"<p style='margin:0;text-align:center;font-weight:bold;font-size:24px;'>{usages['count']} / {usages['daily_limit']}</p>")
58
- if reached:
59
- st.sidebar.html(f"<p style='text-align:center;font-style:italic;'>Vous avez atteint la limite d'utilisation<p>")
60
- else:
61
- st.sidebar.html(f"<p style='text-align:center;'>Nombre de messages envoyés aujourd'hui<p>")
 
 
62
 
63
 
64
  saved_documents = st.Page("pages/persistent_documents.py", title="Communs", icon="🗃️")
 
5
  from rag import Rag
6
  from vectore_store.PineconeConnector import PineconeConnector
7
  from vectore_store.VectoreStoreManager import VectoreStoreManager
8
+ from subscription.index import get_usages, is_usage_limit_reached, daily_limit_enabled
9
 
10
  from util import getYamlConfig
11
 
 
51
  st.logo(LOGO)
52
  st.title(GROUP_NAME)
53
 
54
+ if daily_limit_enabled():
55
+ usages = get_usages()
56
+ reached = is_usage_limit_reached()
57
+
58
+ st.sidebar.html(f"<p style='margin:0;text-align:center;font-weight:bold;font-size:24px;'>{usages['count']} / {usages['daily_limit']}</p>")
59
+ if reached:
60
+ st.sidebar.html(f"<p style='text-align:center;font-style:italic;'>Vous avez atteint la limite d'utilisation<p>")
61
+ else:
62
+ st.sidebar.html(f"<p style='text-align:center;'>Nombre de messages envoyés aujourd'hui<p>")
63
+
64
 
65
 
66
  saved_documents = st.Page("pages/persistent_documents.py", title="Communs", icon="🗃️")
subscription/index.py CHANGED
@@ -4,11 +4,15 @@ from dotenv import load_dotenv
4
 
5
  load_dotenv()
6
 
7
- langsmith = LangSmithAPI()
8
- count = langsmith.getDailyMessages()
9
 
10
- # Convert DAILY_LIMIT to int with a default value of 5
11
- DAILY_LIMIT = int(os.getenv("DAILY_MESSAGES_LIMIT", "5"))
 
 
 
 
12
 
13
  def is_usage_limit_reached():
14
  return count >= DAILY_LIMIT
 
4
 
5
  load_dotenv()
6
 
7
+ # Convert DAILY_LIMIT to int with a default value of 0
8
+ DAILY_LIMIT = int(os.getenv("DAILY_MESSAGES_LIMIT", "0"))
9
 
10
+ if(DAILY_LIMIT > 0):
11
+ langsmith = LangSmithAPI()
12
+ count = langsmith.getDailyMessages()
13
+
14
+ def daily_limit_enabled():
15
+ return DAILY_LIMIT > 0
16
 
17
  def is_usage_limit_reached():
18
  return count >= DAILY_LIMIT