HuggingFaceInstructEmbeddings 找不到指定的模块

问题描述 投票:0回答:0

我正在尝试使用 HuggingFace X langchain 的 HuggingFaceInstructEmbeddings 和以下代码:

``from langchain_community.llms import OpenAI 
from langchain_community.document_loaders import CSVLoader
from langchain_community.embeddings.huggingface import HuggingFaceInstructEmbeddings
from langchain_community.vectorstores import FAISS 
from langchain.prompts import PromptTemplate
from langchain.chains import RetrievalQA




llm = OpenAI(openai_api_key="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", temperature=0.5)


> ins_embeddings = HuggingFaceInstructEmbeddings()
> 
vectordb_file_path = "faiss_index"


def create_vector_db():
    loader = CSVLoader(file_path="Qiwa_CS.csv")
    data = loader.load()
    vectordb = FAISS.from_documents(documents=data, embedding=ins_embeddings)
    vectordb.save_local(vectordb_file_path)

def get_qa_chain():
    vectordb = FAISS.load_local(vectordb_file_path,ins_embeddings)
    my_retriver = vectordb.as_retriever()
    from langchain.prompts import PromptTemplate

    prompt_template = """Your name is  "Aref"  in Arabic is "عارف" and you are working as AI assistance for the Ministry  Human Resource and Social Development in Saudi Arabia.
    Given the following context and a question, generate an answer based on this context only.
    Please reply with the same user's language without missing the context.
    In the answer try to provide as much text as possible from the response section in the source document context without making much changes.
    If the answer is not found in the context, kindly state :
    "Sorry, this is not my specialty or "Sorry I don't have an answer to this question"
    Don't try to make up an answer.
    If the answer is related to the context of the documents in the sources and you do not know the answer, answer with
    "I think your question requires visiting this link : https://www.qiwa.sa/ar"
    CONTEXT:{context}
    QUESTION:{question}
    """

    my_prompt = PromptTemplate(template=prompt_template, input_variables=["context","question"])

    chain = RetrievalQA.from_chain_type(llm=llm,
                            chain_type="stuff",
                            retriever=my_retriver,
                            input_key="query",
                            return_source_documents=True,
                            chain_type_kwargs={"prompt": my_prompt}
                            )
    
    return chain


    


if __name__ == "__main__":
    chain = get_qa_chain()



print( chain (" how much the visa will cost ?"))


但是出现了这个错误:

文件“C:\Users\Nedal Ahmed\Desktop\QAQiwa\main.py”,第 14 行,位于 ins_embeddings = HuggingFaceInstructEmbeddings() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ OSError: [WinError 126] 找不到指定的模块。加载“c:\Users\Nedal Ahmed\Desktop\QAQiwa.venv\Lib\site-packages orch\li 时出错

huggingface-transformers langchain embedding huggingface
© www.soinside.com 2019 - 2024. All rights reserved.