From e1eafb46c386b1d18f2de75ab865156b8c175892 Mon Sep 17 00:00:00 2001 From: puqs1 Date: Wed, 4 Sep 2024 18:25:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B6=E5=8F=91=E8=B0=83=E7=94=A8=E6=96=87?= =?UTF-8?q?=E5=BF=83=E6=A8=A1=E5=9E=8B=EF=BC=8C=E8=8E=B7=E5=8F=96token?= =?UTF-8?q?=E6=97=B6=E5=87=BA=E7=8E=B0=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E7=AC=AC=E4=B8=80=E4=B8=AA=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E8=8E=B7=E5=8F=96=E5=88=B0BaiduAccessToken=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E5=B0=B1=E9=87=8A=E6=94=BE=E4=BA=86=E9=94=81=EF=BC=8C?= =?UTF-8?q?=E6=AD=A4=E6=97=B6=E5=AF=B9=E8=B1=A1=E4=B8=AD=E7=9A=84access=5F?= =?UTF-8?q?token=E8=BF=98=E6=98=AF=E7=A9=BA=E3=80=82=E7=AC=AC=E4=BA=8C?= =?UTF-8?q?=E4=B8=AA=E8=AF=B7=E6=B1=82=E9=A9=AC=E4=B8=8A=E8=BF=9B=E6=9D=A5?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E6=8B=BF=E8=B5=B0=E8=BF=99=E4=B8=AA=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=EF=BC=8C=E5=AF=BC=E8=87=B4=E8=8E=B7=E5=8F=96=E5=88=B0?= =?UTF-8?q?=E7=9A=84access=5Ftoken=E4=B8=BA=E7=A9=BA=EF=BC=8C=E8=BF=9B?= =?UTF-8?q?=E8=80=8C=E5=AF=BC=E8=87=B4=E8=AF=B7=E6=B1=82=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model_runtime/model_providers/wenxin/_common.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/api/core/model_runtime/model_providers/wenxin/_common.py b/api/core/model_runtime/model_providers/wenxin/_common.py index 0230c78b757612..017856bdde2e16 100644 --- a/api/core/model_runtime/model_providers/wenxin/_common.py +++ b/api/core/model_runtime/model_providers/wenxin/_common.py @@ -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