Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions wren-ai-service/src/pipelines/generation/utils/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ async def _classify_generation_result(
- DON'T USE '.' in column/table alias, replace '.' with '_' in column/table alias.
- DON'T USE "FILTER(WHERE <expression>)" clause in the generated SQL query.
- DON'T USE "EXTRACT(EPOCH FROM <expression>)" clause in the generated SQL query.
- DON'T USE "EXTRACT()" function with INTERVAL data types as arguments
- DON'T USE INTERVAL or generate INTERVAL-like expression in the generated SQL query.
- Aggregate functions are not allowed in the WHERE clause. Instead, they belong in the HAVING clause, which is used to filter after aggregation.
- ONLY USE JSON_QUERY for querying fields if "json_type":"JSON" is identified in the columns comment, NOT the deprecated JSON_EXTRACT_SCALAR function.
Expand Down Expand Up @@ -464,9 +465,21 @@ class SqlGenerationResult(BaseModel):
}


def construct_ask_history_messages(histories: list[AskHistory]) -> list[ChatMessage]:
def construct_ask_history_messages(
histories: list[AskHistory] | list[dict],
) -> list[ChatMessage]:
messages = []
for history in histories:
messages.append(ChatMessage.from_user(history.question))
messages.append(ChatMessage.from_assistant(history.sql))
messages.append(
ChatMessage.from_user(
history.question
if hasattr(history, "question")
else history["question"]
)
)
messages.append(
ChatMessage.from_assistant(
history.sql if hasattr(history, "sql") else history["sql"]
)
)
return messages
Loading