diff --git a/aidial_adapter_dial/utils/exceptions.py b/aidial_adapter_dial/utils/exceptions.py index d1f5e2c..4947d4c 100644 --- a/aidial_adapter_dial/utils/exceptions.py +++ b/aidial_adapter_dial/utils/exceptions.py @@ -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: