File tree 2 files changed +3
-4
lines changed
2 files changed +3
-4
lines changed Original file line number Diff line number Diff line change @@ -107,8 +107,8 @@ def is_valid_api_key(api_key: str) -> bool:
107
107
Returns:
108
108
bool: A boolean that indicates if input is valid OpenAI API key.
109
109
"""
110
- api_key_re = re .compile (r" ^sk-([A-Za-z0 -9]+(-+[A-Za-z0 -9]+)*-)?[A-Za-z0-9]{32,}$" )
111
- return bool (re .fullmatch (api_key_re , api_key ))
110
+ api_key_re = re .compile (r' ^sk-(?!.*--)([a-zA-Z0 -9]+(?:-[a-zA-Z0 -9]+)*)$' )
111
+ return bool (re .match (api_key_re , api_key ))
112
112
113
113
114
114
def get_config_list (
Original file line number Diff line number Diff line change @@ -428,8 +428,7 @@ def test_is_valid_api_key():
428
428
assert is_valid_api_key ("sk-aut0gen-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212" )
429
429
assert is_valid_api_key ("sk-aut0-gen-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212" )
430
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" )
431
+ assert is_valid_api_key ("sk-proj-asajsdjsd22372X23kjdfdfdf2329f212_gsirb23Yu7vv4vD4-B2iQkbC" )
433
432
assert is_valid_api_key (MOCK_OPEN_AI_API_KEY )
434
433
435
434
You can’t perform that action at this time.
0 commit comments