Skip to content

Commit 7837996

Browse files
committed
feat(enriched_graph) : 프로파일 추출, 컨텍스트 보강 노드를 추가한 새로운 그래프 파일을 추가
1 parent ffd9dc8 commit 7837996

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

llm_utils/chains.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ def create_profile_extraction_chain(llm):
142142

143143
query_refiner_chain = create_query_refiner_chain(llm)
144144
query_maker_chain = create_query_maker_chain(llm)
145+
profile_extraction_chain = create_profile_extraction_chain(llm)
145146
query_refiner_with_profile_chain = create_query_refiner_with_profile_chain(llm)
146147

147148
if __name__ == "__main__":

llm_utils/enriched_graph.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import json
2+
3+
from langgraph.graph import StateGraph, END
4+
from llm_utils.graph import (
5+
QueryMakerState,
6+
GET_TABLE_INFO,
7+
PROFILE_EXTRACTION,
8+
QUERY_REFINER,
9+
CONTEXT_ENRICHMENT,
10+
QUERY_MAKER,
11+
get_table_info_node,
12+
profile_extraction_node,
13+
query_refiner_with_profile_node,
14+
context_enrichment_node,
15+
query_maker_node,
16+
)
17+
18+
"""
19+
기본 워크플로우에 '프로파일 추출(PROFILE_EXTRACTION)'과 '컨텍스트 보강(CONTEXT_ENRICHMENT)'를
20+
추가한 확장된 그래프입니다.
21+
"""
22+
23+
# StateGraph 생성 및 구성
24+
builder = StateGraph(QueryMakerState)
25+
builder.set_entry_point(GET_TABLE_INFO)
26+
27+
# 노드 추가
28+
builder.add_node(GET_TABLE_INFO, get_table_info_node)
29+
builder.add_node(QUERY_REFINER, query_refiner_with_profile_node)
30+
builder.add_node(PROFILE_EXTRACTION, profile_extraction_node)
31+
builder.add_node(CONTEXT_ENRICHMENT, context_enrichment_node)
32+
builder.add_node(QUERY_MAKER, query_maker_node)
33+
34+
# 기본 엣지 설정
35+
builder.add_edge(GET_TABLE_INFO, PROFILE_EXTRACTION)
36+
builder.add_edge(PROFILE_EXTRACTION, QUERY_REFINER)
37+
builder.add_edge(QUERY_REFINER, CONTEXT_ENRICHMENT)
38+
builder.add_edge(CONTEXT_ENRICHMENT, QUERY_MAKER)
39+
40+
# QUERY_MAKER 노드 후 종료
41+
builder.add_edge(QUERY_MAKER, END)

llm_utils/graph.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
query_refiner_chain,
1313
query_maker_chain,
1414
query_refiner_with_profile_chain,
15+
profile_extraction_chain,
1516
)
1617

1718
from llm_utils.tools import get_info_from_db
@@ -24,6 +25,8 @@
2425
TOOL = "tool"
2526
TABLE_FILTER = "table_filter"
2627
QUERY_MAKER = "query_maker"
28+
PROFILE_EXTRACTION = "profile_extraction"
29+
CONTEXT_ENRICHMENT = "context_enrichment"
2730

2831

2932
# 상태 타입 정의 (추가 상태 정보와 메시지들을 포함)
@@ -43,11 +46,10 @@ class QueryMakerState(TypedDict):
4346
# 노드 함수: PROFILE_EXTRACTION 노드
4447
def profile_extraction_node(state: QueryMakerState):
4548

46-
result = query_refiner_with_profile_chain.invoke(
47-
{"question": state["messages"][0].content}
48-
)
49+
result = profile_extraction_chain.invoke({"question": state["messages"][0].content})
4950

5051
state["question_profile"] = result
52+
print("profile_extraction_node : ", result)
5153
return state
5254

5355

@@ -132,6 +134,7 @@ def context_enrichment_node(state: QueryMakerState):
132134
from langchain_core.messages import HumanMessage
133135

134136
state["messages"].append(HumanMessage(content=enriched_text.content))
137+
print("After context enrichment : ", enriched_text.content)
135138

136139
return state
137140

File renamed without changes.

0 commit comments

Comments
 (0)