Metinden Cypher’a alma zinciri
Artık doğal dili bir Cypher ifadesine dönüştürebilen bir zincirin var. Bunu daha büyük bir zincirde kullanarak LLM’in ürettiği bu Cypher’ı çalıştıralım ve getirilen bilgilerle kullanıcı sorularını yanıtlayalım.
Bu egzersiz, kursun bir parçasıdır
LangChain ve Neo4j ile Graph RAG
Egzersiz talimatları
- Kodu güncelleyerek
text_to_cypher_chaintarafından üretilen Cypher ifadesini çalıştır veQA_PROMPTiçinde kullanılan"context"değişkenine ata. - Girdiyi,
"question"değişkenine olduğu gibi aktar.
Uygulamalı etkileşimli egzersiz
Bu egzersizi bu örnek kodu tamamlayarak deneyin.
qa_prompt = ChatPromptTemplate.from_messages([
SystemMessagePromptTemplate.from_template(QA_PROMPT),
HumanMessagePromptTemplate.from_template("Question: {question}")
])
qa_chain = {
# Use output of text_to_cypher to get database results
"context": text_to_cypher_chain | ____(lambda cypher: graph.____(cypher)),
# Pass the user input through to the "question" variable
"question": ____
} | qa_prompt | llm | StrOutputParser()
res = qa_chain.invoke({"question": "What companies is Harrison Chase connected to?"})
print(res)