[email protected] commited on
Commit
d4c1058
·
1 Parent(s): ba9997b

Fix multi messages by companies

Browse files
app.py CHANGED
@@ -32,6 +32,9 @@ def init_app():
32
  st.session_state["data_dict"] = {}
33
  st.session_state["company_code"] = None
34
  st.session_state["prompt_system"] = config['prompt_system']
 
 
 
35
 
36
  # Initialize data_dict for each company
37
  for company in config['companies']:
 
32
  st.session_state["data_dict"] = {}
33
  st.session_state["company_code"] = None
34
  st.session_state["prompt_system"] = config['prompt_system']
35
+ st.session_state["chat_history_afp"] = []
36
+ st.session_state["chat_history_cettons"] = []
37
+ st.session_state["chat_history_steel"] = []
38
 
39
  # Initialize data_dict for each company
40
  for company in config['companies']:
pages/chatbot_afp.py CHANGED
@@ -8,7 +8,7 @@ from subscription.index import is_usage_limit_reached, daily_limit_enabled
8
 
9
  def display_messages():
10
 
11
- for i, message in enumerate(st.session_state.chat_history):
12
  if isinstance(message, AIMessage):
13
  with st.chat_message("AI"):
14
  # Display the model from the kwargs
@@ -16,7 +16,7 @@ def display_messages():
16
  st.write(f"**Model :** {model}")
17
  st.markdown(message.content)
18
  st_copy_to_clipboard(message.content,key=f"message_{i}")
19
- # show_retrieved_documents(st.session_state.chat_history[i-1].content)
20
 
21
  elif isinstance(message, HumanMessage):
22
  with st.chat_message("Moi"):
@@ -48,12 +48,12 @@ def launchQuery(query: str = None):
48
  st.session_state["assistant"].ask(
49
  query,
50
  # prompt_system=st.session_state.prompt_system,
51
- messages=st.session_state["chat_history"] if "chat_history" in st.session_state else [],
52
  variables=st.session_state["data_dict"]
53
  ))
54
 
55
  # Temporary placeholder AI message in chat history
56
- st.session_state["chat_history"].append(AIMessage(content=full_response, kwargs={"model": st.session_state["assistant"].getReadableModel()}))
57
  st.rerun()
58
 
59
 
@@ -94,9 +94,8 @@ def page():
94
  st.subheader("Auto France Parts")
95
 
96
  company_code = "afp_"
97
- st.session_state["chat_history"] = []
98
 
99
- if "chat_history" not in st.session_state or len(st.session_state["chat_history"]) <= 2:
100
  # print("Initialisation de l'historique")
101
  if st.session_state["data_dict"][company_code] is not None:
102
  # Convertir la liste en dictionnaire avec 'key' comme clé et 'value' comme valeur
@@ -105,7 +104,7 @@ def page():
105
  system_template = st.session_state.prompt_system
106
  full = remplir_texte(system_template, vars, st.session_state["remove_undefined_value"])
107
 
108
- st.session_state["chat_history"] = [
109
  SystemMessage(content=full),
110
  ]
111
 
@@ -120,9 +119,9 @@ def page():
120
  # Models selector
121
  selector.ModelSelector()
122
 
123
- if(len(st.session_state["chat_history"])):
124
  if st.button("Effacer l'historique"):
125
- st.session_state["chat_history"] = []
126
 
127
  # Displaying messages
128
  display_messages()
@@ -139,7 +138,7 @@ def page():
139
 
140
  if user_query is not None and user_query != "":
141
 
142
- st.session_state["chat_history"].append(HumanMessage(content=user_query))
143
 
144
  # Stream and display response
145
  launchQuery(user_query)
 
8
 
9
  def display_messages():
10
 
11
+ for i, message in enumerate(st.session_state.chat_history_afp):
12
  if isinstance(message, AIMessage):
13
  with st.chat_message("AI"):
14
  # Display the model from the kwargs
 
16
  st.write(f"**Model :** {model}")
17
  st.markdown(message.content)
18
  st_copy_to_clipboard(message.content,key=f"message_{i}")
19
+ # show_retrieved_documents(st.session_state.chat_history_afp[i-1].content)
20
 
