support openai 'sk-proj-' apikey format (#2426)

Co-authored-by: Chi Wang <wang.chi@microsoft.com>
This commit is contained in:
saberuster 2024-04-18 23:58:37 +08:00 committed by GitHub
parent 2df0f39b00
commit 442c10bd7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 1 deletions

View File

@ -90,7 +90,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]{32,}$")
api_key_re = re.compile(r"^sk-(proj-)?[A-Za-z0-9]{32,}$")
return bool(re.fullmatch(api_key_re, api_key))

View File

@ -382,6 +382,7 @@ def test_is_valid_api_key():
assert not is_valid_api_key("sk-asajsdjsd22372%23kjdfdfdf2329ffUUDSDS")
assert is_valid_api_key("sk-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS")
assert is_valid_api_key("sk-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS1212121221212sssXX")
assert is_valid_api_key("sk-proj-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212")
assert is_valid_api_key(MOCK_OPEN_AI_API_KEY)