XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Fix websearch with special chars

a57adbee
Heiner Lohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

2 个文件 +6 -6
Modified g4f/Provider/Copilot.py +1 -1
@@ -138,7 +138,6 @@ class Copilot(AbstractProvider, ProviderModelMixin):
138 138 if prompt is None:
139 139 prompt = messages[-1]["content"]
140 140 debug.log(f"Copilot: Use conversation: {conversation_id}")
141 yield Parameters(**{"conversation": conversation.get_dict(), "user": user, "prompt": prompt})
142 141
143 142 uploaded_images = []
144 143 if images is not None:
@@ -200,6 +199,7 @@ class Copilot(AbstractProvider, ProviderModelMixin):
200 199 if not is_started:
201 200 raise RuntimeError(f"Invalid response: {last_msg}")
202 201 finally:
202 yield Parameters(**{"conversation": conversation.get_dict(), "user": user, "prompt": prompt})
203 203 yield Parameters(**{"cookies": {c.name: c.value for c in session.cookies.jar}})
204 204
205 205 async def get_access_token_and_cookies(url: str, proxy: str = None, target: str = "ChatAI",):
Modified g4f/tools/web_search.py +5 -5
@@ -4,7 +4,7 @@ from aiohttp import ClientSession, ClientTimeout, ClientError
4 4 import json
5 5 import hashlib
6 6 from pathlib import Path
7 from urllib.parse import urlparse
7 from urllib.parse import urlparse, quote_plus
8 8 from datetime import datetime
9 9 import datetime
10 10 import asyncio
@@ -177,15 +177,15 @@ async def do_search(prompt: str, query: str = None, instructions: str = DEFAULT_
177 177 query = spacy_get_keywords(prompt)
178 178 json_bytes = json.dumps({"query": query, **kwargs}, sort_keys=True).encode()
179 179 md5_hash = hashlib.md5(json_bytes).hexdigest()
180 bucket_dir: Path = Path(get_cookies_dir()) / ".scrape_cache" / f"web_search:{datetime.date.today()}"
180 bucket_dir: Path = Path(get_cookies_dir()) / ".scrape_cache" / f"web_search" / f"{datetime.date.today()}"
181 181 bucket_dir.mkdir(parents=True, exist_ok=True)
182 cache_file = bucket_dir / f"{query[:20]}.{md5_hash}.txt"
182 cache_file = bucket_dir / f"{quote_plus(query[:20])}.{md5_hash}.txt"
183 183 if cache_file.exists():
184 with open(cache_file, "r") as f:
184 with cache_file.open("r") as f:
185 185 search_results = f.read()
186 186 else:
187 187 search_results = await search(query, **kwargs)
188 with open(cache_file, "w") as f:
188 with cache_file.open("w") as f:
189 189 f.write(str(search_results))
190 190
191 191 new_prompt = f"""