Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bing: add parameter to enable/disable web search #1360

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions g4f/Provider/Bing.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def create_async_generator(
cookies: dict = None,
tone: str = Tones.creative,
image: str = None,
web_search: bool = False,
**kwargs
) -> AsyncResult:
if len(messages) < 2:
Expand All @@ -59,7 +60,7 @@ def create_async_generator(
for key, value in default_cookies.items():
if key not in cookies:
cookies[key] = value
return stream_generate(prompt, tone, image, context, proxy, cookies)
return stream_generate(prompt, tone, image, context, proxy, cookies, web_search)

def create_context(messages: Messages):
return "".join(
Expand Down Expand Up @@ -376,7 +377,7 @@ def compress_image_to_base64(img, compression_rate) -> str:
except Exception as e:
raise e

def create_message(conversation: Conversation, prompt: str, tone: str, context: str=None) -> str:
def create_message(conversation: Conversation, prompt: str, tone: str, context: str = None, web_search: bool = False) -> str:
options_sets = Defaults.optionsSets
if tone == Tones.creative:
options_sets.append("h3imaginative")
Expand All @@ -386,6 +387,8 @@ def create_message(conversation: Conversation, prompt: str, tone: str, context:
options_sets.append("galileo")
else:
options_sets.append("harmonyv3")
if not web_search:
options_sets.append("nosearchall")

request_id = str(uuid.uuid4())
struct = {
Expand Down Expand Up @@ -440,7 +443,8 @@ async def stream_generate(
image: str = None,
context: str = None,
proxy: str = None,
cookies: dict = None
cookies: dict = None,
web_search: bool = False
):
async with ClientSession(
timeout=ClientTimeout(total=900),
Expand All @@ -452,7 +456,7 @@ async def stream_generate(

await wss.send_str(format_message({'protocol': 'json', 'version': 1}))
await wss.receive(timeout=900)
await wss.send_str(create_message(conversation, prompt, tone, context))
await wss.send_str(create_message(conversation, prompt, tone, context, web_search))

response_txt = ''
returned_text = ''
Expand Down
Loading