Refactor Azure OpenAI client creation to support client_configs merging

- Handle None client_configs case
- Merge configs with explicit params
- Override client_configs with params
- Use dict unpacking for client init
- Maintain parameter precedence
This commit is contained in:
yangdx 2025-11-21 19:14:16 +08:00
parent 0c4cba3860
commit 45f4f82392

View file

@ -107,13 +107,26 @@ def create_openai_async_client(
"LLM_BINDING_API_KEY" "LLM_BINDING_API_KEY"
) )
return AsyncAzureOpenAI( if client_configs is None:
azure_endpoint=base_url, client_configs = {}
azure_deployment=azure_deployment,
api_key=api_key, # Create a merged config dict with precedence: explicit params > client_configs
api_version=api_version, merged_configs = {
timeout=timeout, **client_configs,
) "api_key": api_key,
}
# Add explicit parameters (override client_configs)
if base_url is not None:
merged_configs["azure_endpoint"] = base_url
if azure_deployment is not None:
merged_configs["azure_deployment"] = azure_deployment
if api_version is not None:
merged_configs["api_version"] = api_version
if timeout is not None:
merged_configs["timeout"] = timeout
return AsyncAzureOpenAI(**merged_configs)
else: else:
if not api_key: if not api_key:
api_key = os.environ["OPENAI_API_KEY"] api_key = os.environ["OPENAI_API_KEY"]