Bắt đầu ngayBắt đầu miễn phí

Tạo một prompt few-shot cho Cypher

Kỹ thuật cuối cùng bạn sẽ dùng để tăng độ tin cậy của Cypher được sinh ra là cung cấp một few-shot prompt. Few-shot prompt là cách tuyệt vời để điều hướng mô hình tạo ra đầu ra mong muốn mà không cần fine-tune trên một bộ dữ liệu ví dụ lớn.

Một bộ ví dụ phù hợp riêng cho bài toán này đã có sẵn trong examples; bạn có thể in nó trong shell để xem nội dung. Bạn sẽ dùng chúng để tạo một few-shot prompt cho quy trình sinh Cypher. Graph bạn đã tạo trước đó vẫn khả dụng dưới biến graph.

Bài tập này là một phần của khóa học

Retrieval Augmented Generation (RAG) với LangChain

Xem khóa học

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

# Create an example prompt template
example_prompt = ____(
    "User input: {question}\nCypher query: {query}"
)

# Create the few-shot prompt template
cypher_prompt = ____(
    examples=____,
    example_prompt=____,
    prefix="You are a Neo4j expert. Given an input question, create a syntactically correct Cypher query to run.\n\nHere is the schema information\n{schema}.\n\nBelow are a number of examples of questions and their corresponding Cypher queries.",
    suffix="User input: {question}\nCypher query: ",
    input_variables=["____"]
)
Chỉnh sửa và Chạy Mã