Update comments (#4569)

### What problem does this PR solve?

Add license statement.

### Type of change

- [x] Refactoring

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2025-01-21 20:52:28 +08:00
committed by GitHub
parent 583050a876
commit 3894de895b
86 changed files with 1034 additions and 145 deletions

View File

@ -1,3 +1,19 @@
#
# 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.
#
import json
from .base import Base
from .chunk import Chunk
@ -32,7 +48,6 @@ class Document(Base):
res_dict.pop(k)
super().__init__(rag, res_dict)
def update(self, update_message: dict):
res = self.put(f'/datasets/{self.dataset_id}/documents/{self.id}',
update_message)
@ -48,29 +63,28 @@ class Document(Base):
except json.JSONDecodeError:
return res.content
def list_chunks(self,page=1, page_size=30, keywords=""):
data={"keywords": keywords,"page":page,"page_size":page_size}
def list_chunks(self, page=1, page_size=30, keywords=""):
data = {"keywords": keywords, "page": page, "page_size": page_size}
res = self.get(f'/datasets/{self.dataset_id}/documents/{self.id}/chunks', data)
res = res.json()
if res.get("code") == 0:
chunks=[]
chunks = []
for data in res["data"].get("chunks"):
chunk = Chunk(self.rag,data)
chunk = Chunk(self.rag, data)
chunks.append(chunk)
return chunks
raise Exception(res.get("message"))
def add_chunk(self, content: str, important_keywords: list[str] = [], questions: list[str] = []):
res = self.post(f'/datasets/{self.dataset_id}/documents/{self.id}/chunks',
{"content":content,"important_keywords":important_keywords, "questions": questions})
{"content": content, "important_keywords": important_keywords, "questions": questions})
res = res.json()
if res.get("code") == 0:
return Chunk(self.rag,res["data"].get("chunk"))
return Chunk(self.rag, res["data"].get("chunk"))
raise Exception(res.get("message"))
def delete_chunks(self,ids:list[str] | None = None):
res = self.rm(f"/datasets/{self.dataset_id}/documents/{self.id}/chunks",{"chunk_ids":ids})
def delete_chunks(self, ids: list[str] | None = None):
res = self.rm(f"/datasets/{self.dataset_id}/documents/{self.id}/chunks", {"chunk_ids": ids})
res = res.json()
if res.get("code")!=0:
raise Exception(res.get("message"))
if res.get("code") != 0:
raise Exception(res.get("message"))