diff --git a/backend/apps/chat/api/chat.py b/backend/apps/chat/api/chat.py index 56cdfcff..3e0e60d7 100644 --- a/backend/apps/chat/api/chat.py +++ b/backend/apps/chat/api/chat.py @@ -12,7 +12,7 @@ from starlette.responses import JSONResponse from apps.chat.curd.chat import list_chats, get_chat_with_records, create_chat, rename_chat, \ delete_chat, get_chat_chart_data, get_chat_predict_data, get_chat_with_records_with_data, get_chat_record_by_id, \ - format_json_data, format_json_list_data, get_chart_config, list_recent_questions + format_json_data, format_json_list_data, get_chart_config, list_recent_questions,get_chat as get_chat_exec from apps.chat.models.chat_model import CreateChat, ChatRecord, RenameChat, ChatQuestion, AxisObj, QuickCommand, \ ChatInfo, Chat, ChatFinishStep from apps.chat.task.llm import LLMService diff --git a/backend/apps/chat/curd/chat.py b/backend/apps/chat/curd/chat.py index f93ad18e..ae425ea0 100644 --- a/backend/apps/chat/curd/chat.py +++ b/backend/apps/chat/curd/chat.py @@ -1,5 +1,5 @@ import datetime -from typing import List +from typing import List, Optional import orjson import sqlparse @@ -650,7 +650,7 @@ def save_select_datasource_answer(session: SessionDep, record_id: int, answer: s def save_recommend_question_answer(session: SessionDep, record_id: int, - answer: dict = None) -> ChatRecord: + answer: dict = None, articles_number: Optional[int] = 4) -> ChatRecord: if not record_id: raise Exception("Record id cannot be None") @@ -673,12 +673,19 @@ def save_recommend_question_answer(session: SessionDep, record_id: int, ) session.execute(stmt) - session.commit() record = get_chat_record_by_id(session, record_id) record.recommended_question_answer = recommended_question_answer record.recommended_question = recommended_question + if articles_number > 4: + stmt_chat = update(Chat).where(and_(Chat.id == record.chat_id)).values( + recommended_question_answer=recommended_question_answer, + recommended_question=recommended_question, + recommended_generate=True + ) + session.execute(stmt_chat) + session.commit() return record diff --git a/backend/apps/chat/models/chat_model.py b/backend/apps/chat/models/chat_model.py index de7139d3..fdcd1a40 100644 --- a/backend/apps/chat/models/chat_model.py +++ b/backend/apps/chat/models/chat_model.py @@ -86,6 +86,9 @@ class Chat(SQLModel, table=True): origin: Optional[int] = Field( sa_column=Column(Integer, nullable=False, default=0)) # 0: default, 1: mcp, 2: assistant brief_generate: bool = Field(default=False) + recommended_question_answer: str = Field(sa_column=Column(Text, nullable=True)) + recommended_question: str = Field(sa_column=Column(Text, nullable=True)) + recommended_generate: bool = Field(default=False) class ChatRecord(SQLModel, table=True): @@ -172,6 +175,8 @@ class ChatInfo(BaseModel): ds_type: str = '' datasource_name: str = '' datasource_exists: bool = True + recommended_question: Optional[str] = None + recommended_generate: Optional[bool] = False records: List[ChatRecord | dict] = [] diff --git a/backend/apps/chat/task/llm.py b/backend/apps/chat/task/llm.py index 66d85e63..c5badacc 100644 --- a/backend/apps/chat/task/llm.py +++ b/backend/apps/chat/task/llm.py @@ -397,7 +397,7 @@ class LLMService: reasoning_content=full_thinking_text, token_usage=token_usage) self.record = save_recommend_question_answer(session=_session, record_id=self.record.id, - answer={'content': full_guess_text}) + answer={'content': full_guess_text}, articles_number=self.articles_number) yield {'recommended_question': self.record.recommended_question} diff --git a/frontend/src/api/chat.ts b/frontend/src/api/chat.ts index d64fee6d..b3d23782 100644 --- a/frontend/src/api/chat.ts +++ b/frontend/src/api/chat.ts @@ -139,6 +139,8 @@ export class Chat { datasource?: number engine_type?: string ds_type?: string + recommended_question?: string | undefined + recommended_generate?: boolean | undefined constructor() constructor( @@ -200,7 +202,9 @@ export class ChatInfo extends Chat { ds_type?: string, datasource_name?: string, datasource_exists: boolean = true, - records: Array = [] + records: Array = [], + recommended_question?: string | undefined, + recommended_generate?: boolean | undefined ) { super() if (param1 !== undefined) { @@ -213,6 +217,8 @@ export class ChatInfo extends Chat { this.datasource = param1.datasource this.engine_type = param1.engine_type this.ds_type = param1.ds_type + this.recommended_question = recommended_question + this.recommended_generate = recommended_generate } else { this.id = param1 this.create_time = getDate(create_time) @@ -222,6 +228,8 @@ export class ChatInfo extends Chat { this.datasource = datasource this.engine_type = engine_type this.ds_type = ds_type + this.recommended_question = recommended_question + this.recommended_generate = recommended_generate } } this.datasource_name = datasource_name @@ -287,7 +295,9 @@ export const chatApi = { data.ds_type, data.datasource_name, data.datasource_exists, - toChatRecordList(data.records) + toChatRecordList(data.records), + data.recommended_question, + data.recommended_generate ) }, toChatInfoList: (list: any[] = []): ChatInfo[] => { diff --git a/frontend/src/views/chat/RecommendQuestionQuick.vue b/frontend/src/views/chat/RecommendQuestionQuick.vue index a9250f82..bd4436de 100644 --- a/frontend/src/views/chat/RecommendQuestionQuick.vue +++ b/frontend/src/views/chat/RecommendQuestionQuick.vue @@ -1,7 +1,7 @@