summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/Bing.py
diff options
context:
space:
mode:
authorHeiner Lohaus <heiner@lohaus.eu>2023-10-02 17:01:15 +0200
committerHeiner Lohaus <heiner@lohaus.eu>2023-10-02 17:01:15 +0200
commitff4d9ae584cd3e9eefee6642c2a5290b63351b0a (patch)
tree59b9e30e081b2e1c46b672bc95c5610186516885 /g4f/Provider/Bing.py
parent~ | g4f v-0.1.4.4 (diff)
downloadgpt4free-ff4d9ae584cd3e9eefee6642c2a5290b63351b0a.tar
gpt4free-ff4d9ae584cd3e9eefee6642c2a5290b63351b0a.tar.gz
gpt4free-ff4d9ae584cd3e9eefee6642c2a5290b63351b0a.tar.bz2
gpt4free-ff4d9ae584cd3e9eefee6642c2a5290b63351b0a.tar.lz
gpt4free-ff4d9ae584cd3e9eefee6642c2a5290b63351b0a.tar.xz
gpt4free-ff4d9ae584cd3e9eefee6642c2a5290b63351b0a.tar.zst
gpt4free-ff4d9ae584cd3e9eefee6642c2a5290b63351b0a.zip
Diffstat (limited to 'g4f/Provider/Bing.py')
-rw-r--r--g4f/Provider/Bing.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/g4f/Provider/Bing.py b/g4f/Provider/Bing.py
index 05be27e7..e4e56519 100644
--- a/g4f/Provider/Bing.py
+++ b/g4f/Provider/Bing.py
@@ -3,6 +3,7 @@ from __future__ import annotations
import random
import json
import os
+import urllib.parse
from aiohttp import ClientSession, ClientTimeout
from ..typing import AsyncGenerator
from .base_provider import AsyncGeneratorProvider, get_cookies
@@ -245,7 +246,6 @@ async def stream_generate(
await wss.send_str(create_message(conversation, prompt, context))
response_txt = ''
- result_text = ''
returned_text = ''
final = False
@@ -260,14 +260,18 @@ async def stream_generate(
if response.get('type') == 1 and response['arguments'][0].get('messages'):
message = response['arguments'][0]['messages'][0]
if (message['contentOrigin'] != 'Apology'):
- response_txt = result_text + \
- message['adaptiveCards'][0]['body'][0].get('text', '')
-
- if message.get('messageType'):
- inline_txt = message['adaptiveCards'][0]['body'][0]['inlines'][0].get('text')
- response_txt += inline_txt + '\n'
- result_text += inline_txt + '\n'
-
+ if 'adaptiveCards' in message:
+ card = message['adaptiveCards'][0]['body'][0]
+ if "text" in card:
+ response_txt = card.get('text')
+ if message.get('messageType'):
+ inline_txt = card['inlines'][0].get('text')
+ response_txt += inline_txt + '\n'
+ elif message.get('contentType') == "IMAGE":
+ query = urllib.parse.quote(message.get('text'))
+ url = f"\nhttps://www.bing.com/images/create?q={query}"
+ response_txt += url
+ final = True
if response_txt.startswith(returned_text):
new = response_txt[len(returned_text):]
if new != "\n":