Skip to content
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
11 changes: 7 additions & 4 deletions common/lib/openai_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
DEFAULT_AZURE_OPENAI_API_VERSION = "2024-10-21"


def get_openai_client(opts=None):
def get_openai_client(opts=None, max_retries=0):
"""
Return an OpenAI-compatible client (OpenAI or AzureOpenAI).
Same client is used for chat and embeddings; LiteLLM proxy supports both.

opts: dict of options. All values are read from opts only.
max_retries: SDK-level retry count for transient 5xx/429 from the
provider/proxy. Defaults to 0 to preserve existing behavior; callers
making idempotent requests (e.g. embeddings) should pass a small value.

Supported keys in opts:
- LITELLM_PROXY_URL, LITELLM_MASTER_KEY -> use LiteLLM proxy (chat + embeddings)
Expand All @@ -46,7 +49,7 @@ def get_openai_client(opts=None):
organization=organization if organization else None,
project=project if project else None,
timeout=120.0,
max_retries=0,
max_retries=max_retries,
)

azure_endpoint = (opts.get("AZURE_OPENAI_ENDPOINT") or "").strip()
Expand All @@ -60,7 +63,7 @@ def get_openai_client(opts=None):
azure_endpoint=azure_endpoint,
api_version=azure_api_version,
timeout=120.0,
max_retries=0,
max_retries=max_retries,
)

openai_api_key = (
Expand All @@ -77,7 +80,7 @@ def get_openai_client(opts=None):
organization=organization if organization else None,
project=project if project else None,
timeout=120.0,
max_retries=0,
max_retries=max_retries,
)

raise ValueError(
Expand Down
5 changes: 3 additions & 2 deletions common/storage/milvus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,9 @@ def save(vcon_uuid: str, opts=default_options) -> None:
logger.info(f"vCon {vcon_uuid} already exists in Milvus collection {collection_name}, skipping")
return

# Initialize OpenAI client (supports LiteLLM proxy via LITELLM_PROXY_URL + LITELLM_MASTER_KEY provided in opts)
openai_client = get_openai_client(opts)
# Initialize OpenAI client (supports LiteLLM proxy via LITELLM_PROXY_URL + LITELLM_MASTER_KEY provided in opts).
# Embeddings are idempotent, so retry transient 5xx/429 from the proxy (Sentry CONSERVER-9G).
openai_client = get_openai_client(opts, max_retries=3)

# Extract text content from vCon
text = extract_text_from_vcon(vcon_dict)
Expand Down
Loading