(session: SessionDep, record_id: int,
answer: dict = None, articles_number: Optional[int] = 4)
| 967 | |
| 968 | |
| 969 | def save_recommend_question_answer(session: SessionDep, record_id: int, |
| 970 | answer: dict = None, articles_number: Optional[int] = 4) -> ChatRecord: |
| 971 | if not record_id: |
| 972 | raise Exception("Record id cannot be None") |
| 973 | |
| 974 | recommended_question_answer = orjson.dumps(answer).decode() |
| 975 | |
| 976 | json_str = '[]' |
| 977 | if answer and answer.get('content') and answer.get('content') != '': |
| 978 | try: |
| 979 | json_str = extract_nested_json(answer.get('content')) |
| 980 | |
| 981 | if not json_str: |
| 982 | json_str = '[]' |
| 983 | except Exception as e: |
| 984 | pass |
| 985 | recommended_question = json_str |
| 986 | |
| 987 | stmt = update(ChatRecord).where(and_(ChatRecord.id == record_id)).values( |
| 988 | recommended_question_answer=recommended_question_answer, |
| 989 | recommended_question=recommended_question, |
| 990 | ) |
| 991 | |
| 992 | session.execute(stmt) |
| 993 | session.commit() |
| 994 | |
| 995 | record = get_chat_record_by_id(session, record_id) |
| 996 | record.recommended_question_answer = recommended_question_answer |
| 997 | record.recommended_question = recommended_question |
| 998 | if articles_number > 4: |
| 999 | stmt_chat = update(Chat).where(and_(Chat.id == record.chat_id)).values( |
| 1000 | recommended_question_answer=recommended_question_answer, |
| 1001 | recommended_question=recommended_question, |
| 1002 | recommended_generate=True |
| 1003 | ) |
| 1004 | session.execute(stmt_chat) |
| 1005 | session.commit() |
| 1006 | |
| 1007 | return record |
| 1008 | |
| 1009 | |
| 1010 | def save_sql(session: SessionDep, record_id: int, sql: str) -> ChatRecord: |
no test coverage detected