Skip to content

Commit 1fb74b8

Browse files
committed
fix: adapt intent recognition to upstream v1.6.0 API changes
- Remove message history round-limit for intent recognition context - Add db_schema guard in choose_table_schema() to skip RAG when guess_tables already set schema - Delay init_messages() when intent recognition is enabled - Fix init_messages() calls to pass required session parameter (v1.6.0) - Add i18n labels for RECOGNIZE_INTENT and GENERATE_CLARIFICATION in zh-CN, en, ko-KR
1 parent 7f14b68 commit 1fb74b8

4 files changed

Lines changed: 19 additions & 9 deletions

File tree

backend/apps/chat/task/llm.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,9 @@ def init_intent_messages(self, session: Session):
329329
)
330330
))
331331

332-
# 2. 历史消息(限制数量,仿照 sql_message)
333-
count_limit = 0 - base_message_count_limit
332+
# 2. 历史消息(不限轮次,使用全部历史以保持意图识别上下文完整)
334333
if last_messages is not None and len(last_messages) > 0:
335-
for msg in last_messages[count_limit:]:
334+
for msg in last_messages:
336335
if msg.get('type') == 'human':
337336
self.intent_message.append(HumanMessage(content=msg.get('content')))
338337
elif msg.get('type') == 'ai':
@@ -678,6 +677,9 @@ def filter_training_template(self, _session: Session, oid: int = None, ds_id: in
678677
full_message=example_list)
679678

680679
def choose_table_schema(self, _session: Session):
680+
# 如果 db_schema 已设置(如意图识别的 guess_tables),跳过 RAG 搜索
681+
if self.chat_question.db_schema:
682+
return
681683
self.current_logs[OperationEnum.CHOOSE_TABLE] = start_log(session=_session,
682684
operate=OperationEnum.CHOOSE_TABLE,
683685
record_id=self.record.id,
@@ -1421,7 +1423,9 @@ def run_task(self, in_chat: bool = True, stream: bool = True,
14211423

14221424
self.filter_custom_prompts(_session, CustomPromptTypeEnum.GENERATE_SQL, oid, ds_id)
14231425

1424-
self.init_messages(_session)
1426+
# 意图识别启用时,延迟到意图识别完成后再 init_messages
1427+
if not settings.INTENT_RECOGNITION_ENABLED:
1428+
self.init_messages(_session)
14251429

14261430
# return id
14271431
if in_chat:
@@ -1456,15 +1460,15 @@ def run_task(self, in_chat: bool = True, stream: bool = True,
14561460
self._intent_result['guess_tables']
14571461
)
14581462
# 重新初始化消息,使用更新后的 db_schema
1459-
self.init_messages()
1463+
self.init_messages(_session)
14601464
elif not self.chat_question.db_schema:
14611465
# fallback: 如果没有 guess_tables 且 db_schema 未设置,走原 RAG 流程
14621466
self.chat_question.db_schema = get_table_schema(
14631467
session=_session, current_user=self.current_user, ds=self.ds,
14641468
question=self.chat_question.question
14651469
)
14661470
# 重新初始化消息,使用更新后的 db_schema
1467-
self.init_messages()
1471+
self.init_messages(_session)
14681472
# ===== 意图识别结束 =====
14691473

14701474
# select datasource if datasource is none

frontend/src/i18n/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,9 @@
741741
"FILTER_SQL_EXAMPLE": "Match SQL Examples",
742742
"FILTER_CUSTOM_PROMPT": "Match Custom Prompts",
743743
"EXECUTE_SQL": "Execute SQL",
744-
"GENERATE_PICTURE": "Generate Picture"
744+
"GENERATE_PICTURE": "Generate Picture",
745+
"RECOGNIZE_INTENT": "Recognize Intent",
746+
"GENERATE_CLARIFICATION": "Generate Clarification"
745747
}
746748
},
747749
"about": {

frontend/src/i18n/ko-KR.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,9 @@
741741
"FILTER_SQL_EXAMPLE": "SQL 예시 매칭",
742742
"FILTER_CUSTOM_PROMPT": "사용자 정의 프롬프트 매칭",
743743
"EXECUTE_SQL": "SQL 실행",
744-
"GENERATE_PICTURE": "이미지 생성"
744+
"GENERATE_PICTURE": "이미지 생성",
745+
"RECOGNIZE_INTENT": "의도 인식",
746+
"GENERATE_CLARIFICATION": "명확화 질문 생성"
745747
}
746748
},
747749
"about": {

frontend/src/i18n/zh-CN.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,9 @@
741741
"FILTER_SQL_EXAMPLE": "匹配 SQL 示例",
742742
"FILTER_CUSTOM_PROMPT": "匹配自定义提示词",
743743
"EXECUTE_SQL": "执行 SQL",
744-
"GENERATE_PICTURE": "生成图片"
744+
"GENERATE_PICTURE": "生成图片",
745+
"RECOGNIZE_INTENT": "识别意图",
746+
"GENERATE_CLARIFICATION": "生成澄清问题"
745747
}
746748
},
747749
"about": {

0 commit comments

Comments
 (0)