Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

add progress bar to upsert from CLI #88

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fastapi = "^0.92.0"
uvicorn = "^0.20.0"
tenacity = "^8.2.1"
sse-starlette = "^1.6.5"
types-tqdm = "^4.61.0"


[tool.poetry.group.dev.dependencies]
Expand Down
12 changes: 10 additions & 2 deletions src/resin_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import requests
from dotenv import load_dotenv
from tqdm import tqdm

import pandas as pd
import openai
Expand Down Expand Up @@ -119,7 +120,8 @@ def new(index_name, tokenizer_model):
help="Index name",
)
@click.option("--tokenizer-model", default="gpt-3.5-turbo", help="Tokenizer model")
def upsert(index_name, data_path, tokenizer_model):
@click.option("--batch-size", default=10, help="Batch size for upsert")
def upsert(index_name, data_path, tokenizer_model, batch_size):
if index_name is None:
msg = ("Index name is not provided, please provide it with" +
' --index-name or set it with env var + '
Expand Down Expand Up @@ -178,7 +180,13 @@ def upsert(index_name, data_path, tokenizer_model):
click.echo(click.style(f"\nTotal records: {len(data)}"))
click.confirm(click.style("\nDoes this data look right?", fg="red"),
abort=True)
kb.upsert(data)

pbar = tqdm(total=len(data), desc="Upserting documents")
for i in range(0, len(data), batch_size):
batch = data[i:i + batch_size]
kb.upsert(batch)
pbar.update(len(batch))

click.echo(click.style("Success!", fg="green"))


Expand Down