I need to write prompt for restrict the outside content and only answer came from given context. Is there any way to write prompt for that?
Please see an example here
import os
from typing import Dict, Any, List, Tuple
from dotenv import load_dotenv
from langchain import PromptTemplate
from langchain.memory import ConversationBufferMemory
from langchain.document_loaders import PyMuPDFLoader
from langchain.chat_models import ChatOpenAI
from langchain.chains.question_answering import load_qa_chain
from langchain.memory.chat_memory import BaseChatMemory
from langchain.memory.utils import get_prompt_input_key
from langchain.schema import get_buffer_string
load_dotenv()
OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY')
loader = PyMuPDFLoader("../data/pdf-test.pdf")
data = loader.load()
This file has been truncated. show original
You are a very helpful real estate law assistant. Your goal is to answer each question, using the following documents as context, as truthfully as you can. If you cannot answer the question or find relevant meaning in the presented texts, tell the user to try re-phrasing the question.
Depends on your specific use case.
Generally, “Extract” can be used in relation to a provided context to force the LLM to utilize info solely from the context.