Enhance dialog context handling for Text2SQL queries by integrating session history. Introduce new methods for summarizing previous assistant messages and determining if the last interaction was a data query. Update environment configuration for embedding options and improve error handling in SQL generation. Add user-facing delivery messages for successful SQL execution. This update supports more coherent follow-up questions and improves user experience in conversational interactions.
This commit is contained in:
@@ -253,6 +253,43 @@ class DeepSeekClient:
|
||||
text = (msg.content or "").strip()
|
||||
return text
|
||||
|
||||
def sql_probe_success_delivery_message(
|
||||
self,
|
||||
question: str,
|
||||
sql: str,
|
||||
*,
|
||||
max_sql_chars: int = 4000,
|
||||
**kwargs: Any,
|
||||
) -> str:
|
||||
"""
|
||||
库探针为 1(执行成功且至少一行数据)时,生成面向用户的简短交付说明。
|
||||
"""
|
||||
from config.prompts import (
|
||||
SQL_PROBE_SUCCESS_DELIVERY_SYSTEM,
|
||||
SQL_PROBE_SUCCESS_DELIVERY_USER,
|
||||
)
|
||||
|
||||
q = (question or "").strip() or "(无)"
|
||||
s = (sql or "").strip()
|
||||
if len(s) > max_sql_chars:
|
||||
s = s[: max_sql_chars - 20].rstrip() + "\n-- …(已截断)"
|
||||
|
||||
messages = [
|
||||
{"role": "system", "content": SQL_PROBE_SUCCESS_DELIVERY_SYSTEM},
|
||||
{
|
||||
"role": "user",
|
||||
"content": SQL_PROBE_SUCCESS_DELIVERY_USER.format(
|
||||
question=q,
|
||||
sql=s,
|
||||
),
|
||||
},
|
||||
]
|
||||
kwargs.setdefault("temperature", 0.2)
|
||||
kwargs.setdefault("top_p", 1.0)
|
||||
kwargs.setdefault("max_tokens", 320)
|
||||
msg = self.chat(messages, **kwargs)
|
||||
return (msg.content or "").strip()
|
||||
|
||||
def select_tables(
|
||||
self,
|
||||
question: str,
|
||||
|
||||
Reference in New Issue
Block a user