Fix: Document.update() now refreshes object data (#8068)

### What problem does this PR solve?

#8067 

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
Liu An
2025-06-05 12:46:29 +08:00
committed by GitHub
parent 640fca7dc9
commit 8b7c424617
2 changed files with 123 additions and 166 deletions

View File

@ -15,6 +15,7 @@
#
import json
from .base import Base
from .chunk import Chunk
@ -52,12 +53,14 @@ class Document(Base):
if "meta_fields" in update_message:
if not isinstance(update_message["meta_fields"], dict):
raise Exception("meta_fields must be a dictionary")
res = self.put(f'/datasets/{self.dataset_id}/documents/{self.id}',
update_message)
res = self.put(f"/datasets/{self.dataset_id}/documents/{self.id}", update_message)
res = res.json()
if res.get("code") != 0:
raise Exception(res["message"])
self._update_from_dict(self.rag, res.get("data", {}))
return self
def download(self):
res = self.get(f"/datasets/{self.dataset_id}/documents/{self.id}")
try:
@ -66,9 +69,9 @@ class Document(Base):
except json.JSONDecodeError:
return res.content
def list_chunks(self, page=1, page_size=30, keywords="", id = ""):
def list_chunks(self, page=1, page_size=30, keywords="", id=""):
data = {"keywords": keywords, "page": page, "page_size": page_size, "id": id}
res = self.get(f'/datasets/{self.dataset_id}/documents/{self.id}/chunks', data)
res = self.get(f"/datasets/{self.dataset_id}/documents/{self.id}/chunks", data)
res = res.json()
if res.get("code") == 0:
chunks = []
@ -79,8 +82,7 @@ class Document(Base):
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})
res = self.post(f"/datasets/{self.dataset_id}/documents/{self.id}/chunks", {"content": content, "important_keywords": important_keywords, "questions": questions})
res = res.json()
if res.get("code") == 0:
return Chunk(self.rag, res["data"].get("chunk"))