mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: OpenAI Clients accepting api_key callback (#1139)
* openai clients accepting callable * fixes * version checks
This commit is contained in:
committed by
GitHub
Unverified
parent
ee8d95b3dc
commit
4e6ae443cf
@@ -1258,3 +1258,18 @@ async def test_openai_assistants_client_agent_level_tool_persistence():
|
||||
assert second_response.text is not None
|
||||
# Should use the agent-level weather tool again
|
||||
assert any(term in second_response.text.lower() for term in ["miami", "sunny", "72"])
|
||||
|
||||
|
||||
# Callable API Key Tests
|
||||
def test_openai_assistants_client_with_callable_api_key() -> None:
|
||||
"""Test OpenAIAssistantsClient initialization with callable API key."""
|
||||
|
||||
async def get_api_key() -> str:
|
||||
return "test-api-key-123"
|
||||
|
||||
client = OpenAIAssistantsClient(model_id="gpt-4o", api_key=get_api_key)
|
||||
|
||||
# Verify client was created successfully
|
||||
assert client.model_id == "gpt-4o"
|
||||
# OpenAI SDK now manages callable API keys internally
|
||||
assert client.client is not None
|
||||
|
||||
@@ -783,3 +783,17 @@ def test_openai_content_parser_data_content_image(openai_unit_test_env: dict[str
|
||||
# Should use custom filename
|
||||
assert result["type"] == "file"
|
||||
assert result["file"]["filename"] == "report.pdf"
|
||||
|
||||
|
||||
def test_openai_chat_client_with_callable_api_key() -> None:
|
||||
"""Test OpenAIChatClient initialization with callable API key."""
|
||||
|
||||
async def get_api_key() -> str:
|
||||
return "test-api-key-123"
|
||||
|
||||
client = OpenAIChatClient(model_id="gpt-4o", api_key=get_api_key)
|
||||
|
||||
# Verify client was created successfully
|
||||
assert client.model_id == "gpt-4o"
|
||||
# OpenAI SDK now manages callable API keys internally
|
||||
assert client.client is not None
|
||||
|
||||
@@ -2088,3 +2088,17 @@ def test_prepare_options_store_parameter_handling() -> None:
|
||||
options = client._prepare_options(messages, chat_options) # type: ignore
|
||||
assert options["store"] is False
|
||||
assert "previous_response_id" not in options
|
||||
|
||||
|
||||
def test_openai_responses_client_with_callable_api_key() -> None:
|
||||
"""Test OpenAIResponsesClient initialization with callable API key."""
|
||||
|
||||
async def get_api_key() -> str:
|
||||
return "test-api-key-123"
|
||||
|
||||
client = OpenAIResponsesClient(model_id="gpt-4o", api_key=get_api_key)
|
||||
|
||||
# Verify client was created successfully
|
||||
assert client.model_id == "gpt-4o"
|
||||
# OpenAI SDK now manages callable API keys internally
|
||||
assert client.client is not None
|
||||
|
||||
Reference in New Issue
Block a user