From 07c944ad0a90e10e9401d34a626bbc7878ffab2a Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Tue, 23 Jan 2024 01:47:55 +0100 Subject: Add upload svg image support Fix upload image in Bing Provider --- g4f/Provider/bing/upload_image.py | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'g4f/Provider/bing') diff --git a/g4f/Provider/bing/upload_image.py b/g4f/Provider/bing/upload_image.py index 4d70659f..bb5687a8 100644 --- a/g4f/Provider/bing/upload_image.py +++ b/g4f/Provider/bing/upload_image.py @@ -82,13 +82,16 @@ def build_image_upload_payload(image_bin: str, tone: str) -> Tuple[str, str]: Tuple[str, str]: The data and boundary for the payload. """ boundary = "----WebKitFormBoundary" + ''.join(random.choices(string.ascii_letters + string.digits, k=16)) - data = f"--{boundary}\r\n" \ - f"Content-Disposition: form-data; name=\"knowledgeRequest\"\r\n\r\n" \ - f"{json.dumps(build_knowledge_request(tone), ensure_ascii=False)}\r\n" \ - f"--{boundary}\r\n" \ - f"Content-Disposition: form-data; name=\"imageBase64\"\r\n\r\n" \ - f"{image_bin}\r\n" \ - f"--{boundary}--\r\n" + data = f"""--{boundary} +Content-Disposition: form-data; name="knowledgeRequest" + +{json.dumps(build_knowledge_request(tone), ensure_ascii=False)} +--{boundary} +Content-Disposition: form-data; name="imageBase64" + +{image_bin} +--{boundary}-- +""" return data, boundary def build_knowledge_request(tone: str) -> dict: @@ -102,14 +105,17 @@ def build_knowledge_request(tone: str) -> dict: dict: The knowledge request payload. """ return { - 'invokedSkills': ["ImageById"], - 'subscriptionId': "Bing.Chat.Multimodal", - 'invokedSkillsRequestData': { - 'enableFaceBlur': True - }, - 'convoData': { - 'convoid': "", - 'convotone': tone + "imageInfo": {}, + "knowledgeRequest": { + 'invokedSkills': ["ImageById"], + 'subscriptionId': "Bing.Chat.Multimodal", + 'invokedSkillsRequestData': { + 'enableFaceBlur': True + }, + 'convoData': { + 'convoid': "", + 'convotone': tone + } } } -- cgit v1.2.3