File tree 2 files changed +4
-1
lines changed
2 files changed +4
-1
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ def is_valid_api_key(api_key: str) -> bool:
108
108
Returns:
109
109
bool: A boolean that indicates if input is valid OpenAI API key.
110
110
"""
111
- api_key_re = re .compile (r"^sk-(proj -)?[A-Za-z0-9_]{32,}$" )
111
+ api_key_re = re .compile (r"^sk-([A-Za-z0-9_]+(-+[A-Za-z0-9_]+)* -)?[A-Za-z0-9_]{32,}$" )
112
112
return bool (re .fullmatch (api_key_re , api_key ))
113
113
114
114
Original file line number Diff line number Diff line change @@ -425,6 +425,9 @@ def test_is_valid_api_key():
425
425
assert is_valid_api_key ("sk-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS1212121221212sssXX" )
426
426
assert is_valid_api_key ("sk-proj-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212" )
427
427
assert is_valid_api_key ("sk-0-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212" )
428
+ assert is_valid_api_key ("sk-None-sajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212" )
429
+ assert is_valid_api_key ("sk-svcacct-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212" )
430
+ assert is_valid_api_key ("sk-svcacct-asajsdjsd22372X23kjdfdf_f2329ffUUDSDS12121212212" )
428
431
assert is_valid_api_key ("sk-aut0gen-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212" )
429
432
assert is_valid_api_key ("sk-aut0-gen-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212" )
430
433
assert is_valid_api_key ("sk-aut0--gen-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212" )
You can’t perform that action at this time.
0 commit comments