Skip to content

Commit

Permalink
fix: Fix encoding errors caused by incorrect headers (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
KenyonY authored May 13, 2023
1 parent cf569be commit 62d184e
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions openai_forward/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,17 @@ async def _reverse_proxy(cls, request: Request):
except Exception as e:
logger.debug(f"log chat (not) error:\n{request.client.host=}: {e}")

headers.pop("host", None)
headers.update(tmp_headers)

tmp_headers.update({"Content-Type": "application/json"})
req = client.build_request(
request.method, url, headers=headers,
request.method, url, headers=tmp_headers,
content=request.stream(),
timeout=cls.timeout,
)
try:
r = await client.send(req, stream=True)
except (httpx.ConnectError, httpx.ConnectTimeout) as e:
error_info = f"{type(e)}: {e} | " \
f"Please check if host={request.client.host} can access [{cls.BASE_URL}] successfully."
f"Please check if host={request.client.host} can access [{cls.BASE_URL}] successfully?"
logger.error(error_info)
raise HTTPException(status_code=status.HTTP_504_GATEWAY_TIMEOUT, detail=error_info)
except Exception as e:
Expand Down

0 comments on commit 62d184e

Please sign in to comment.