Skip to content

Commit 535eeae

Browse files
authored
Merge branch 'main' into pgvector_tensor_embeddding_fix
2 parents e7ddf11 + 857830c commit 535eeae

File tree

3 files changed

+3
-39
lines changed

3 files changed

+3
-39
lines changed

autogen/oai/client.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from autogen.cache import Cache
1313
from autogen.io.base import IOStream
1414
from autogen.logger.logger_utils import get_current_ts
15-
from autogen.oai.openai_utils import OAI_PRICE1K, get_key, is_valid_api_key
15+
from autogen.oai.openai_utils import OAI_PRICE1K, get_key
1616
from autogen.runtime_logging import log_chat_completion, log_new_client, log_new_wrapper, logging_enabled
1717
from autogen.token_count_utils import count_token
1818

@@ -165,11 +165,7 @@ class OpenAIClient:
165165

166166
def __init__(self, client: Union[OpenAI, AzureOpenAI]):
167167
self._oai_client = client
168-
if (
169-
not isinstance(client, openai.AzureOpenAI)
170-
and str(client.base_url).startswith(OPEN_API_BASE_URL_PREFIX)
171-
and not is_valid_api_key(self._oai_client.api_key)
172-
):
168+
if not isinstance(client, openai.AzureOpenAI) and str(client.base_url).startswith(OPEN_API_BASE_URL_PREFIX):
173169
logger.warning(
174170
"The API key specified is not a valid OpenAI format; it won't work with the OpenAI-hosted model."
175171
)

autogen/oai/openai_utils.py

-13
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,6 @@ def get_key(config: Dict[str, Any]) -> str:
9999
return json.dumps(config, sort_keys=True)
100100

101101

102-
def is_valid_api_key(api_key: str) -> bool:
103-
"""Determine if input is valid OpenAI API key.
104-
105-
Args:
106-
api_key (str): An input string to be validated.
107-
108-
Returns:
109-
bool: A boolean that indicates if input is valid OpenAI API key.
110-
"""
111-
api_key_re = re.compile(r"^sk-([A-Za-z0-9]+(-+[A-Za-z0-9]+)*-)?[A-Za-z0-9]{32,}$")
112-
return bool(re.fullmatch(api_key_re, api_key))
113-
114-
115102
def get_config_list(
116103
api_keys: List[str],
117104
base_urls: Optional[List[str]] = None,

test/oai/test_utils.py

+1-20
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from conftest import MOCK_OPEN_AI_API_KEY
1313

1414
import autogen # noqa: E402
15-
from autogen.oai.openai_utils import DEFAULT_AZURE_API_VERSION, filter_config, is_valid_api_key
15+
from autogen.oai.openai_utils import DEFAULT_AZURE_API_VERSION, filter_config
1616

1717
# Example environment variables
1818
ENV_VARS = {
@@ -414,24 +414,5 @@ def test_tags():
414414
assert len(list_5) == 0
415415

416416

417-
def test_is_valid_api_key():
418-
assert not is_valid_api_key("")
419-
assert not is_valid_api_key("sk-")
420-
assert not is_valid_api_key("SK-")
421-
assert not is_valid_api_key("sk-asajsdjsd2")
422-
assert not is_valid_api_key("FooBar")
423-
assert not is_valid_api_key("sk-asajsdjsd22372%23kjdfdfdf2329ffUUDSDS")
424-
assert is_valid_api_key("sk-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS")
425-
assert is_valid_api_key("sk-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS1212121221212sssXX")
426-
assert is_valid_api_key("sk-proj-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212")
427-
assert is_valid_api_key("sk-0-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212")
428-
assert is_valid_api_key("sk-aut0gen-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212")
429-
assert is_valid_api_key("sk-aut0-gen-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212")
430-
assert is_valid_api_key("sk-aut0--gen-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212")
431-
assert not is_valid_api_key("sk-aut0-gen--asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212")
432-
assert not is_valid_api_key("sk--aut0-gen-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212")
433-
assert is_valid_api_key(MOCK_OPEN_AI_API_KEY)
434-
435-
436417
if __name__ == "__main__":
437418
pytest.main()

0 commit comments

Comments
 (0)