summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/bing/upload_image.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-03-12 18:45:22 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-03-12 18:45:22 +0100
commit5bcf21f9bd2dd9ea581e5301113facda6fc28426 (patch)
treeee3bd34f1e061c80576d8a34cb2bf0033f80a4ac /g4f/Provider/bing/upload_image.py
parentFix unit test with missing requirements (diff)
downloadgpt4free-5bcf21f9bd2dd9ea581e5301113facda6fc28426.tar
gpt4free-5bcf21f9bd2dd9ea581e5301113facda6fc28426.tar.gz
gpt4free-5bcf21f9bd2dd9ea581e5301113facda6fc28426.tar.bz2
gpt4free-5bcf21f9bd2dd9ea581e5301113facda6fc28426.tar.lz
gpt4free-5bcf21f9bd2dd9ea581e5301113facda6fc28426.tar.xz
gpt4free-5bcf21f9bd2dd9ea581e5301113facda6fc28426.tar.zst
gpt4free-5bcf21f9bd2dd9ea581e5301113facda6fc28426.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/bing/upload_image.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/g4f/Provider/bing/upload_image.py b/g4f/Provider/bing/upload_image.py
index 6d51aba0..c517e493 100644
--- a/g4f/Provider/bing/upload_image.py
+++ b/g4f/Provider/bing/upload_image.py
@@ -9,6 +9,7 @@ from aiohttp import ClientSession, FormData
from ...typing import ImageType, Tuple
from ...image import to_image, process_image, to_base64_jpg, ImageRequest, Image
+from ...requests import raise_for_status
IMAGE_CONFIG = {
"maxImagePixels": 360000,
@@ -20,7 +21,7 @@ async def upload_image(
session: ClientSession,
image_data: ImageType,
tone: str,
- proxy: str = None
+ headers: dict
) -> ImageRequest:
"""
Uploads an image to Bing's AI service and returns the image response.
@@ -43,11 +44,9 @@ async def upload_image(
img_binary_data = to_base64_jpg(image, IMAGE_CONFIG['imageCompressionRate'])
data = build_image_upload_payload(img_binary_data, tone)
- headers = prepare_headers(session)
- async with session.post("https://www.bing.com/images/kblob", data=data, headers=headers, proxy=proxy) as response:
- if response.status != 200:
- raise RuntimeError("Failed to upload image.")
+ async with session.post("https://www.bing.com/images/kblob", data=data, headers=prepare_headers(headers)) as response:
+ await raise_for_status(response, "Failed to upload image")
return parse_image_response(await response.json())
def calculate_new_dimensions(image: Image) -> Tuple[int, int]:
@@ -109,7 +108,7 @@ def build_knowledge_request(tone: str) -> dict:
}
}
-def prepare_headers(session: ClientSession) -> dict:
+def prepare_headers(headers: dict) -> dict:
"""
Prepares the headers for the image upload request.
@@ -120,7 +119,6 @@ def prepare_headers(session: ClientSession) -> dict:
Returns:
dict: The headers for the request.
"""
- headers = session.headers.copy()
headers["Referer"] = 'https://www.bing.com/search?q=Bing+AI&showconv=1&FORM=hpcodx'
headers["Origin"] = 'https://www.bing.com'
return headers