|
13 | 13 | query_maker_chain, |
14 | 14 | query_refiner_with_profile_chain, |
15 | 15 | profile_extraction_chain, |
| 16 | + query_enrichment_chain, |
16 | 17 | ) |
17 | 18 |
|
18 | 19 | from llm_utils.tools import get_info_from_db |
@@ -142,36 +143,13 @@ def context_enrichment_node(state: QueryMakerState): |
142 | 143 | question_profile = state["question_profile"].model_dump() |
143 | 144 | question_profile_json = json.dumps(question_profile, ensure_ascii=False, indent=2) |
144 | 145 |
|
145 | | - from langchain.prompts import PromptTemplate |
146 | | - |
147 | | - enrichment_prompt = PromptTemplate( |
148 | | - input_variables=["refined_question", "profiles", "related_tables"], |
149 | | - template=""" |
150 | | - You are a smart assistant that takes a user question and enriches it using: |
151 | | - 1. Question profiles: {profiles} |
152 | | - 2. Table metadata (names, columns, descriptions): |
153 | | - {related_tables} |
154 | | -
|
155 | | - Tasks: |
156 | | - - Correct any wrong terms by matching them to actual column names. |
157 | | - - If the question is time-series or aggregation, add explicit hints (e.g., "over the last 30 days"). |
158 | | - - If needed, map natural language terms to actual column values (e.g., ‘미국’ → ‘USA’ for country_code). |
159 | | - - Output the enriched question only. |
160 | | -
|
161 | | - Refined question: |
162 | | - {refined_question} |
163 | | -
|
164 | | - Using the refined version for enrichment, but keep original intent in mind. |
165 | | - """.strip(), |
166 | | - ) |
167 | | - |
168 | | - llm = get_llm() |
169 | | - prompt = enrichment_prompt.format_prompt( |
170 | | - refined_question=state["refined_input"], |
171 | | - profiles=question_profile_json, |
172 | | - related_tables=searched_tables_json, |
| 146 | + enriched_text = query_enrichment_chain.invoke( |
| 147 | + input={ |
| 148 | + "refined_question": state["refined_input"], |
| 149 | + "profiles": question_profile_json, |
| 150 | + "related_tables": searched_tables_json, |
| 151 | + } |
173 | 152 | ) |
174 | | - enriched_text = llm.invoke(prompt.to_messages()) |
175 | 153 |
|
176 | 154 | state["refined_input"] = enriched_text |
177 | 155 | state["messages"].append(enriched_text) |
|
0 commit comments