(session: SessionDep, current_user: CurrentUser, request_question: ChatQuestion,
current_assistant: Optional[CurrentAssistant] = None, in_chat: bool = True,
stream: bool = True,
finish_step: ChatFinishStep = ChatFinishStep.GENERATE_CHART, embedding: bool = False,
return_img: bool = True)
| 275 | |
| 276 | |
| 277 | async def question_answer_inner(session: SessionDep, current_user: CurrentUser, request_question: ChatQuestion, |
| 278 | current_assistant: Optional[CurrentAssistant] = None, in_chat: bool = True, |
| 279 | stream: bool = True, |
| 280 | finish_step: ChatFinishStep = ChatFinishStep.GENERATE_CHART, embedding: bool = False, |
| 281 | return_img: bool = True): |
| 282 | try: |
| 283 | command, text_before_command, record_id, warning_info = parse_quick_command(request_question.question) |
| 284 | if command: |
| 285 | # todo 对话界面下,暂不支持分析和预测,需要改造前端 |
| 286 | if in_chat and (command == QuickCommand.ANALYSIS or command == QuickCommand.PREDICT_DATA): |
| 287 | raise Exception(f'Command: {command.value} temporary not supported') |
| 288 | |
| 289 | if record_id is not None: |
| 290 | # 排除analysis和predict |
| 291 | stmt = select(ChatRecord.id, ChatRecord.chat_id, ChatRecord.analysis_record_id, |
| 292 | ChatRecord.predict_record_id, ChatRecord.regenerate_record_id, |
| 293 | ChatRecord.first_chat).where( |
| 294 | and_(ChatRecord.id == record_id)).order_by(ChatRecord.create_time.desc()) |
| 295 | _record = session.execute(stmt).fetchone() |
| 296 | if not _record: |
| 297 | raise Exception(f'Record id: {record_id} does not exist') |
| 298 | |
| 299 | rec_id, rec_chat_id, rec_analysis_record_id, rec_predict_record_id, rec_regenerate_record_id, rec_first_chat = _record |
| 300 | |
| 301 | if rec_chat_id != request_question.chat_id: |
| 302 | raise Exception(f'Record id: {record_id} does not belong to this chat') |
| 303 | if rec_first_chat: |
| 304 | raise Exception(f'Record id: {record_id} does not support this operation') |
| 305 | |
| 306 | if rec_analysis_record_id: |
| 307 | raise Exception('Analysis record does not support this operation') |
| 308 | if rec_predict_record_id: |
| 309 | raise Exception('Predict data record does not support this operation') |
| 310 | |
| 311 | else: # get last record id |
| 312 | stmt = select(ChatRecord.id, ChatRecord.chat_id, ChatRecord.regenerate_record_id).where( |
| 313 | and_(ChatRecord.chat_id == request_question.chat_id, |
| 314 | ChatRecord.first_chat == False, |
| 315 | ChatRecord.analysis_record_id.is_(None), |
| 316 | ChatRecord.predict_record_id.is_(None))).order_by( |
| 317 | ChatRecord.create_time.desc()).limit(1) |
| 318 | _record = session.execute(stmt).fetchone() |
| 319 | |
| 320 | if not _record: |
| 321 | raise Exception(f'You have not ask any question') |
| 322 | |
| 323 | rec_id, rec_chat_id, rec_regenerate_record_id = _record |
| 324 | |
| 325 | # 没有指定的,就查询上一个 |
| 326 | if not rec_regenerate_record_id: |
| 327 | rec_regenerate_record_id = rec_id |
| 328 | |
| 329 | # 针对已经是重新生成的提问,需要找到原来的提问是什么 |
| 330 | base_question_text = find_base_question(rec_regenerate_record_id, session) |
| 331 | text_before_command = text_before_command + ("\n" if text_before_command else "") + base_question_text |
| 332 | |
| 333 | if command == QuickCommand.REGENERATE: |
| 334 | request_question.question = text_before_command |
no test coverage detected