mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-12-06 02:30:41 -08:00
Fix websearch with special chars
This commit is contained in:
parent
04624f2dfa
commit
a57adbee97
2 changed files with 6 additions and 6 deletions
|
|
@ -138,7 +138,6 @@ class Copilot(AbstractProvider, ProviderModelMixin):
|
||||||
if prompt is None:
|
if prompt is None:
|
||||||
prompt = messages[-1]["content"]
|
prompt = messages[-1]["content"]
|
||||||
debug.log(f"Copilot: Use conversation: {conversation_id}")
|
debug.log(f"Copilot: Use conversation: {conversation_id}")
|
||||||
yield Parameters(**{"conversation": conversation.get_dict(), "user": user, "prompt": prompt})
|
|
||||||
|
|
||||||
uploaded_images = []
|
uploaded_images = []
|
||||||
if images is not None:
|
if images is not None:
|
||||||
|
|
@ -200,6 +199,7 @@ class Copilot(AbstractProvider, ProviderModelMixin):
|
||||||
if not is_started:
|
if not is_started:
|
||||||
raise RuntimeError(f"Invalid response: {last_msg}")
|
raise RuntimeError(f"Invalid response: {last_msg}")
|
||||||
finally:
|
finally:
|
||||||
|
yield Parameters(**{"conversation": conversation.get_dict(), "user": user, "prompt": prompt})
|
||||||
yield Parameters(**{"cookies": {c.name: c.value for c in session.cookies.jar}})
|
yield Parameters(**{"cookies": {c.name: c.value for c in session.cookies.jar}})
|
||||||
|
|
||||||
async def get_access_token_and_cookies(url: str, proxy: str = None, target: str = "ChatAI",):
|
async def get_access_token_and_cookies(url: str, proxy: str = None, target: str = "ChatAI",):
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ from aiohttp import ClientSession, ClientTimeout, ClientError
|
||||||
import json
|
import json
|
||||||
import hashlib
|
import hashlib
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse, quote_plus
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import datetime
|
import datetime
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
@ -177,15 +177,15 @@ async def do_search(prompt: str, query: str = None, instructions: str = DEFAULT_
|
||||||
query = spacy_get_keywords(prompt)
|
query = spacy_get_keywords(prompt)
|
||||||
json_bytes = json.dumps({"query": query, **kwargs}, sort_keys=True).encode()
|
json_bytes = json.dumps({"query": query, **kwargs}, sort_keys=True).encode()
|
||||||
md5_hash = hashlib.md5(json_bytes).hexdigest()
|
md5_hash = hashlib.md5(json_bytes).hexdigest()
|
||||||
bucket_dir: Path = Path(get_cookies_dir()) / ".scrape_cache" / f"web_search:{datetime.date.today()}"
|
bucket_dir: Path = Path(get_cookies_dir()) / ".scrape_cache" / f"web_search" / f"{datetime.date.today()}"
|
||||||
bucket_dir.mkdir(parents=True, exist_ok=True)
|
bucket_dir.mkdir(parents=True, exist_ok=True)
|
||||||
cache_file = bucket_dir / f"{query[:20]}.{md5_hash}.txt"
|
cache_file = bucket_dir / f"{quote_plus(query[:20])}.{md5_hash}.txt"
|
||||||
if cache_file.exists():
|
if cache_file.exists():
|
||||||
with open(cache_file, "r") as f:
|
with cache_file.open("r") as f:
|
||||||
search_results = f.read()
|
search_results = f.read()
|
||||||
else:
|
else:
|
||||||
search_results = await search(query, **kwargs)
|
search_results = await search(query, **kwargs)
|
||||||
with open(cache_file, "w") as f:
|
with cache_file.open("w") as f:
|
||||||
f.write(str(search_results))
|
f.write(str(search_results))
|
||||||
|
|
||||||
new_prompt = f"""
|
new_prompt = f"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue