I was trying to create a chatbot using a LLM and Chat Prompt Template. But I am facing this error :type error: object of type Chat Prompt Value has no len(). Could someone let me know where this error comes from and what should be done right.
llm = Llama(
model_path=model_path1,
n_gqa=8,
n_ctx=16000, # Context length to use
n_threads=32, # Number of CPU threads to use
n_gpu_layers=0 # Number of model layers to offload to GPU
)
generation_kwargs = {
"max_tokens":20000,
"stop":["</s>"],
"echo":False, # Echo the prompt in the output
"top_k":1 # This is essentially greedy decoding, since the model will always return the highest-probability token. Set this value > 1 for sampling decoding
}
#prompt Initialization
prompt= ChatPromptTemplate.from_template(
'''
Answer the following question based on the provided context only.
Please provide the most accurate response based on question and context.
If you don't know the answer don't makeup the answer just mention that you dont have enough information.
I'll tip you $1000 if user finds it helpful.
<context>
{context}
</context>
Questions:{input}
'''
)
#persist_directory
# ps=r"C:/Users/Selva N/Documents/Chat_projects/Codes/Docs"
def simplechat():
#loading path files from local
Loader=PyPDFDirectoryLoader(file_path)
docs=Loader.load()
#Splitting the text using text splitters
text_splitter=RecursiveCharacterTextSplitter(chunk_size=200,chunk_overlap=20)
splits=text_splitter.split_documents(docs)
# Storing in the vector database
embeddings=OllamaEmbeddings()
st.session_state.db=Chroma.from_documents(splits,embeddings)
st.sidebar.success("Start Querying!")
# Retrieval
def retreiver():
document_chain = create_stuff_documents_chain(llm,prompt)
retriever=st.session_state.db.as_retriever()
retrieval_chain=create_retrieval_chain(retriever,document_chain)
response=retrieval_chain.invoke({'input':st.session_state.query})
st.write(response['answer'])
return response
#Calling the function
file_path=st.sidebar.text_input("Select the folder path which contains the docs")
st.session_state.query=st.text_input("Enter the query to be asked")
if st.sidebar.button('Submit'):
DB=simplechat()
if st.button('Enter'):
retreiver()
I was trying to create a chatbot using a LLM and Chat Prompt Template. But I am facing this error :type error: object of type Chat Prompt Value has no Len(). Could someone let me know where this error comes from and what should be done right.
Porselvan Prakash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.