MCPcopy Create free account
hub / github.com/dataease/SQLBot / save_recommend_question_answer

Function save_recommend_question_answer

backend/apps/chat/curd/chat.py:969–1007  ·  view source on GitHub ↗
(session: SessionDep, record_id: int,
                                   answer: dict = None, articles_number: Optional[int] = 4)

Source from the content-addressed store, hash-verified

967
968
969def 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
1010def save_sql(session: SessionDep, record_id: int, sql: str) -> ChatRecord:

Callers 1

Calls 5

extract_nested_jsonFunction · 0.90
get_chat_record_by_idFunction · 0.85
getMethod · 0.65
updateFunction · 0.50
valuesMethod · 0.45

Tested by

no test coverage detected