-
Notifications
You must be signed in to change notification settings - Fork 5
6 dbms별 sql 차이를 반영한 few shot prompt 최적화 제안 #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "6-dbms\uBCC4-sql-\uCC28\uC774\uB97C-\uBC18\uC601\uD55C-few-shot-prompt-\uCD5C\uC801\uD654-\uC81C\uC548"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ | |
from typing_extensions import TypedDict, Annotated | ||
from langgraph.graph import END, StateGraph | ||
from langgraph.graph.message import add_messages | ||
from langchain.chains.sql_database.prompt import SQL_PROMPTS | ||
from pydantic import BaseModel, Field | ||
from .llm_factory import get_llm | ||
|
||
from llm_utils.chains import ( | ||
query_refiner_chain, | ||
|
@@ -102,14 +105,44 @@ def query_maker_node(state: QueryMakerState): | |
return state | ||
|
||
|
||
class SQLResult(BaseModel): | ||
sql: str = Field(description="SQL 쿼리 문자열") | ||
explanation: str = Field(description="SQL 쿼리 설명") | ||
|
||
|
||
def query_maker_node_with_db_guide(state: QueryMakerState): | ||
sql_prompt = SQL_PROMPTS[state["user_database_env"]] | ||
llm = get_llm( | ||
model_type="openai", | ||
model_name="gpt-4o-mini", | ||
openai_api_key=os.getenv("OPENAI_API_KEY"), | ||
) | ||
chain = sql_prompt | llm.with_structured_output(SQLResult) | ||
res = chain.invoke( | ||
input={ | ||
"input": "\n\n---\n\n".join( | ||
[state["messages"][0].content] + [state["refined_input"].content] | ||
), | ||
"table_info": [json.dumps(state["searched_tables"])], | ||
"top_k": 10, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💊 top_k가 10개로 제한되어있는데 해당 파라미터의 갯수를 input으로 받게하는건 어떨까요? 그렇다면 top_k의 값을
이런식으로 받을 수 있을것 같습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. top_k의 의미가 SQL LIMIT There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아하 그렇군요!! SQL_PROMPTS의 top_k 파라미터군요 설명 감사합니다.ㅎㅎㅎㅎ |
||
} | ||
) | ||
state["generated_query"] = res.sql | ||
state["messages"].append(res.explanation) | ||
return state | ||
|
||
|
||
# StateGraph 생성 및 구성 | ||
builder = StateGraph(QueryMakerState) | ||
builder.set_entry_point(QUERY_REFINER) | ||
|
||
# 노드 추가 | ||
builder.add_node(QUERY_REFINER, query_refiner_node) | ||
builder.add_node(GET_TABLE_INFO, get_table_info_node) | ||
builder.add_node(QUERY_MAKER, query_maker_node) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💬 query_maker_node 함수 정의는 삭제되지 않았네요! (이견은 없습니다.) 추후에 성능평가 부분이 추가된다면 query_maker_node, query_maker_node_with_db_guide 를 비교해볼수도 있을것 같습니다ㅎㅎㅎ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 만들면서 #3 작업이 필요함을 느꼈습니다. token 소비는 많이 줄었는데 이게 제대로 만든 것인지 구분이 안되어서 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💬 교체된 프롬프트 덕분인지 그런지 토큰 사용량 측면에서는 비용이 꽤 많이 절약되는 것 같습니다. 그런데 호민님께서 말씀해주셨듯이 생성된 쿼리가 제대로 된 작업을 하는지 검증할 수 있으면 좋을 것 같습니다!! 또한 추가적으로 생성된 쿼리의 성능평가를 한다면 어떤 측면에서(비용, 실행시간, 리소스, 쿼리 정확도 등등) 해야 할지 논의해 보아야 할 것 같습니다. |
||
# builder.add_node(QUERY_MAKER, query_maker_node) # query_maker_node_with_db_guide | ||
builder.add_node( | ||
QUERY_MAKER, query_maker_node_with_db_guide | ||
) # query_maker_node_with_db_guide | ||
|
||
# 기본 엣지 설정 | ||
builder.add_edge(QUERY_REFINER, GET_TABLE_INFO) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💊: 추후 유저나 개발자가 프롬프트를 수정하고자 할 때, 추후 변경이 어려울 수도 있을 것 같습니다. 별도의 Class로 관리하는 것도 좋을 것 같다고 생각해 제안드립니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 #11 와 연결하면 좋을 것 같은데 Propmt를 위한 class가 정해지면 멘션 주시면 저도 참여하여 작업하도록 하겠습니다. 😄