MCPcopy Index your code
hub / github.com/1Panel-dev/MaxKB / save_problem

Function save_problem

apps/knowledge/task/handler.py:111–134  ·  view source on GitHub ↗
(knowledge_id, document_id, paragraph_id, problem)

Source from the content-addressed store, hash-verified

109
110
111def 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)))

Callers 1

Calls 3

searchMethod · 0.80
saveMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected