You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I added a very descriptive title to this question.
I searched the LangChain documentation with the integrated search.
I used the GitHub search to find a similar question and didn't find it.
Commit to Help
I commit to help with one of those options 👆
Example Code
importpicklefromlangchain_huggingfaceimportHuggingFaceEmbeddingsfromlangchain.chainsimportRetrievalQAfromlangchain.promptsimportChatPromptTemplatefromlangchain.promptsimportChatPromptTemplatefromlangchain_groqimportChatGroqdefinitialize_llm():
groq_api_key="my_api"ifnotgroq_api_key:
raiseValueError("GROQ_API_KEY is not set in environment variables")
llm=ChatGroq(temperature=0, model_name="llama3-8b-8192", groq_api_key=groq_api_key)
returnllmdefcreate_rag_chain(retriever, llm):
system_prompt= (
"Anda adalah asisten untuk tugas menjawab pertanyaan yang bernama TikAI. ""Gunakan konteks yang diambil untuk menjawab. ""Menjawab menggunakan bahasa Indonesia. ""Jika Anda tidak ada jawaban pada konteks, katakan saja 'saya tidak tahu' dan berikan jawaban yang sesuai. ""Gunakan maksimal empat kalimat dan pertahankan jawaban singkat.\n\n""{context}"
)
chat_prompt=ChatPromptTemplate.from_messages([
("system", system_prompt),
("human", "{question}")
])
rag_chain=RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff",
retriever=retriever
)
returnrag_chainllm=initialize_llm()
fromtqdmimporttqdmtqdm._instances.clear() # Menonaktifkan progress bar# Membuat objek embeddingsembeddings=HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2")
# Memuat vectorstorewithopen('models/chatbot/vectorstore.pkl', 'rb') asf:
vectorstore=pickle.load(f)
retriever=vectorstore.as_retriever()
rag_chain=create_rag_chain(retriever, llm)
@app.route('/chat_bot', methods=['POST'])defchat_bot():
try:
data=request.get_json()
question=data.get('question')
ifnotquestion:
returnjsonify({"error": "Question is required"}), 400print(f"Question received: {question}")
result=rag_chain.invoke({"query": question})
print(f"Result: {result}")
ifisinstance(result, dict) and'result'inresult:
answer=result['result']
else:
answer='Saya tidak tahu'returnjsonify({"answer": answer})
exceptExceptionase:
print(f"Error: {e}")
returnjsonify({"error": "Internal Server Error"}), 500
Description
so I'm creating a chatbot function and when it's in the embeding process it gets an error like this:
Error: 'HuggingFaceBgeEmbeddings' object has no attribute 'show_progress'
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
so I'm creating a chatbot function and when it's in the embeding process it gets an error like this:
Error: 'HuggingFaceBgeEmbeddings' object has no attribute 'show_progress'
System Info
Python Version: 3.11.2
Beta Was this translation helpful? Give feedback.
All reactions