Skip to content

Commit

Permalink
fix(ray): replace user-agent header (#209)
Browse files Browse the repository at this point in the history
Because

- `python-request` user-agent header will cause image retrieval to be
blocked

This commit

- replace user-agent header
  • Loading branch information
heiruwu authored Sep 11, 2024
1 parent f5da73f commit e18b217
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions instill/helpers/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
EMBEDDING_TRUNCATE_END = "end"
EMBEDDING_TRUNCATE_START = "start"

HEADERS = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 \
(KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36"
}


class VisionInput:
image: Image.Image
Expand Down
3 changes: 2 additions & 1 deletion instill/helpers/ray_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from starlette.requests import Request

from instill.helpers.const import (
HEADERS,
IMAGE_INPUT_TYPE_BASE64,
IMAGE_INPUT_TYPE_URL,
PROMPT_ROLES,
Expand Down Expand Up @@ -42,7 +43,7 @@ def base64_to_pil_image(base64_str):


def url_to_pil_image(url):
resp = requests.get(url, timeout=10)
resp = requests.get(url, headers=HEADERS, timeout=10)
resp.raise_for_status()
return Image.open(io.BytesIO(resp.content))

Expand Down

0 comments on commit e18b217

Please sign in to comment.