Commit 4cbda716 authored by tongzifang's avatar tongzifang

fix: auto-append /chat/completions to base URL

The CU Cloud gateway base URL is /v1 but the actual endpoint needs
/chat/completions appended. Auto-detect and append when missing.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 8bc16667
...@@ -150,7 +150,10 @@ def call_llm(system_msg, user_msg, max_tokens=4096, timeout=300, model=None, ena ...@@ -150,7 +150,10 @@ def call_llm(system_msg, user_msg, max_tokens=4096, timeout=300, model=None, ena
"Authorization": f"Bearer {API_KEY}" "Authorization": f"Bearer {API_KEY}"
} }
data = json.dumps(payload).encode("utf-8") data = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(API_URL, data=data, headers=headers, method="POST") url = API_URL.rstrip("/")
if not url.endswith("/chat/completions"):
url = url + "/chat/completions"
req = urllib.request.Request(url, data=data, headers=headers, method="POST")
try: try:
with urllib.request.urlopen(req, timeout=timeout) as resp: with urllib.request.urlopen(req, timeout=timeout) as resp:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment