Skip to content

Commit 245df75

Browse files
committed
easier version: detect chunking_func result is coroutine or not
1 parent d137ba5 commit 245df75

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

lightrag/lightrag.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
from inspect import iscoroutinefunction
43
import traceback
54
import asyncio
65
import configparser
@@ -1758,24 +1757,17 @@ async def process_document(
17581757
content = content_data["content"]
17591758

17601759
# Generate chunks from document
1761-
if iscoroutinefunction(self.chunking_func):
1762-
chunks = await self.chunking_func(
1763-
self.tokenizer,
1764-
content,
1765-
split_by_character,
1766-
split_by_character_only,
1767-
self.chunk_overlap_token_size,
1768-
self.chunk_token_size,
1769-
)
1770-
else:
1771-
chunks = self.chunking_func(
1772-
self.tokenizer,
1773-
content,
1774-
split_by_character,
1775-
split_by_character_only,
1776-
self.chunk_overlap_token_size,
1777-
self.chunk_token_size,
1778-
)
1760+
chunks = self.chunking_func(
1761+
self.tokenizer,
1762+
content,
1763+
split_by_character,
1764+
split_by_character_only,
1765+
self.chunk_overlap_token_size,
1766+
self.chunk_token_size,
1767+
)
1768+
# 判断chunks是否是异步异步函数的返回
1769+
if asyncio.iscoroutine(chunks):
1770+
chunks = await chunks
17791771
chunks: dict[str, Any] = {
17801772
compute_mdhash_id(dp["content"], prefix="chunk-"): {
17811773
**dp,

0 commit comments

Comments
 (0)