Skip to content

Commit

Permalink
robust json parsing & entity extraction progress log
Browse files Browse the repository at this point in the history
  • Loading branch information
rangehow committed Oct 18, 2024
2 parents 3c022e2 + a96899b commit ad57a9d
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions nano_graphrag/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,23 +229,26 @@ async def __call__(self, *args, **kwargs) -> np.ndarray:


# Decorators ------------------------------------------------------------------------
def limit_async_func_call(max_size: int, waitting_time: float = 0.0001):
"""Add restriction of maximum async calling times for a async func"""


def limit_async_func_call(max_size: int):
"""Add restriction of maximum async calling times for a async func using Semaphore"""

def final_decorator(func):
# Create a semaphore with the given max_size
semaphore = asyncio.Semaphore(max_size)
def final_decro(func):
"""Not using async.Semaphore to aovid use nest-asyncio"""
__current_size = 0

@wraps(func)
async def wrapped_func(*args, **kwargs):
async with semaphore: # Acquire the semaphore
return await func(*args, **kwargs) # Run the async function
async def wait_func(*args, **kwargs):
nonlocal __current_size
while __current_size >= max_size:
await asyncio.sleep(waitting_time)
__current_size += 1
result = await func(*args, **kwargs)
__current_size -= 1
return result

return wrapped_func
return wait_func

return final_decorator
return final_decro


def wrap_embedding_func_with_attrs(**kwargs):
Expand Down

0 comments on commit ad57a9d

Please sign in to comment.