mirror of https://github.com/microsoft/autogen.git
support openai 'sk-proj-' apikey format (#2426)
Co-authored-by: Chi Wang <wang.chi@microsoft.com>
This commit is contained in:
parent
2df0f39b00
commit
442c10bd7b
|
@ -90,7 +90,7 @@ def is_valid_api_key(api_key: str) -> bool:
|
||||||
Returns:
|
Returns:
|
||||||
bool: A boolean that indicates if input is valid OpenAI API key.
|
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))
|
return bool(re.fullmatch(api_key_re, api_key))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -382,6 +382,7 @@ def test_is_valid_api_key():
|
||||||
assert not is_valid_api_key("sk-asajsdjsd22372%23kjdfdfdf2329ffUUDSDS")
|
assert not is_valid_api_key("sk-asajsdjsd22372%23kjdfdfdf2329ffUUDSDS")
|
||||||
assert is_valid_api_key("sk-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS")
|
assert is_valid_api_key("sk-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS")
|
||||||
assert is_valid_api_key("sk-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS1212121221212sssXX")
|
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)
|
assert is_valid_api_key(MOCK_OPEN_AI_API_KEY)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue