Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrent calls to the Wenxin model, and the exception problem when obtaining the token is fixed #7976

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions api/core/model_runtime/model_providers/wenxin/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ def get_access_token(api_key: str, secret_key: str) -> 'BaiduAccessToken':
# if access token not in cache, request it
token = BaiduAccessToken(api_key)
baidu_access_tokens[api_key] = token
# release it to enhance performance
# btw, _get_access_token will raise exception if failed, release lock here to avoid deadlock
baidu_access_tokens_lock.release()
# try to get access token
token_str = BaiduAccessToken._get_access_token(api_key, secret_key)
try:
# try to get access token
token_str = BaiduAccessToken._get_access_token(api_key, secret_key)
finally:
# release it to enhance performance
# btw, _get_access_token will raise exception if failed, release lock here to avoid deadlock
baidu_access_tokens_lock.release()
token.access_token = token_str
token.expires = now + timedelta(days=3)
return token
Expand Down