hello-sajal / src /chains /rephrase_question.py
sajal2692's picture
add hfspace files
274be20
raw
history blame contribute delete
981 Bytes
"""Implements the rephrase question chain"""
from langchain_core.prompts import PromptTemplate
from langchain_core.output_parsers import StrOutputParser
class RephraseQuestion:
"""Implements the rephrase question chain"""
_CONDESE_QUESTION_PROMPT_TEMPLATE = """
Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question, in its original language.
Chat History:
{chat_history}
Follow Up Input: {question}
Standalone question:
"""
_CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(_CONDESE_QUESTION_PROMPT_TEMPLATE)
def __init__(self, llm):
self.rephrase_question_chain = self._CONDENSE_QUESTION_PROMPT | llm | StrOutputParser()
def run(self, message, history):
"""Returns the rephrased question from the LLM to the user's message."""
return self.rephrase_question_chain.invoke({"chat_history": history, "question": message})