Feat: add_chunk supports add image (#13629)

### What problem does this PR solve?

Add_chunk supports add image.

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

Co-authored-by: Yingfeng <yingfeng.zhang@gmail.com>
This commit is contained in:
Yongteng Lei
2026-03-16 20:15:36 +08:00
committed by GitHub
parent 09ff1bc2b0
commit af7e24ba8c
6 changed files with 95 additions and 9 deletions

View File

@ -87,8 +87,11 @@ class Document(Base):
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})
def add_chunk(self, content: str, important_keywords: list[str] = [], questions: list[str] = [], image_base64: str | None = None):
body = {"content": content, "important_keywords": important_keywords, "questions": questions}
if image_base64 is not None:
body["image_base64"] = image_base64
res = self.post(f"/datasets/{self.dataset_id}/documents/{self.id}/chunks", body)
res = res.json()
if res.get("code") == 0:
return Chunk(self.rag, res["data"].get("chunk"))