File tree 2 files changed +7
-1
lines changed
2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ def is_valid_api_key(api_key: str) -> bool:
96
96
Returns:
97
97
bool: A boolean that indicates if input is valid OpenAI API key.
98
98
"""
99
- api_key_re = re .compile (r"^sk-(proj -)?[A-Za-z0-9]{32,}$" )
99
+ api_key_re = re .compile (r"^sk-([A-Za-z0-9]+(-+[A-Za-z0-9]+)* -)?[A-Za-z0-9]{32,}$" )
100
100
return bool (re .fullmatch (api_key_re , api_key ))
101
101
102
102
Original file line number Diff line number Diff line change @@ -424,6 +424,12 @@ def test_is_valid_api_key():
424
424
assert is_valid_api_key ("sk-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS" )
425
425
assert is_valid_api_key ("sk-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS1212121221212sssXX" )
426
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" )
427
433
assert is_valid_api_key (MOCK_OPEN_AI_API_KEY )
428
434
429
435
You can’t perform that action at this time.
0 commit comments