@danhachuel/thunderbolt 0.5.51 → 0.5.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -266,37 +266,23 @@ def validate_paligemma_api_key(
|
|
|
266
266
|
*,
|
|
267
267
|
timeout: float = DEFAULT_TIMEOUT_SECONDS,
|
|
268
268
|
) -> None:
|
|
269
|
-
"""Validate the
|
|
269
|
+
"""Validate the NIM credential through its authenticated model catalog."""
|
|
270
270
|
token = str(api_key or "").strip()
|
|
271
271
|
if not token:
|
|
272
272
|
raise OpenAICompatibleAPIError("Informe a API key antes do teste.")
|
|
273
273
|
configured = str(base_url or DEFAULT_NVIDIA_NIM_BASE_URL).rstrip("/")
|
|
274
274
|
if configured.endswith("/chat/completions"):
|
|
275
275
|
configured = configured.removesuffix("/chat/completions")
|
|
276
|
-
if
|
|
277
|
-
configured = configured.replace("integrate.api.nvidia.com", "ai.api.nvidia.com")
|
|
278
|
-
endpoint = configured if "/vlm/google/paligemma" in configured else f"{configured}/vlm/google/paligemma"
|
|
279
|
-
# O endpoint VLM devolve 422 quando recebe apenas texto; uma imagem mínima
|
|
280
|
-
# permite testar autenticação e validação do contrato sem usar ficheiros do utilizador.
|
|
281
|
-
one_pixel_png = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="
|
|
282
|
-
payload = {
|
|
283
|
-
"messages": [{"role": "user", "content": [
|
|
284
|
-
{"type": "text", "text": "Describe this image in one word."},
|
|
285
|
-
{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{one_pixel_png}"}},
|
|
286
|
-
]}],
|
|
287
|
-
"max_tokens": 8,
|
|
288
|
-
"temperature": 0,
|
|
289
|
-
}
|
|
276
|
+
endpoint = configured if configured.endswith("/models") else f"{configured}/models"
|
|
290
277
|
try:
|
|
291
|
-
response = requests.
|
|
278
|
+
response = requests.get(
|
|
292
279
|
endpoint,
|
|
293
|
-
headers={"Accept": "application/json", "Authorization": f"Bearer {token}"
|
|
294
|
-
json=payload,
|
|
280
|
+
headers={"Accept": "application/json", "Authorization": f"Bearer {token}"},
|
|
295
281
|
timeout=timeout,
|
|
296
282
|
)
|
|
297
283
|
except requests.RequestException as exc:
|
|
298
|
-
raise OpenAICompatibleAPIError(f"Não foi possível testar o
|
|
284
|
+
raise OpenAICompatibleAPIError(f"Não foi possível testar o catálogo NVIDIA NIM: {exc}") from exc
|
|
299
285
|
if response.status_code >= 400:
|
|
300
286
|
if response.status_code in (401, 403):
|
|
301
|
-
raise OpenAICompatibleAPIError(f"O
|
|
302
|
-
raise OpenAICompatibleAPIError(f"O
|
|
287
|
+
raise OpenAICompatibleAPIError(f"O catálogo NVIDIA NIM recusou a API key (HTTP {response.status_code}).")
|
|
288
|
+
raise OpenAICompatibleAPIError(f"O catálogo NVIDIA NIM devolveu HTTP {response.status_code}.")
|
package/package.json
CHANGED