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: removed content-encoding header to avoid decoding errors #29

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Changes from all commits
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
11 changes: 11 additions & 0 deletions aidial_adapter_dial/utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,20 @@ def to_dial_exception(exc: Exception) -> DialException | ResponseWrapper:
r = exc.response
headers = r.headers

# The original content length may have changed
# due to the response modification in the adapter.
if "Content-Length" in headers:
del headers["Content-Length"]

# httpx library (used by openai) automatically sets
# "Accept-Encoding:gzip,deflate" header in requests to the upstream.
# Therefore, we may receive from the upstream gzip-encoded
# response along with "Content-Encoding:gzip" header.
# We either need to encode the response, or
# remove the "Content-Encoding" header.
if "Content-Encoding" in headers:
del headers["Content-Encoding"]

try:
content = r.json()
except Exception:
Expand Down
Loading