Skip to content

Commit

Permalink
Allow hypen, update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thienlnam committed Sep 10, 2024
1 parent 8932b01 commit e0bbcad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion autogen/oai/openai_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand Down
7 changes: 4 additions & 3 deletions test/oai/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit e0bbcad

Please sign in to comment.