feat: add diagnostic logs for generation flows
This commit is contained in:
+28
-1
@@ -425,6 +425,33 @@ def get_model(name, path=AI_MODELS_PATH) -> dict:
|
||||
return copy.deepcopy(models[_model_index(models, name)])
|
||||
|
||||
|
||||
|
||||
def model_request_url(model) -> str:
|
||||
"""Return the HTTP endpoint used for a configured AI model."""
|
||||
|
||||
raw_url = str(model.get("url", "") or "").strip()
|
||||
api_type = str(model.get("api_type", "auto") or "auto").strip()
|
||||
if api_type == "images_edits":
|
||||
return _append_default_endpoint(raw_url, "images/edits")
|
||||
return _append_default_endpoint(raw_url, "chat/completions")
|
||||
|
||||
|
||||
def _append_default_endpoint(raw_url, endpoint):
|
||||
if not raw_url:
|
||||
return raw_url
|
||||
parts = urllib.parse.urlsplit(raw_url)
|
||||
path = parts.path.rstrip("/")
|
||||
lowered = path.lower()
|
||||
endpoint_path = "/" + endpoint.strip("/")
|
||||
if lowered.endswith(endpoint_path):
|
||||
return raw_url
|
||||
base_markers = ("", "/v1", "/v1beta", "/api/v1", "/api/v1beta")
|
||||
if lowered in base_markers or lowered.endswith(base_markers[1:]):
|
||||
path = path + endpoint_path
|
||||
return urllib.parse.urlunsplit(
|
||||
(parts.scheme, parts.netloc, path, parts.query, parts.fragment)
|
||||
)
|
||||
return raw_url
|
||||
def _test_request_payload(model):
|
||||
if model["api_type"] == "images_edits":
|
||||
payload = {"model": model["model"], "prompt": "ping"}
|
||||
@@ -455,7 +482,7 @@ def test_ai_model(name, path=AI_MODELS_PATH) -> dict:
|
||||
"utf-8"
|
||||
)
|
||||
request = urllib.request.Request(
|
||||
model["url"],
|
||||
model_request_url(model),
|
||||
data=data,
|
||||
headers={
|
||||
"Authorization": "Bearer " + model["api_key"],
|
||||
|
||||
Reference in New Issue
Block a user