AIAnytime / Llama2-Medical-Chatbot

This is a medical bot built using Llama2 and Sentence Transformers. The bot is powered by Langchain and Chainlit. The bot runs on a decent CPU machine with a minimum of 16GB of RAM.
MIT License
296 stars 218 forks source link

AttributeError: 'Message' object has no attribute 'replace' #18

Closed vegansquirrel closed 8 months ago

vegansquirrel commented 10 months ago

(chatbot) C:\Users\risha\Documents\AI\LLM Chatbot OS>chainlit run main.py 2023-11-02 10:05:42 - Your app is available at http://localhost:8000 2023-11-02 10:05:56 - Load pretrained SentenceTransformer: sentence-transformers/all-MiniLM-L6-v2 2023-11-02 10:05:59 - Loading faiss with AVX2 support. 2023-11-02 10:05:59 - Could not load library with AVX2 support due to: ModuleNotFoundError("No module named 'faiss.swigfaiss_avx2'") 2023-11-02 10:05:59 - Loading faiss. 2023-11-02 10:05:59 - Successfully loaded faiss. 2023-11-02 10:06:07 - 'Message' object has no attribute 'replace' Traceback (most recent call last): File "C:\Users\risha\AppData\Roaming\Python\Python311\site-packages\chainlit\utils.py", line 39, in wrapper return await user_function(*params_values) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\risha\Documents\AI\LLM Chatbot OS\main.py", line 92, in main res = await chain.acall(message, callbacks=[cb]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\risha\AppData\Roaming\Python\Python311\site-packages\langchain\chains\base.py", line 379, in acall raise e File "C:\Users\risha\AppData\Roaming\Python\Python311\site-packages\langchain\chains\base.py", line 373, in acall await self._acall(inputs, run_manager=run_manager) File "C:\Users\risha\AppData\Roaming\Python\Python311\site-packages\langchain\chains\retrieval_qa\base.py", line 179, in _acall docs = await self._aget_docs(question, run_manager=_run_manager) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\risha\AppData\Roaming\Python\Python311\site-packages\langchain\chains\retrieval_qa\base.py", line 227, in _aget_docs return await self.retriever.aget_relevant_documents( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\risha\AppData\Roaming\Python\Python311\site-packages\langchain\schema\retriever.py", line 269, in aget_relevant_documents raise e File "C:\Users\risha\AppData\Roaming\Python\Python311\site-packages\langchain\schema\retriever.py", line 262, in aget_relevant_documents result = await self._aget_relevant_documents( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\risha\AppData\Roaming\Python\Python311\site-packages\langchain\schema\vectorstore.py", line 677, in _aget_relevant_documents docs = await self.vectorstore.asimilarity_search( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\risha\AppData\Roaming\Python\Python311\site-packages\langchain\vectorstores\faiss.py", line 534, in asimilarity_search docs_and_scores = await self.asimilarity_search_with_score( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\risha\AppData\Roaming\Python\Python311\site-packages\langchain\vectorstores\faiss.py", line 421, in asimilarity_search_with_score embedding = await self._aembed_query(query) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\risha\AppData\Roaming\Python\Python311\site-packages\langchain\vectorstores\faiss.py", line 159, in _aembed_query return await self.embedding_function.aembed_query(text) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\risha\AppData\Roaming\Python\Python311\site-packages\langchain\schema\embeddings.py", line 25, in aembed_query return await asyncio.get_running_loop().run_in_executor( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\risha\anaconda3\envs\chatbot\Lib\asyncio\futures.py", line 287, in await yield self # This tells Task to wait for completion. ^^^^^^^^^^ File "C:\Users\risha\anaconda3\envs\chatbot\Lib\asyncio\tasks.py", line 339, in __wakeup future.result() File "C:\Users\risha\anaconda3\envs\chatbot\Lib\asyncio\futures.py", line 203, in result raise self._exception.with_traceback(self._exception_tb) File "C:\Users\risha\anaconda3\envs\chatbot\Lib\concurrent\futures\thread.py", line 58, in run result = self.fn(self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\risha\AppData\Roaming\Python\Python311\site-packages\langchain\embeddings\huggingface.py", line 105, in embed_query return self.embed_documents([text])[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\risha\AppData\Roaming\Python\Python311\site-packages\langchain\embeddings\huggingface.py", line 86, in embed_documents texts = list(map(lambda x: x.replace("\n", " "), texts)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\risha\AppData\Roaming\Python\Python311\site-packages\langchain\embeddings\huggingface.py", line 86, in texts = list(map(lambda x: x.replace("\n", " "), texts)) ^^^^^^^^^ AttributeError: 'Message' object has no attribute 'replace'

MOTURUPRAVEENBHARGAV commented 10 months ago

Even I faced the same issue.

user message is not typecasting into a string in the Message object by some reasons, Why it is? I am not sure, I just rectified and typecasted into string format and it worked for me. Try it out !!

YOUR ISSUE: File "C:\Users\risha\Documents\AI\LLM Chatbot OS\main.py", line 92, in main res = await chain.acall(message, callbacks=[cb]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"

SOLUTION:

File "C:\Users\risha\Documents\AI\LLM Chatbot OS\main.py", line 92, in main res = await chain.acall(str(message), callbacks=[cb]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Kunjesh07 commented 9 months ago

I also got the same error. but then I again clone this repo and it got solved.

vegansquirrel commented 8 months ago

I also got the same error. but then I again clone this repo and it got solved.

great! I think there were relevant changes made to the code to fix the error, and library compatibility.