21
  elif isinstance(message, HumanMessage):
22
  with st.chat_message("Moi"):
 
48
  st.session_state["assistant"].ask(
49
  query,
50
  # prompt_system=st.session_state.prompt_system,
51
+ messages=st.session_state["chat_history_afp"] if "chat_history_afp" in st.session_state else [],
52
  variables=st.session_state["data_dict"]
53
  ))
54
 
55
  # Temporary placeholder AI message in chat history
56
+ st.session_state["chat_history_afp"].append(AIMessage(content=full_response, kwargs={"model": st.session_state["assistant"].getReadableModel()}))
57
  st.rerun()
58
 
59
 
 
94
  st.subheader("Auto France Parts")
95
 
96
  company_code = "afp_"
 
97
 
98
+ if "chat_history_afp" not in st.session_state or len(st.session_state["chat_history_afp"]) <= 2:
99
  # print("Initialisation de l'historique")
100
  if st.session_state["data_dict"][company_code] is not None:
101
  # Convertir la liste en dictionnaire avec 'key' comme clé et 'value' comme valeur
 
104
  system_template = st.session_state.prompt_system
105
  full = remplir_texte(system_template, vars, st.session_state["remove_undefined_value"])
106
 
107
+ st.session_state["chat_history_afp"] = [
108
  SystemMessage(content=full),
109
  ]
110
 
 
119
  # Models selector
120
  selector.ModelSelector()
121
 
122
+ if(len(st.session_state["chat_history_afp"])):
123
  if st.button("Effacer l'historique"):
124
+ st.session_state["chat_history_afp"] = []
125
 
126
  # Displaying messages
127
  display_messages()
 
138
 
139
  if user_query is not None and user_query != "":
140
 
141
+ st.session_state["chat_history_afp"].append(HumanMessage(content=user_query))
142
 
143
  # Stream and display response
144
  launchQuery(user_query)
pages/chatbot_cettons.py CHANGED
@@ -7,8 +7,8 @@ from st_copy_to_clipboard import st_copy_to_clipboard
7
  from subscription.index import is_usage_limit_reached, daily_limit_enabled
8
 
9
  def display_messages():
10
-
11
- for i, message in enumerate(st.session_state.chat_history):
12
  if isinstance(message, AIMessage):
13
  with st.chat_message("AI"):
14
  # Display the model from the kwargs
@@ -16,7 +16,7 @@ def display_messages():
16
  st.write(f"**Model :** {model}")
17
  st.markdown(message.content)
18
  st_copy_to_clipboard(message.content,key=f"message_{i}")
19
- # show_retrieved_documents(st.session_state.chat_history[i-1].content)
20
 
21
  elif isinstance(message, HumanMessage):
22
  with st.chat_message("Moi"):
@@ -48,12 +48,12 @@ def launchQuery(query: str = None):
48
  st.session_state["assistant"].ask(
49
  query,
50
  # prompt_system=st.session_state.prompt_system,
51
- messages=st.session_state["chat_history"] if "chat_history" in st.session_state else [],
52
  variables=st.session_state["data_dict"]
53
  ))
54
 
55
  # Temporary placeholder AI message in chat history
56
- st.session_state["chat_history"].append(AIMessage(content=full_response, kwargs={"model": st.session_state["assistant"].getReadableModel()}))
57
  st.rerun()
58
 
59
 
@@ -94,9 +94,8 @@ def page():
94
  st.subheader("La Pyramide des Cettons")
95
 
96
  company_code = "cettons_"
97
- st.session_state["chat_history"] = []
98
 
99
- if "chat_history" not in st.session_state or len(st.session_state["chat_history"]) <= 2:
100
  # print("Initialisation de l'historique")
101
  if st.session_state["data_dict"][company_code] is not None:
102
  # Convertir la liste en dictionnaire avec 'key' comme clé et 'value' comme valeur
@@ -105,7 +104,7 @@ def page():
105
  system_template = st.session_state.prompt_system
106
  full = remplir_texte(system_template, vars, st.session_state["remove_undefined_value"])
107
 
108
- st.session_state["chat_history"] = [
109
  SystemMessage(content=full),
110
  ]
