mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
feat: modify chat & predict template
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -138,6 +138,7 @@ template:
|
||||
```json
|
||||
|
||||
无法预测或者不支持预测的数据请直接返回:"抱歉,该数据无法进行预测。(有原因则返回无法预测的原因)"
|
||||
不需要返回原有数据,直接返回预测的部份
|
||||
|
||||
user: |
|
||||
### 请使用 i18n: {lang} 对应的语言输出你的结果
|
||||
|
||||
Reference in New Issue
Block a user