From d454ffbc751126de495a388df20aab5af3bab9ab Mon Sep 17 00:00:00 2001 From: ulleo Date: Wed, 25 Jun 2025 16:42:05 +0800 Subject: [PATCH] feat: modify chat & predict template --- backend/apps/chat/curd/chat.py | 26 +++++++++++++++++--------- backend/template.yaml | 1 + 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/backend/apps/chat/curd/chat.py b/backend/apps/chat/curd/chat.py index f3c69256..ee10d7d6 100644 --- a/backend/apps/chat/curd/chat.py +++ b/backend/apps/chat/curd/chat.py @@ -74,8 +74,8 @@ def list_records(session: SessionDep, chart_id: int, current_user: CurrentUser) return record_list -def create_chat(session: SessionDep, current_user: CurrentUser, create_chat_obj: CreateChat) -> ChatInfo: - if not create_chat_obj.datasource: +def create_chat(session: SessionDep, current_user: CurrentUser, create_chat_obj: CreateChat, require_datasource: bool = True) -> ChatInfo: + if not create_chat_obj.datasource and require_datasource: raise Exception("Datasource cannot be None") if not create_chat_obj.question or create_chat_obj.question.strip() == '': @@ -83,15 +83,16 @@ def create_chat(session: SessionDep, current_user: CurrentUser, create_chat_obj: chat = Chat(create_time=datetime.datetime.now(), create_by=current_user.id, - brief=create_chat_obj.question.strip()[:20], - datasource=create_chat_obj.datasource) + brief=create_chat_obj.question.strip()[:20]) + ds: CoreDatasource = None + if create_chat_obj.datasource: + chat.datasource = create_chat_obj.datasource + ds = session.query(CoreDatasource).filter(CoreDatasource.id == create_chat_obj.datasource).first() - ds = session.query(CoreDatasource).filter(CoreDatasource.id == create_chat_obj.datasource).first() + if not ds: + raise Exception(f"Datasource with id {create_chat_obj.datasource} not found") - if not ds: - raise Exception(f"Datasource with id {create_chat_obj.datasource} not found") - - chat.engine_type = ds.type_name + chat.engine_type = ds.type_name chat_info = ChatInfo(**chat.model_dump()) @@ -101,6 +102,13 @@ def create_chat(session: SessionDep, current_user: CurrentUser, create_chat_obj: chat_info.id = chat.id session.commit() + if not create_chat_obj.datasource: + # use AI to get ds + + if not ds: + raise Exception(f"Datasource with id {create_chat_obj.datasource} not found") + + chat_info.datasource_exists = True chat_info.datasource_name = ds.name diff --git a/backend/template.yaml b/backend/template.yaml index 71014c1f..01e33956 100644 --- a/backend/template.yaml +++ b/backend/template.yaml @@ -138,6 +138,7 @@ template: ```json 无法预测或者不支持预测的数据请直接返回:"抱歉,该数据无法进行预测。(有原因则返回无法预测的原因)" + 不需要返回原有数据,直接返回预测的部份 user: | ### 请使用 i18n: {lang} 对应的语言输出你的结果