diff --git a/autogen/oai/openai_utils.py b/autogen/oai/openai_utils.py index 2512a75ba257..a2b2aa42aaf7 100644 --- a/autogen/oai/openai_utils.py +++ b/autogen/oai/openai_utils.py @@ -108,7 +108,7 @@ def is_valid_api_key(api_key: str) -> bool: Returns: bool: A boolean that indicates if input is valid OpenAI API key. """ - api_key_re = re.compile(r"^sk-([A-Za-z0-9]+(-+[A-Za-z0-9]+)*-)?[A-Za-z0-9_]{32,}$") + api_key_re = re.compile(r"^sk-([A-Za-z0-9]+(-+[A-Za-z0-9]+)*-)?[A-Za-z0-9_-]{32,}$") return bool(re.fullmatch(api_key_re, api_key)) diff --git a/test/oai/test_utils.py b/test/oai/test_utils.py index 21f3c2aaeada..a79a56d27e4c 100755 --- a/test/oai/test_utils.py +++ b/test/oai/test_utils.py @@ -432,9 +432,10 @@ def test_is_valid_api_key(): assert is_valid_api_key("sk-aut0gen-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212") assert is_valid_api_key("sk-aut0-gen-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212") assert is_valid_api_key("sk-aut0--gen-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212") - assert not is_valid_api_key("sk-aut0-gen--asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212") - assert not is_valid_api_key("sk-abc_def-ghijklmnopqrstuvwxyz0123456789ABCDEFGH") - assert not is_valid_api_key("sk--aut0-gen-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212") + assert is_valid_api_key("sk-proj-mhsJPwdSvNpTPo7V7nXXX--sAUco3WfNB7D77JY6wNmIFWXXXXXXXXXXXXXXXXXXX4NE") + assert is_valid_api_key("sk-aut0-gen--asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212") + assert is_valid_api_key("sk-abc_def-ghijklmnopqrstuvwxyz0123456789ABCDEFGH") + assert is_valid_api_key("sk--aut0-gen-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212") assert is_valid_api_key(MOCK_OPEN_AI_API_KEY)