Spaces:
Sleeping
Sleeping
File size: 934 Bytes
44ed2c7 ea19adc 44ed2c7 | 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 | from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from app.core.config import get_llm
from app.core.prompt import QUERY_TRANSFORM_PROMPT
def transform_with_multi_step(user_query: str) -> list:
llm = get_llm(temperature=0.2)
multi_query_prompt = ChatPromptTemplate.from_template(QUERY_TRANSFORM_PROMPT)
multi_chain = multi_query_prompt | llm | StrOutputParser()
from app.core.config import invoke_chain_with_retry
response = invoke_chain_with_retry(multi_chain, {"question": user_query})
sub_queries = [q.strip() for q in response.split('\n') if q.strip()]
cleaned_queries = []
for q in sub_queries:
cleaned_q = q.lstrip('0123456789. -')
if cleaned_q:
cleaned_queries.append(cleaned_q)
for i, q in enumerate(cleaned_queries, 1):
print(f"Sub-query {i}: {q}")
return cleaned_queries
|