jenngang commited on
Commit
278679f
·
verified ·
1 Parent(s): e302641

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +5 -33
app.py CHANGED
@@ -569,28 +569,12 @@ class NutritionBot:
569
  self.memory = MemoryClient(api_key=MEM0_api_key) # userdata.get("mem0")) # Complete the code to define the memory client API key
570
 
571
  self.client = ChatOpenAI(
572
- model_name="gpt-4o-mini", # Specify the model to use (e.g., GPT-4 optimized version)
573
  api_key = my_api_key, # config.get("API_KEY"), # API key for authentication
574
  #endpoint = endpoint, # config.get("OPENAI_API_BASE"),
575
  temperature=0 # Controls randomness in responses; 0 ensures deterministic results
576
  )
577
 
578
- '''
579
- try:
580
- self.client = ChatOpenAI(
581
- api_key=my_api_key,
582
- base_url=endpoint,
583
- openai_api_base=endpoint,
584
- openai_api_key=my_api_key,
585
- model="gpt-4o-mini",
586
- streaming=False, # Explicitly disabling streaming
587
- temperature=0
588
- )
589
- except Exception as e:
590
- print(f"Error with OpenAI: {str(e)}")
591
- return None
592
- '''
593
-
594
  # Define tools available to the chatbot, such as web search
595
  tools = [agentic_rag]
596
 
@@ -694,7 +678,7 @@ class NutritionBot:
694
  context += "---\n"
695
 
696
  # Print context for debugging purposes
697
- st.write("Context: ", context)
698
 
699
  # Prepare a prompt combining past context and the current query
700
  prompt = f"""
@@ -702,11 +686,9 @@ class NutritionBot:
702
  Current customer query: {query}
703
  Provide a helpful response that takes into account any relevant past interactions.
704
  """
705
- st.write("prompt: ", prompt)
706
 
707
  # Generate a response using the agent
708
  response = self.agent_executor.invoke({"input": prompt})
709
- st.write("response: ", response)
710
 
711
  # Store the current interaction for future reference
712
  self.store_customer_interaction(
@@ -781,17 +763,11 @@ def nutrition_disorder_streamlit():
781
 
782
  # Check if input is safe based on allowed statuses
783
  if filtered_result in ["safe", "safe S7", "safe S6"]: # Blanks #3, #4, #5: Fill in with allowed safe statuses (e.g., "safe", "unsafe S7", "unsafe S6")
784
- st.write("Got a safe input...")
785
  try:
786
  if 'chatbot' not in st.session_state:
787
- st.write("In not in st.session_state...")
788
  st.session_state.chatbot = NutritionBot() # Blank #6: Fill in with the chatbot class initialization (e.g., NutritionBot)
789
- else:
790
- st.write("In st.session_state...")
791
 
792
- st.write(f"Getting response...\nUser ID: {st.session_state.user_id}\nUser query: {user_query}")
793
  response = st.session_state.chatbot.handle_customer_query(st.session_state.user_id, user_query)
794
- st.write(f"Got response: {response}")
795
  # Blank #7: Fill in with the method to handle queries (e.g., handle_customer_query)
796
  st.write(response)
797
  st.session_state.chat_history.append({"role": "assistant", "content": response})
@@ -800,13 +776,9 @@ def nutrition_disorder_streamlit():
800
  st.write(error_msg)
801
  st.session_state.chat_history.append({"role": "assistant", "content": error_msg})
802
  else:
803
- try:
804
- inappropriate_msg = "I apologize, but I cannot process that input as it may be inappropriate. Please try again."
805
- st.write(inappropriate_msg)
806
- st.session_state.chat_history.append({"role": "assistant", "content": inappropriate_msg})
807
- except Exception as e:
808
- st.write(str(e))
809
- st.session_state.chat_history.append({"role": "assistant", "content": str(e)})
810
 
811
  if __name__ == "__main__":
812
  nutrition_disorder_streamlit()
 
569
  self.memory = MemoryClient(api_key=MEM0_api_key) # userdata.get("mem0")) # Complete the code to define the memory client API key
570
 
571
  self.client = ChatOpenAI(
572
+ model_name="gpt-4o", # Specify the model to use (e.g., GPT-4 optimized version)
573
  api_key = my_api_key, # config.get("API_KEY"), # API key for authentication
574
  #endpoint = endpoint, # config.get("OPENAI_API_BASE"),
575
  temperature=0 # Controls randomness in responses; 0 ensures deterministic results
576
  )
577
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
578
  # Define tools available to the chatbot, such as web search
579
  tools = [agentic_rag]
580
 
 
678
  context += "---\n"
679
 
680
  # Print context for debugging purposes
681
+ #st.write("Context: ", context)
682
 
683
  # Prepare a prompt combining past context and the current query
684
  prompt = f"""
 
686
  Current customer query: {query}
687
  Provide a helpful response that takes into account any relevant past interactions.
688
  """
 
689
 
690
  # Generate a response using the agent
691
  response = self.agent_executor.invoke({"input": prompt})
 
692
 
693
  # Store the current interaction for future reference
694
  self.store_customer_interaction(
 
763
 
764
  # Check if input is safe based on allowed statuses
765
  if filtered_result in ["safe", "safe S7", "safe S6"]: # Blanks #3, #4, #5: Fill in with allowed safe statuses (e.g., "safe", "unsafe S7", "unsafe S6")
 
766
  try:
767
  if 'chatbot' not in st.session_state:
 
768
  st.session_state.chatbot = NutritionBot() # Blank #6: Fill in with the chatbot class initialization (e.g., NutritionBot)
 
 
769
 
 
770
  response = st.session_state.chatbot.handle_customer_query(st.session_state.user_id, user_query)
 
771
  # Blank #7: Fill in with the method to handle queries (e.g., handle_customer_query)
772
  st.write(response)
773
  st.session_state.chat_history.append({"role": "assistant", "content": response})
 
776
  st.write(error_msg)
777
  st.session_state.chat_history.append({"role": "assistant", "content": error_msg})
778
  else:
779
+ inappropriate_msg = "I apologize, but I cannot process that input as it may be inappropriate. Please try again."
780
+ st.write(inappropriate_msg)
781
+ st.session_state.chat_history.append({"role": "assistant", "content": inappropriate_msg})
 
 
 
 
782
 
783
  if __name__ == "__main__":
784
  nutrition_disorder_streamlit()