更改ensure_openai_base_url_has_v1,实现强制使用base url
This commit is contained in:
@@ -7,10 +7,19 @@ from google import genai
|
|||||||
from google.genai import types
|
from google.genai import types
|
||||||
|
|
||||||
def ensure_openai_base_url_has_v1(url: str) -> str:
|
def ensure_openai_base_url_has_v1(url: str) -> str:
|
||||||
|
"""
|
||||||
|
处理base_url的规则:
|
||||||
|
1. 如果url以#结尾,则移除#并直接使用用户提供的url
|
||||||
|
2. 否则检查是否需要添加/v1后缀
|
||||||
|
"""
|
||||||
import re
|
import re
|
||||||
url = url.strip()
|
url = url.strip()
|
||||||
if not url:
|
if not url:
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
if url.endswith('#'):
|
||||||
|
return url.rstrip('#')
|
||||||
|
|
||||||
if not re.search(r'/v\d+$', url):
|
if not re.search(r'/v\d+$', url):
|
||||||
if '/v1' not in url:
|
if '/v1' not in url:
|
||||||
url = url.rstrip('/') + '/v1'
|
url = url.rstrip('/') + '/v1'
|
||||||
|
|||||||
Reference in New Issue
Block a user