Skip to content

Commit

Permalink
fix: removed content-encoding header to avoid decoding errors (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
adubovik authored Nov 19, 2024
1 parent 2fed242 commit 8a50570
Showing 1 changed file with 11 additions and 0 deletions.
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

0 comments on commit 8a50570

Please sign in to comment.