carlotamdeluna commited on
Commit
750bdfe
1 Parent(s): e4b86e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -18
app.py CHANGED
@@ -11,9 +11,6 @@ import os
11
  from getpass import getpass
12
  from langchain import HuggingFaceHub
13
  from langchain_community.llms import HuggingFaceEndpoint
14
- from langchain_core.messages import AIMessage, HumanMessage
15
- from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
16
- from langchain.memory import ChatMessageHistory
17
 
18
 
19
 
@@ -88,29 +85,19 @@ llm = HuggingFaceEndpoint(repo_id='google/gemma-7b',
88
  if 'entity_memory' not in st.session_state:
89
  st.session_state.entity_memory = ConversationEntityMemory(llm=llm, k=K )
90
 
91
- # Create the ConversationChain object with the specified configuration
92
- conversation = ConversationChain(llm=llm,,
 
93
  memory=st.session_state.entity_memory
94
  )
95
 
96
 
97
- #create prompt
98
- prompt = ChatPromptTemplate.from_messages([
99
- ("system", "You are a helpful assistant. Answer all questions to the best of your ability."),
100
- MessagesPlaceholder(variable_name="messages"),
101
- ])
102
-
103
- #create the chain
104
-
105
- chain = prompt | conversation
106
-
107
-
108
  # Get the user input
109
  user_input = get_text()
110
 
111
  # Generate the output using the ConversationChain object and the user input, and add the input/output to the session
112
  if user_input:
113
- output = chain.invoke({"messages": user_input}
114
  st.session_state.past.append(user_input)
115
  st.session_state.generated.append(output)
116
 
@@ -131,4 +118,4 @@ for i, sublist in enumerate(st.session_state.stored_session):
131
  # Allow the user to clear all stored conversation sessions
132
  if st.session_state.stored_session:
133
  if st.sidebar.checkbox("Clear-all"):
134
- del st.session_state.stored_session
 
11
  from getpass import getpass
12
  from langchain import HuggingFaceHub
13
  from langchain_community.llms import HuggingFaceEndpoint
 
 
 
14
 
15
 
16
 
 
85
  if 'entity_memory' not in st.session_state:
86
  st.session_state.entity_memory = ConversationEntityMemory(llm=llm, k=K )
87
 
88
+ # Create the ConversationChain object with the specified configuration
89
+ Conversation = ConversationChain(llm=llm,
90
+ prompt=ENTITY_MEMORY_CONVERSATION_TEMPLATE,
91
  memory=st.session_state.entity_memory
92
  )
93
 
94
 
 
 
 
 
 
 
 
 
 
 
 
95
  # Get the user input
96
  user_input = get_text()
97
 
98
  # Generate the output using the ConversationChain object and the user input, and add the input/output to the session
99
  if user_input:
100
+ output = Conversation.run(input=user_input)
101
  st.session_state.past.append(user_input)
102
  st.session_state.generated.append(output)
103
 
 
118
  # Allow the user to clear all stored conversation sessions
119
  if st.session_state.stored_session:
120
  if st.sidebar.checkbox("Clear-all"):
121
+ del st.session_state.stored_session