avngrstark commited on
Commit
8595757
·
verified ·
1 Parent(s): 1feb390

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -26,6 +26,7 @@ prompt = PromptTemplate(
26
 
27
  # Initialize memory
28
  memory = ConversationBufferMemory()
 
29
 
30
  # Create the LLM chain
31
  llm_chain = LLMChain(
@@ -34,6 +35,12 @@ llm_chain = LLMChain(
34
  memory=memory
35
  )
36
 
 
 
 
 
 
 
37
  # Streamlit app
38
  st.title("AI Chatbot")
39
  st.write("Welcome to the AI Chatbot! Ask anything you like.")
@@ -44,11 +51,9 @@ user_input = st.text_input("You:", key="input")
44
  if st.button("Send"):
45
  if user_input:
46
  # Generate response
47
- response = llm_chain.invoke({"history": memory.chat_memory.messages, 'user_input': user_input})
48
  response_text = response['text']
49
  # Display the response
50
  st.text_area("ChatBot:", response_text, height=100)
51
-
52
- st.write('----------------------------------------------------------------------------------------------')
53
  st.write('History:')
54
  st.write(response['history'])
 
26
 
27
  # Initialize memory
28
  memory = ConversationBufferMemory()
29
+ memory.save_context({"input": "I need some help"}, {"output": "ok! how can i help you."})
30
 
31
  # Create the LLM chain
32
  llm_chain = LLMChain(
 
35
  memory=memory
36
  )
37
 
38
+
39
+ def generate_response(user_input):
40
+ response = llm_chain.invoke({"history":memory.chat_memory.messages, 'user_input':user_input})
41
+ return response
42
+
43
+
44
  # Streamlit app
45
  st.title("AI Chatbot")
46
  st.write("Welcome to the AI Chatbot! Ask anything you like.")
 
51
  if st.button("Send"):
52
  if user_input:
53
  # Generate response
54
+ response = generate_response(user_input)
55
  response_text = response['text']
56
  # Display the response
57
  st.text_area("ChatBot:", response_text, height=100)
 
 
58
  st.write('History:')
59
  st.write(response['history'])