cd@bziiit.com commited on
Commit
3a8ddd8
·
1 Parent(s): ea077e1

feature : dynamic variables

Browse files
Files changed (5) hide show
  1. app.py +18 -4
  2. pages/chatbot.py +1 -1
  3. pages/form.py +4 -0
  4. prompt_template.py +4 -0
  5. rag.py +13 -3
app.py CHANGED
@@ -1,15 +1,23 @@
1
  import streamlit as st
2
- import dotenv
3
  import os
4
 
 
5
  from rag import Rag
6
  from vectore_store.PineconeConnector import PineconeConnector
7
  from vectore_store.VectoreStoreManager import VectoreStoreManager
8
 
9
- GROUP_NAME = "Groupe 1"
10
 
11
- def main():
12
-
 
 
 
 
 
 
 
 
 
13
  if len(st.session_state) == 0:
14
  # Define Vectore store strategy
15
  pinecone_connector = PineconeConnector()
@@ -17,6 +25,12 @@ def main():
17
 
18
  st.session_state["messages"] = []
19
  st.session_state["assistant"] = Rag(vectore_store=vs_manager)
 
 
 
 
 
 
20
 
21
  st.set_page_config(page_title=GROUP_NAME)
22
 
 
1
  import streamlit as st
 
2
  import os
3
 
4
+ 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
 
 
9
 
10
+ load_dotenv()
11
+
12
+ GROUP_NAME = os.environ.get("APP_NAME")
13
+
14
+ def init_app():
15
+
16
+ # Read the environment variable and create a dictionary
17
+ variables = os.environ.get('VARIABLES')
18
+ keys = variables.split(',')
19
+ data_dict = {key: '' for key in keys} # Initialize with empty values
20
+
21
  if len(st.session_state) == 0:
22
  # Define Vectore store strategy
23
  pinecone_connector = PineconeConnector()
 
25
 
26
  st.session_state["messages"] = []
27
  st.session_state["assistant"] = Rag(vectore_store=vs_manager)
28
+ st.session_state["data_dict"] = data_dict
29
+
30
+
31
+ def main():
32
+
33
+ init_app()
34
 
35
  st.set_page_config(page_title=GROUP_NAME)
36
 
pages/chatbot.py CHANGED
@@ -14,7 +14,7 @@ def process_input():
14
 
15
 
16
  with st.session_state["thinking_spinner"], st.spinner(f"Je réfléchis"):
17
- agent_text = st.session_state["assistant"].ask(user_text, st.session_state["messages"] if "messages" in st.session_state else [])
18
 
19
  st.session_state["messages"].append((user_text, True))
20
  st.session_state["messages"].append((agent_text, False))
 
14
 
15
 
16
  with st.session_state["thinking_spinner"], st.spinner(f"Je réfléchis"):
17
+ agent_text = st.session_state["assistant"].ask(user_text, st.session_state["messages"] if "messages" in st.session_state else [], variables=st.session_state["data_dict"])
18
 
19
  st.session_state["messages"].append((user_text, True))
20
  st.session_state["messages"].append((agent_text, False))
pages/form.py CHANGED
@@ -3,4 +3,8 @@ import streamlit as st
3
  def page():
4
  st.subheader("Définissez vos paramètres")
5
 
 
 
 
 
6
  page()
 
3
  def page():
4
  st.subheader("Définissez vos paramètres")
5
 
6
+ for key in st.session_state.data_dict.keys():
7
+ value = st.text_input(label=key, value=st.session_state.data_dict[key])
8
+ st.session_state.data_dict[key] = value # Update the session state with user input
9
+
10
  page()
prompt_template.py CHANGED
@@ -1,5 +1,9 @@
1
  base_template = '''
2
 
 
 
 
 
3
  Documents partagées : {commonContext}
4
  Document de référence : {documentContext}
5
 
 
1
  base_template = '''
2
 
3
+ Paramètre 1 : {param_1}
4
+ Paramètre 2 : {param_2}
5
+ Paramètre 3 : {param_3}
6
+
7
  Documents partagées : {commonContext}
8
  Document de référence : {documentContext}
9
 
rag.py CHANGED
@@ -71,7 +71,7 @@ class Rag:
71
  },
72
  )
73
 
74
- def ask(self, query: str, messages: list):
75
  print(self.model)
76
  self.chain = self.prompt | self.model | StrOutputParser()
77
 
@@ -84,12 +84,22 @@ class Rag:
84
  # Retrieve the VectoreStore
85
  contextCommon = self.vector_store.retriever(query, self.embedding)
86
 
87
- return self.chain.invoke({
 
88
  "query": query,
89
  "documentContext": documentContext,
90
  "commonContext": contextCommon,
91
  "messages": messages
92
- })
 
 
 
 
 
 
 
 
 
93
 
94
  def clear(self):
95
  self.document_vector_store = None
 
71
  },
72
  )
73
 
74
+ def ask(self, query: str, messages: list, variables: dict = {}):
75
  print(self.model)
76
  self.chain = self.prompt | self.model | StrOutputParser()
77
 
 
84
  # Retrieve the VectoreStore
85
  contextCommon = self.vector_store.retriever(query, self.embedding)
86
 
87
+ # Dictionnaire de base avec les variables principales
88
+ chain_input = {
89
  "query": query,
90
  "documentContext": documentContext,
91
  "commonContext": contextCommon,
92
  "messages": messages
93
+ }
94
+
95
+ # Suppression des valeurs nulles (facultatif)
96
+ chain_input = {k: v for k, v in chain_input.items() if v is not None}
97
+
98
+ # Ajout dynamique d'autres variables dans **extra_vars
99
+ chain_input.update(variables)
100
+ print("chain_input", chain_input)
101
+
102
+ return self.chain.invoke(chain_input)
103
 
104
  def clear(self):
105
  self.document_vector_store = None