Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing api_key = None issue and try_raise parsing miss #13

Merged
merged 6 commits into from
Mar 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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
Loading