(knowledge_id, document_id, paragraph_id, problem)
| 109 | |
| 110 | |
| 111 | def save_problem(knowledge_id, document_id, paragraph_id, problem): |
| 112 | from knowledge.serializers.paragraph import ParagraphSerializers |
| 113 | |
| 114 | # print(f"knowledge_id: {knowledge_id}") |
| 115 | # print(f"document_id: {document_id}") |
| 116 | # print(f"paragraph_id: {paragraph_id}") |
| 117 | # print(f"problem: {problem}") |
| 118 | problem = re.sub(r"^\d+\.\s*", "", problem) |
| 119 | match = re.search(r"<question>(.*?)<\/question>", problem, flags=re.DOTALL) |
| 120 | problem = match.group(1) if match else None |
| 121 | if problem is None or len(problem) == 0: |
| 122 | return |
| 123 | try: |
| 124 | workspace_id = QuerySet(Knowledge).filter(id=knowledge_id).first().workspace_id |
| 125 | ParagraphSerializers.Problem( |
| 126 | data={ |
| 127 | "workspace_id": workspace_id, |
| 128 | "knowledge_id": knowledge_id, |
| 129 | "document_id": document_id, |
| 130 | "paragraph_id": paragraph_id, |
| 131 | } |
| 132 | ).save(instance={"content": problem}, with_valid=True) |
| 133 | except Exception as e: |
| 134 | maxkb_logger.error(_("Association problem failed {error}").format(error=str(e))) |
no test coverage detected