111
 
@@ -120,9 +119,9 @@ def page():
120
  # Models selector
121
  selector.ModelSelector()
122
 
123
- if(len(st.session_state["chat_history"])):
124
  if st.button("Effacer l'historique"):
125
- st.session_state["chat_history"] = []
126
 
127
  # Displaying messages
128
  display_messages()
@@ -139,7 +138,7 @@ def page():
139
 
140
  if user_query is not None and user_query != "":
141
 
142
- st.session_state["chat_history"].append(HumanMessage(content=user_query))
143
 
144
  # Stream and display response
145
  launchQuery(user_query)
 
7
  from subscription.index import is_usage_limit_reached, daily_limit_enabled
8
 
9
  def display_messages():
10
+ print(st.session_state.chat_history_cettons)
11
+ for i, message in enumerate(st.session_state.chat_history_cettons):
12
  if isinstance(message, AIMessage):
13
  with st.chat_message("AI"):
14
  # Display the model from the kwargs
 
16
  st.write(f"**Model :** {model}")
17
  st.markdown(message.content)
18
  st_copy_to_clipboard(message.content,key=f"message_{i}")
19
+ # show_retrieved_documents(st.session_state.chat_history_cettons[i-1].content)
20
 
21
  elif isinstance(message, HumanMessage):
22
  with st.chat_message("Moi"):
 
48
  st.session_state["assistant"].ask(
49
  query,
50
  # prompt_system=st.session_state.prompt_system,
51
+ messages=st.session_state["chat_history_cettons"] if "chat_history_cettons" in st.session_state else [],
52
  variables=st.session_state["data_dict"]
53
  ))
54
 
55
  # Temporary placeholder AI message in chat history
56
+ st.session_state["chat_history_cettons"].append(AIMessage(content=full_response, kwargs={"model": st.session_state["assistant"].getReadableModel()}))
57
  st.rerun()
58
 
59
 
 
94
  st.subheader("La Pyramide des Cettons")
95
 
96
  company_code = "cettons_"
 
97
 
98
+ if "chat_history_cettons" not in st.session_state or len(st.session_state["chat_history_cettons"]) <= 2:
99
  # print("Initialisation de l'historique")
100
  if st.session_state["data_dict"][company_code] is not None:
101
  # Convertir la liste en dictionnaire avec 'key' comme clé et 'value' comme valeur
 
104
  system_template = st.session_state.prompt_system
105
  full = remplir_texte(system_template, vars, st.session_state["remove_undefined_value"])
106
 
107
+ st.session_state["chat_history_cettons"] = [
108
  SystemMessage(content=full),
109
  ]
110
 
 
119
  # Models selector
120
  selector.ModelSelector()
121
 
122
+ if(len(st.session_state["chat_history_cettons"])):
123
  if st.button("Effacer l'historique"):
124
+ st.session_state["chat_history_cettons"] = []
125
 
126
  # Displaying messages
127
  display_messages()
 
138
 
139
  if user_query is not None and user_query != "":
140
 
141
+ st.session_state["chat_history_cettons"].append(HumanMessage(content=user_query))
142
 
143
  # Stream and display response
144
  launchQuery(user_query)
pages/chatbot_steel.py CHANGED
@@ -8,7 +8,7 @@ from subscription.index import is_usage_limit_reached, daily_limit_enabled
8
 
9
  def display_messages():
10
 
11
- for i, message in enumerate(st.session_state.chat_history):
12
  if isinstance(message, AIMessage):
13
  with st.chat_message("AI"):
14
  # Display the model from the kwargs
@@ -16,7 +16,7 @@ def display_messages():
16
  st.write(f"**Model :** {model}")
17
  st.markdown(message.content)
18
  st_copy_to_clipboard(message.content,key=f"message_{i}")
19
- # show_retrieved_documents(st.session_state.chat_history[i-1].content)
20
 
21
  elif isinstance(message, HumanMessage):
22
  with st.chat_message("Moi"):
@@ -48,12 +48,12 @@ def launchQuery(query: str = None):
48
  st.session_state["assistant"].ask(
49
  query,
50
  # prompt_system=st.session_state.prompt_system,
51
- messages=st.session_state["chat_history"] if "chat_history" in st.session_state else [],
52
  variables=st.session_state["data_dict"]
53
  ))
