How many parallel requests can I safely make to this API call?
from tqdm import tqdm
from concurrent.futures import ThreadPoolExecutor
# Define the processing function
def process_item(i):
try:
tagged_sentence = gemini_model_generative(prompt.format(i.tagged_source, i.temp_target))
return tagged_sentence
except Exception as e:
return f"Failed ID {i.id}: {e}"
# Main execution
if __name__ == "__main__":
with ThreadPoolExecutor(max_workers=5) as executor: # Adjust max_workers based on your system
futures = list(tqdm(executor.map(process_item, with_tagged_seg), total=len(with_tagged_seg)))