(session: SessionDep, current_user: CurrentUser, question: ChatQuestion)
| 774 | |
| 775 | |
| 776 | def save_question(session: SessionDep, current_user: CurrentUser, question: ChatQuestion) -> ChatRecord: |
| 777 | if not question.chat_id: |
| 778 | raise Exception("ChatId cannot be None") |
| 779 | if not question.question or question.question.strip() == '': |
| 780 | raise Exception("Question cannot be Empty") |
| 781 | |
| 782 | # chat = session.query(Chat).filter(Chat.id == question.chat_id).first() |
| 783 | chat: Chat = session.get(Chat, question.chat_id) |
| 784 | if not chat: |
| 785 | raise Exception(f"Chat with id {question.chat_id} not found") |
| 786 | |
| 787 | record = ChatRecord() |
| 788 | record.question = question.question |
| 789 | record.chat_id = chat.id |
| 790 | record.create_time = datetime.datetime.now() |
| 791 | record.create_by = current_user.id |
| 792 | record.datasource = chat.datasource |
| 793 | record.engine_type = chat.engine_type |
| 794 | record.ai_modal_id = question.ai_modal_id |
| 795 | record.regenerate_record_id = question.regenerate_record_id |
| 796 | |
| 797 | result = ChatRecord(**record.model_dump()) |
| 798 | |
| 799 | session.add(record) |
| 800 | session.flush() |
| 801 | session.refresh(record) |
| 802 | result.id = record.id |
| 803 | session.commit() |
| 804 | |
| 805 | return result |
| 806 | |
| 807 | |
| 808 | def save_analysis_predict_record(session: SessionDep, base_record: ChatRecord, action_type: str) -> ChatRecord: |
no test coverage detected