返回提交历史
Modified
g4f/gui/client/static/js/chat.v1.js
+1
-1
Modified
g4f/tools/files.py
+3
-3
Modified
g4f/tools/web_search.py
+2
-2
XFEstudio/gpt4free
Fix url download function
6314d27d
代码差异
3 个文件
+6
-6
@@ -402,7 +402,7 @@ const handle_ask = async (do_ask_gpt = true) => {
402
402
await add_conversation(window.conversation_id);
403
403
404
404
// Is message a url?
405
const expression = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi;
405
const expression = /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$/gi;
406
406
const regex = new RegExp(expression);
407
407
if (message.match(regex)) {
408
408
paperclip.classList.add("blink");
@@ -416,7 +416,7 @@ def read_links(html: str, base: str) -> set[str]:
416
416
async def download_urls(
417
417
bucket_dir: Path,
418
418
urls: list[str],
419
max_depth: int = 1,
419
max_depth: int = 0,
420
420
loading_urls: set[str] = set(),
421
421
lock: asyncio.Lock = None,
422
422
delay: int = 3,
@@ -515,7 +515,7 @@ def stream_chunks(bucket_dir: Path, delete_files: bool = False, refine_chunks_wi
515
515
if refine_chunks_with_spacy:
516
516
for chunk in stream_read_parts_and_refine(bucket_dir, delete_files):
517
517
if event_stream:
518
size += len(chunk.decode('utf-8'))
518
size += len(chunk.encode())
519
519
yield f'data: {json.dumps({"action": "refine", "size": size})}\n\n'
520
520
else:
521
521
yield chunk
@@ -524,7 +524,7 @@ def stream_chunks(bucket_dir: Path, delete_files: bool = False, refine_chunks_wi
524
524
streaming = cache_stream(streaming, bucket_dir)
525
525
for chunk in streaming:
526
526
if event_stream:
527
size += len(chunk.decode('utf-8'))
527
size += len(chunk.encode())
528
528
yield f'data: {json.dumps({"action": "load", "size": size})}\n\n'
529
529
else:
530
530
yield chunk
@@ -89,10 +89,10 @@ def scrape_text(html: str, max_words: int = None, add_source=True, count_images:
89
89
if select:
90
90
select.extract()
91
91
92
image_select = "img[alt][src^=http]:not([alt='']):not(.avatar)"
92
image_select = "img[alt][src^=http]:not([alt='']):not(.avatar):not([width])"
93
93
image_link_select = f"a:has({image_select})"
94
94
yield_words = []
95
for paragraph in soup.select(f"h1, h2, h3, h4, h5, h6, p, table:not(:has(p)), ul:not(:has(p)), {image_link_select}"):
95
for paragraph in soup.select(f"h1, h2, h3, h4, h5, h6, p, pre, table:not(:has(p)), ul:not(:has(p)), {image_link_select}"):
96
96
if count_images > 0:
97
97
image = paragraph.select_one(image_select)
98
98
if image: