mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-09 09:46:55 +08:00
feat: improve generate sql/chart quality
This commit is contained in:
@@ -248,7 +248,7 @@ class AiModelQuestion(BaseModel):
|
||||
_example_answer_3 = _sql_template['example_answer_3_with_limit'] if enable_query_limit else _sql_template[
|
||||
'example_answer_3']
|
||||
|
||||
templates['system'] = _base_template['system'].format(process_check=_process_check)
|
||||
templates['system'] = _base_template['system'].format(lang=self.lang, process_check=_process_check)
|
||||
templates['rules'] = _base_template['generate_rules'].format(lang=self.lang,
|
||||
base_sql_rules=_base_sql_rules,
|
||||
basic_sql_examples=_sql_examples,
|
||||
@@ -282,10 +282,14 @@ class AiModelQuestion(BaseModel):
|
||||
change_title=change_title)
|
||||
|
||||
def chart_sys_question(self):
|
||||
return get_chart_template()['system'].format(sql=self.sql, question=self.question, lang=self.lang)
|
||||
templates: dict[str, str] = {
|
||||
'system': get_chart_template()['system'].format(lang=self.lang),
|
||||
'rules': get_chart_template()['generate_rules'].format(lang=self.lang)
|
||||
}
|
||||
return templates
|
||||
|
||||
def chart_user_question(self, chart_type: Optional[str] = '', schema: Optional[str] = ''):
|
||||
return get_chart_template()['user'].format(sql=self.sql, question=self.question, rule=self.rule,
|
||||
return get_chart_template()['user'].format(lang=self.lang, sql=self.sql, question=self.question, rule=self.rule,
|
||||
chart_type=chart_type, schema=schema)
|
||||
|
||||
def analysis_sys_question(self):
|
||||
|
||||
@@ -261,11 +261,17 @@ class LLMService:
|
||||
filter(lambda obj: obj.pid == self.chat_question.regenerate_record_id, self.generate_chart_logs), None)
|
||||
last_chart_messages: List[dict[str, Any]] = _temp_log.messages if _temp_log else []
|
||||
|
||||
# 排除所有的系统提示词
|
||||
last_chart_messages = [obj for obj in last_chart_messages if obj.get("sqlbot_system") != True]
|
||||
|
||||
count_chart_limit = self.base_message_round_count_limit
|
||||
|
||||
self.chart_message = []
|
||||
# add sys prompt
|
||||
self.chart_message.append(SystemPromptMessage(content=self.chat_question.chart_sys_question()))
|
||||
_chart_system_templates = self.chat_question.chart_sys_question()
|
||||
self.chart_message.append(SystemPromptMessage(content=_chart_system_templates['system']))
|
||||
self.chart_message.append(HumanPromptMessage(content=_chart_system_templates['rules']))
|
||||
self.chart_message.append(AIPromptMessage(content='我已掌握所有规则,我会严格遵守这些规则来生成符合要求的JSON。'))
|
||||
if last_chart_messages is not None and len(last_chart_messages) > 0:
|
||||
last_rounds = get_last_conversation_rounds(last_chart_messages, rounds=count_chart_limit)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user