add tqdm to embeddings (#7205)

for longer running embeddings, can be helpful to visualize
This commit is contained in:
Harrison Chase 2023-07-05 12:04:22 -04:00 committed by GitHub
parent 6fc24743b7
commit 7b585c7585
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -298,7 +298,13 @@ class OpenAIEmbeddings(BaseModel, Embeddings):
batched_embeddings = []
_chunk_size = chunk_size or self.chunk_size
for i in range(0, len(tokens), _chunk_size):
try:
import tqdm
_iter = tqdm.tqdm(range(0, len(tokens), _chunk_size))
except ImportError:
_iter = range(0, len(tokens), _chunk_size)
for i in _iter:
response = embed_with_retry(
self,
input=tokens[i : i + _chunk_size],