File size: 1,154 Bytes
f2ec360
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

from langchain.llms import BaseLLM
from langchain.base_language import BaseLanguageModel
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate

class MostPertinentQuestion(LLMChain):
    @classmethod
    def from_llm(cls, llm: BaseLanguageModel, verbose: bool = True) -> LLMChain:
        """Get the response parser."""
        question_prioritization_template = (
            "You are provided with the following list of questions:"
            " {unanswered_questions} \n"
            " Your task is to choose one question from the above list" 
            " that is the most pertinent to the following query:\n" 
            " '{original_question}' \n"
            " Respond with one question out of the provided list of questions."
            " Return the questions as it is without any edits."
            " Format your response like:\n"
            " #. question"
        )
        prompt = PromptTemplate(
            template=question_prioritization_template,
            input_variables=["unanswered_questions", "original_question"],
        )
        return cls(prompt=prompt, llm=llm, verbose=verbose)