Spaces:
Running
Running
Update src/DAG2pr.py
Browse files- src/DAG2pr.py +18 -3
src/DAG2pr.py
CHANGED
|
@@ -70,10 +70,15 @@ def extract_basic_information(
|
|
| 70 |
is_gemini = "gemini" in model.lower()
|
| 71 |
|
| 72 |
if is_gemini:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
# === Gemini Client Setup ===
|
| 74 |
api_key = api_keys_config.get("gemini_api_key") or os.getenv("GOOGLE_API_KEY")
|
| 75 |
|
| 76 |
-
client = genai.Client(api_key=api_key)
|
| 77 |
|
| 78 |
# Gemini Call
|
| 79 |
resp = client.models.generate_content(
|
|
@@ -236,6 +241,11 @@ def generate_pr_from_dag(
|
|
| 236 |
client = None
|
| 237 |
|
| 238 |
if is_gemini:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
# Gemini Configuration (New SDK)
|
| 240 |
if genai is None:
|
| 241 |
raise ImportError("Google GenAI SDK not installed. Please run `pip install google-genai`.")
|
|
@@ -244,7 +254,7 @@ def generate_pr_from_dag(
|
|
| 244 |
if not api_key:
|
| 245 |
raise RuntimeError("API Key not found for Gemini.")
|
| 246 |
|
| 247 |
-
client = genai.Client(api_key=api_key)
|
| 248 |
|
| 249 |
else:
|
| 250 |
# OpenAI Configuration
|
|
@@ -679,6 +689,11 @@ def add_title_and_hashtag(pr_path: str, add_title_and_hashtag_prompt: str, model
|
|
| 679 |
|
| 680 |
# >>> 分支判断逻辑 >>>
|
| 681 |
if "gemini" in model.lower():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 682 |
# --- Google Gemini (New SDK) ---
|
| 683 |
api_key = api_keys.get("gemini_api_key", "").strip()
|
| 684 |
|
|
@@ -692,7 +707,7 @@ def add_title_and_hashtag(pr_path: str, add_title_and_hashtag_prompt: str, model
|
|
| 692 |
raise ImportError("google-genai package is required. Install with: pip install google-genai") from e
|
| 693 |
|
| 694 |
# 配置 client
|
| 695 |
-
client = genai.Client(api_key=api_key)
|
| 696 |
|
| 697 |
try:
|
| 698 |
response = client.models.generate_content(
|
|
|
|
| 70 |
is_gemini = "gemini" in model.lower()
|
| 71 |
|
| 72 |
if is_gemini:
|
| 73 |
+
raw_url = config.get('api_base_url', '').strip().rstrip("/")
|
| 74 |
+
if raw_url.endswith("/v1"):
|
| 75 |
+
base_url = raw_url[:-3].rstrip("/") # 去掉最后的 /v1
|
| 76 |
+
else:
|
| 77 |
+
base_url = raw_url
|
| 78 |
# === Gemini Client Setup ===
|
| 79 |
api_key = api_keys_config.get("gemini_api_key") or os.getenv("GOOGLE_API_KEY")
|
| 80 |
|
| 81 |
+
client = genai.Client(api_key=api_key, http_options={'base_url': base_url} if base_url else None)
|
| 82 |
|
| 83 |
# Gemini Call
|
| 84 |
resp = client.models.generate_content(
|
|
|
|
| 241 |
client = None
|
| 242 |
|
| 243 |
if is_gemini:
|
| 244 |
+
raw_url = config.get('api_base_url', '').strip().rstrip("/")
|
| 245 |
+
if raw_url.endswith("/v1"):
|
| 246 |
+
base_url = raw_url[:-3].rstrip("/") # 去掉最后的 /v1
|
| 247 |
+
else:
|
| 248 |
+
base_url = raw_url
|
| 249 |
# Gemini Configuration (New SDK)
|
| 250 |
if genai is None:
|
| 251 |
raise ImportError("Google GenAI SDK not installed. Please run `pip install google-genai`.")
|
|
|
|
| 254 |
if not api_key:
|
| 255 |
raise RuntimeError("API Key not found for Gemini.")
|
| 256 |
|
| 257 |
+
client = genai.Client(api_key=api_key, http_options={'base_url': base_url} if base_url else None)
|
| 258 |
|
| 259 |
else:
|
| 260 |
# OpenAI Configuration
|
|
|
|
| 689 |
|
| 690 |
# >>> 分支判断逻辑 >>>
|
| 691 |
if "gemini" in model.lower():
|
| 692 |
+
raw_url = config.get('api_base_url', '').strip().rstrip("/")
|
| 693 |
+
if raw_url.endswith("/v1"):
|
| 694 |
+
base_url = raw_url[:-3].rstrip("/") # 去掉最后的 /v1
|
| 695 |
+
else:
|
| 696 |
+
base_url = raw_url
|
| 697 |
# --- Google Gemini (New SDK) ---
|
| 698 |
api_key = api_keys.get("gemini_api_key", "").strip()
|
| 699 |
|
|
|
|
| 707 |
raise ImportError("google-genai package is required. Install with: pip install google-genai") from e
|
| 708 |
|
| 709 |
# 配置 client
|
| 710 |
+
client = genai.Client(api_key=api_key, http_options={'base_url': base_url} if base_url else None)
|
| 711 |
|
| 712 |
try:
|
| 713 |
response = client.models.generate_content(
|