Darpan07 commited on
Commit
60f64c5
1 Parent(s): 0f5d833

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -8,7 +8,7 @@ from langchain_openai import OpenAI, OpenAIEmbeddings
8
  from langchain.prompts import PromptTemplate
9
  from langchain.chains import LLMChain
10
  from langchain.memory import ConversationBufferWindowMemory
11
- from langchain.text_splitter import CharacterTextSplitter
12
  from langchain_community.vectorstores import FAISS
13
 
14
 
@@ -46,11 +46,11 @@ def get_vectorstore(text_chunks):
46
 
47
  def get_text_chunks(text: str):
48
  """ This function will split the text into the smaller chunks"""
49
- text_splitter = CharacterTextSplitter(
50
- separator="\n",
51
- chunk_size=1000,
52
- chunk_overlap=264,
53
- length_function=len
54
  )
55
  chunks = text_splitter.split_text(text)
56
  return chunks
@@ -70,7 +70,7 @@ def processing(pdf):
70
 
71
  def get_response(query: str) -> str:
72
  # getting the context from the database that is similar to the user query
73
- query_context = st.session_state.vectorDB.similarity_search(query=query,k=2)
74
  # calling the chain to get the output from the LLM
75
  response = st.session_state.chain.invoke({'human_input':query,'context':query_context,'name':st.session_state.bot_name})['text']
76
  # Iterate through each word in the 'response' string after splitting it based on whitespace
@@ -83,12 +83,12 @@ def get_response(query: str) -> str:
83
 
84
  def get_conversation_chain(vectorDB):
85
  # using OPENAI LLM
86
- llm = OpenAI(temperature=0.5)
87
 
88
  # creating a template to pass into LLM
89
  template = """You are a Personalized ChatBot with a name: {name} for a company's customer support system, aiming to enhance the customer experience by providing tailored assistance and information. You are interacting with customer.
90
 
91
- Answer the question as detailed as possible from the context: {context}\n , and make sure to provide all the details, if the answer is not in the provided context just say, "answer is not available in the context", don't provide the wrong answer\n\n
92
 
93
  {chat_history}
94
  Human: {human_input}
 
8
  from langchain.prompts import PromptTemplate
9
  from langchain.chains import LLMChain
10
  from langchain.memory import ConversationBufferWindowMemory
11
+ from langchain.text_splitter import CharacterTextSplitter, RecursiveCharacterTextSplitter
12
  from langchain_community.vectorstores import FAISS
13
 
14
 
 
46
 
47
  def get_text_chunks(text: str):
48
  """ This function will split the text into the smaller chunks"""
49
+ text_splitter = RecursiveCharacterTextSplitter(
50
+ chunk_size=1000,
51
+ chunk_overlap=100,
52
+ length_function=len,
53
+ is_separator_regex=False,
54
  )
55
  chunks = text_splitter.split_text(text)
56
  return chunks
 
70
 
71
  def get_response(query: str) -> str:
72
  # getting the context from the database that is similar to the user query
73
+ query_context = st.session_state.vectorDB.similarity_search(query=query,k=3)
74
  # calling the chain to get the output from the LLM
75
  response = st.session_state.chain.invoke({'human_input':query,'context':query_context,'name':st.session_state.bot_name})['text']
76
  # Iterate through each word in the 'response' string after splitting it based on whitespace
 
83
 
84
  def get_conversation_chain(vectorDB):
85
  # using OPENAI LLM
86
+ llm = OpenAI(temperature=0.3)
87
 
88
  # creating a template to pass into LLM
89
  template = """You are a Personalized ChatBot with a name: {name} for a company's customer support system, aiming to enhance the customer experience by providing tailored assistance and information. You are interacting with customer.
90
 
91
+ Answer the question as detailed as possible and to the point from the context: {context}\n , and make sure to provide all the information, if the answer is not in the provided context just say, "answer is not available in the context", don't provide the wrong answer\n\n
92
 
93
  {chat_history}
94
  Human: {human_input}