2025-01-21 20:52:28 +08:00
|
|
|
#
|
|
|
|
# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
|
2024-09-14 13:24:21 +08:00
|
|
|
from .base import Base
|
|
|
|
|
2025-03-13 19:06:50 +08:00
|
|
|
class ChunkUpdateError(Exception):
|
|
|
|
def __init__(self, code=None, message=None, details=None):
|
|
|
|
self.code = code
|
|
|
|
self.message = message
|
|
|
|
self.details = details
|
|
|
|
super().__init__(message)
|
2024-09-14 13:24:21 +08:00
|
|
|
|
|
|
|
class Chunk(Base):
|
|
|
|
def __init__(self, rag, res_dict):
|
|
|
|
self.id = ""
|
2024-09-18 11:08:19 +08:00
|
|
|
self.content = ""
|
|
|
|
self.important_keywords = []
|
2024-12-05 14:51:19 +08:00
|
|
|
self.questions = []
|
2024-09-14 13:24:21 +08:00
|
|
|
self.create_time = ""
|
2024-09-19 12:52:35 +08:00
|
|
|
self.create_timestamp = 0.0
|
2024-10-23 12:02:18 +08:00
|
|
|
self.dataset_id = None
|
2024-09-18 11:08:19 +08:00
|
|
|
self.document_name = ""
|
|
|
|
self.document_id = ""
|
2024-10-23 12:02:18 +08:00
|
|
|
self.available = True
|
2024-09-18 11:08:19 +08:00
|
|
|
for k in list(res_dict.keys()):
|
|
|
|
if k not in self.__dict__:
|
|
|
|
res_dict.pop(k)
|
2024-09-14 13:24:21 +08:00
|
|
|
super().__init__(rag, res_dict)
|
2024-09-18 11:08:19 +08:00
|
|
|
|
2025-01-21 20:52:28 +08:00
|
|
|
def update(self, update_message: dict):
|
|
|
|
res = self.put(f"/datasets/{self.dataset_id}/documents/{self.document_id}/chunks/{self.id}", update_message)
|
2024-09-18 11:08:19 +08:00
|
|
|
res = res.json()
|
2025-01-21 20:52:28 +08:00
|
|
|
if res.get("code") != 0:
|
2025-03-13 19:06:50 +08:00
|
|
|
raise ChunkUpdateError(
|
|
|
|
code=res.get("code"),
|
|
|
|
message=res.get("message"),
|
|
|
|
details=res.get("details")
|
|
|
|
)
|