mirror of
https://github.com/microsoft/autogen.git
synced 2025-08-01 21:32:38 +00:00

* Validate the OpenAI API key format Increase the amount of internal validation for OpenAI API keys. The intent is to shorten the debugging loop in case of typos. The changes do *not* add validation for Azure OpenAI API keys. * Add the validation in `__init__` of `OpenAIClient`. * Introduce the `MOCK_OPEN_AI_API_KEY` constant for testing. * Add unit test coverage for the `is_valid_api_key` function. * Validate the OpenAI API key format Increase the amount of internal validation for OpenAI API keys. The intent is to shorten the debugging loop in case of typos. The changes do *not* add validation for Azure OpenAI API keys. * Add the validation in `__init__` of `OpenAIClient`. * Introduce the `MOCK_OPEN_AI_API_KEY` constant for testing. *Add unit test coverage for the `is_valid_api_key` function. * Log a warning when register a default client fails. * Validate the OpenAI API key format Increase the amount of internal validation for OpenAI API keys. The intent is to shorten the debugging loop in case of typos. The changes do *not* add validation for Azure OpenAI API keys. * Add the validation in `__init__` of `OpenAIClient`. We'll log a warning when the OpenAI API key isn't valid. * Introduce the `MOCK_OPEN_AI_API_KEY` constant for testing. * Add unit test coverage for the `is_valid_api_key` function. * Check for OpenAI base_url before API key validation --------- Co-authored-by: Chi Wang <wang.chi@microsoft.com>
27 lines
1.1 KiB
Python
27 lines
1.1 KiB
Python
import pytest
|
|
|
|
skip_openai = False
|
|
skip_redis = False
|
|
skip_docker = False
|
|
|
|
MOCK_OPEN_AI_API_KEY = "sk-mockopenaiAPIkeyinexpectedformatfortestingonly"
|
|
|
|
|
|
# Registers command-line options like '--skip-openai' and '--skip-redis' via pytest hook.
|
|
# When these flags are set, it indicates that tests requiring OpenAI or Redis (respectively) should be skipped.
|
|
def pytest_addoption(parser):
|
|
parser.addoption("--skip-openai", action="store_true", help="Skip all tests that require openai")
|
|
parser.addoption("--skip-redis", action="store_true", help="Skip all tests that require redis")
|
|
parser.addoption("--skip-docker", action="store_true", help="Skip all tests that require docker")
|
|
|
|
|
|
# pytest hook implementation extracting command line args and exposing it globally
|
|
@pytest.hookimpl(tryfirst=True)
|
|
def pytest_configure(config):
|
|
global skip_openai
|
|
skip_openai = config.getoption("--skip-openai", False)
|
|
global skip_redis
|
|
skip_redis = config.getoption("--skip-redis", False)
|
|
global skip_docker
|
|
skip_docker = config.getoption("--skip-docker", False)
|