File size: 706 Bytes
2e5aca2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
### Rewrite a question to be more optimized for Wikipedia search
from utils.config import REWRITER_MODEL
from utils.prompts import QUERY_REWRITE_PROMPT, QUERY_REWRITE_SYSTEM_PROMPT
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI

# Question rewriter LLM
llm = ChatOpenAI(model=REWRITER_MODEL, temperature=0, streaming=True)

# Prompt
rewrite_prompt = ChatPromptTemplate.from_messages(
    [
        ("system", QUERY_REWRITE_SYSTEM_PROMPT),
        ("human", QUERY_REWRITE_PROMPT),
    ]
)

question_rewriter = rewrite_prompt | llm | StrOutputParser()
# question_rewriter.invoke({"question": question})