import asyncio from openai import AsyncOpenAI import huggingface_hub from tqdm.asyncio import tqdm_asyncio # max concurrency sem = asyncio.Semaphore(5) # Initialize the client using the Hugging Face Inference API client = AsyncOpenAI( base_url="https://api-inference.huggingface.co/v1/", api_key=huggingface_hub.get_token(), ) # Combined async helper method to handle concurrent scoring and async def limited_get_score(dataset): async def gen(sample): async with sem: res = await get_eval_score(sample) progress_bar.update(1) return res progress_bar = tqdm_asyncio(total=len(dataset), desc="Scoring", unit="sample") tasks = [gen(text) for text in dataset] responses = await tqdm_asyncio.gather(*tasks) progress_bar.close() return responses