Skip to content

Commit

Permalink
Fix API_KEY issue and try_raise miss
Browse files Browse the repository at this point in the history
  • Loading branch information
VKudlay authored Mar 29, 2024
1 parent 64280b5 commit 1240d59
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions libs/ai-endpoints/langchain_nvidia_ai_endpoints/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def validate_model(cls, values: Dict[str, Any]) -> Dict[str, Any]:
values.get(cls._api_key_var.lower())
or values.get("api_key")
or os.getenv(cls._api_key_var)
or ""
)
values["is_staging"] = "nvapi-stg-" in values["api_key"]
if "headers_tmpl" not in values:
Expand Down Expand Up @@ -263,15 +264,20 @@ def _try_raise(self, response: Response) -> None:
rd["detail"] = rd_buf
except json.JSONDecodeError:
rd = response.__dict__
rd = rd.get("_content", rd)
if isinstance(rd, bytes):
rd = rd.decode("utf-8")[5:] ## remove "data:" prefix
try:
rd = json.loads(rd)
except Exception:
rd = {"detail": rd}
status = rd.get("status", "###")
title = rd.get("title", rd.get("error", "Unknown Error"))
if "status_code" in rd:
if "headers" in rd and "WWW-Authenticate" in rd["headers"]:
rd["detail"] = rd.get("headers").get("WWW-Authenticate")
rd["detail"] = rd["detail"].replace(", ", "\n")
else:
rd = rd.get("_content", rd)
if isinstance(rd, bytes):
rd = rd.decode("utf-8")[5:] ## remove "data:" prefix
try:
rd = json.loads(rd)
except Exception:
rd = {"detail": rd}
status = rd.get("status") or rd.get("status_code") or "###"
title = rd.get("title") or rd.get("error") or rd.get("reason") or "Unknown Error"

Check failure on line 280 in libs/ai-endpoints/langchain_nvidia_ai_endpoints/_common.py

View workflow job for this annotation

GitHub Actions / cd libs/ai-endpoints / make lint #3.8

Ruff (E501)

langchain_nvidia_ai_endpoints/_common.py:280:89: E501 Line too long (93 > 88)

Check failure on line 280 in libs/ai-endpoints/langchain_nvidia_ai_endpoints/_common.py

View workflow job for this annotation

GitHub Actions / cd libs/ai-endpoints / make lint #3.11

Ruff (E501)

langchain_nvidia_ai_endpoints/_common.py:280:89: E501 Line too long (93 > 88)
header = f"[{status}] {title}"
body = ""
if "requestId" in rd:
Expand Down

0 comments on commit 1240d59

Please sign in to comment.