54
 
55
  # Temporary placeholder AI message in chat history
56
- st.session_state["chat_history"].append(AIMessage(content=full_response, kwargs={"model": st.session_state["assistant"].getReadableModel()}))
57
  st.rerun()
58
 
59
 
@@ -94,9 +94,8 @@ def page():
94
  st.subheader("Steel France")
95
 
96
  company_code = "steel_"
97
- st.session_state["chat_history"] = []
98
 
99
- if "chat_history" not in st.session_state or len(st.session_state["chat_history"]) <= 2:
100
  # print("Initialisation de l'historique")
101
  if st.session_state["data_dict"][company_code] is not None:
102
  # Convertir la liste en dictionnaire avec 'key' comme clé et 'value' comme valeur
@@ -105,7 +104,7 @@ def page():
105
  system_template = st.session_state.prompt_system
106
  full = remplir_texte(system_template, vars, st.session_state["remove_undefined_value"])
107
 
108
- st.session_state["chat_history"] = [
109
  SystemMessage(content=full),
110
  ]
111
 
@@ -120,9 +119,9 @@ def page():
120
  # Models selector
121
  selector.ModelSelector()
122
 
123
- if(len(st.session_state["chat_history"])):
124
  if st.button("Effacer l'historique"):
125
- st.session_state["chat_history"] = []
126
 
127
  # Displaying messages
128
  display_messages()
@@ -139,7 +138,7 @@ def page():
139
 
140
  if user_query is not None and user_query != "":
141
 
142
- st.session_state["chat_history"].append(HumanMessage(content=user_query))
143
 
144
  # Stream and display response
145
  launchQuery(user_query)
 
8
 
9
  def display_messages():
10
 
11
+ for i, message in enumerate(st.session_state.chat_history_steel):
12
  if isinstance(message, AIMessage):
13
  with st.chat_message("AI"):
14
  # Display the model from the kwargs
 
16
  st.write(f"**Model :** {model}")
17
  st.markdown(message.content)
18
  st_copy_to_clipboard(message.content,key=f"message_{i}")
19
+ # show_retrieved_documents(st.session_state.chat_history_steel[i-1].content)
20
 
21
  elif isinstance(message, HumanMessage):
22
  with st.chat_message("Moi"):
 
48
  st.session_state["assistant"].ask(
49
  query,
50
  # prompt_system=st.session_state.prompt_system,
51
+ messages=st.session_state["chat_history_steel"] if "chat_history_steel" in st.session_state else [],
52
  variables=st.session_state["data_dict"]
53
  ))
54
 
55
  # Temporary placeholder AI message in chat history
56
+ st.session_state["chat_history_steel"].append(AIMessage(content=full_response, kwargs={"model": st.session_state["assistant"].getReadableModel()}))
57
  st.rerun()
58
 
59
 
 
94
  st.subheader("Steel France")
95
 
96
  company_code = "steel_"
 
97
 
98
+ if "chat_history_steel" not in st.session_state or len(st.session_state["chat_history_steel"]) <= 2:
99
  # print("Initialisation de l'historique")
100
  if st.session_state["data_dict"][company_code] is not None:
101
  # Convertir la liste en dictionnaire avec 'key' comme clé et 'value' comme valeur
 
104
  system_template = st.session_state.prompt_system
105
  full = remplir_texte(system_template, vars, st.session_state["remove_undefined_value"])
106
 
107
+ st.session_state["chat_history_steel"] = [
108
  SystemMessage(content=full),
109
  ]
110
 
 
119
  # Models selector
120
  selector.ModelSelector()
121
 
122
+ if(len(st.session_state["chat_history_steel"])):
123
  if st.button("Effacer l'historique"):
124
+ st.session_state["chat_history_steel"] = []
125
 
126
  # Displaying messages
127
  display_messages()
 
138
 
139
  if user_query is not None and user_query != "":
140
 
141
+ st.session_state["chat_history_steel"].append(HumanMessage(content=user_query))
142
 
143
  # Stream and display response
144
  launchQuery(user_query)