chatdocs icon indicating copy to clipboard operation
chatdocs copied to clipboard

Custom LangChain prompt via `config.retriever.custom_prompt`

Open matteocargnelutti opened this issue 2 years ago • 3 comments

This PR allows for replacing LangChain's default prompt via the retriever.custom_prompt property of the config object.

matteocargnelutti avatar Sep 29 '23 17:09 matteocargnelutti

Could you please provide an example chatdocs.yml for a custom LangChain prompt. Thank you in advance

AlexPerkin avatar Oct 10 '23 06:10 AlexPerkin

For sure. Any prompt compatible with LangChain's PromptTemplate should do.

In chatdocs.yml:

retriever:
  custom_prompt: "
    Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.

    {context}

    Question: {question}
    Helpful Answer:"

matteocargnelutti avatar Oct 10 '23 14:10 matteocargnelutti

For my part, I would like to offer a prompt designed for Llama 2, which significantly improves the quality of answers:

retriever:
  custom_prompt: "[INST] <<SYS>>Use the following pieces of context to answer the question at the end. Let's think step by step. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.
<</SYS>>

CONTEXT:

{context}

Question: {question}
[/INST]

Helpful Answer:"

AlexPerkin avatar Oct 11 '23 12:10 AlexPerkin