From ee908ee8d061daaccd6974e79a57f94b25d4125d Mon Sep 17 00:00:00 2001 From: huanshang141 <1375436987@qq.com> Date: Fri, 14 Feb 2025 00:34:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9ensure=5Fopenai=5Fbase=5Furl?= =?UTF-8?q?=5Fhas=5Fv1=EF=BC=8C=E5=AE=9E=E7=8E=B0=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E4=BD=BF=E7=94=A8base=20url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- llm_adapters.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/llm_adapters.py b/llm_adapters.py index 6437509..7b20f45 100644 --- a/llm_adapters.py +++ b/llm_adapters.py @@ -7,10 +7,19 @@ from google import genai from google.genai import types def ensure_openai_base_url_has_v1(url: str) -> str: + """ + 处理base_url的规则: + 1. 如果url以#结尾,则移除#并直接使用用户提供的url + 2. 否则检查是否需要添加/v1后缀 + """ import re url = url.strip() if not url: return url + + if url.endswith('#'): + return url.rstrip('#') + if not re.search(r'/v\d+$', url): if '/v1' not in url: url = url.rstrip('/') + '/v1'