diff options
author | Heiner Lohaus <heiner.lohaus@netformic.com> | 2023-08-22 23:27:34 +0200 |
---|---|---|
committer | Heiner Lohaus <heiner.lohaus@netformic.com> | 2023-08-22 23:27:34 +0200 |
commit | 98d3304108de3e55c18f2af8a66a501541ec658b (patch) | |
tree | a2d80ab0c39ec93ebb97967a9f5a32f0c662c99e /g4f/Provider/You.py | |
parent | ~ | Merge pull request #829 (diff) | |
download | gpt4free-98d3304108de3e55c18f2af8a66a501541ec658b.tar gpt4free-98d3304108de3e55c18f2af8a66a501541ec658b.tar.gz gpt4free-98d3304108de3e55c18f2af8a66a501541ec658b.tar.bz2 gpt4free-98d3304108de3e55c18f2af8a66a501541ec658b.tar.lz gpt4free-98d3304108de3e55c18f2af8a66a501541ec658b.tar.xz gpt4free-98d3304108de3e55c18f2af8a66a501541ec658b.tar.zst gpt4free-98d3304108de3e55c18f2af8a66a501541ec658b.zip |
Diffstat (limited to 'g4f/Provider/You.py')
-rw-r--r-- | g4f/Provider/You.py | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/g4f/Provider/You.py b/g4f/Provider/You.py index 0d8114a8..cbd741ba 100644 --- a/g4f/Provider/You.py +++ b/g4f/Provider/You.py @@ -1,5 +1,6 @@ import re import urllib.parse +import json from curl_cffi import requests @@ -28,7 +29,11 @@ class You(BaseProvider): impersonate="chrome107", ) response.raise_for_status() - yield _parse_output(response.text) + start = 'data: {"youChatToken": ' + for line in response.content.splitlines(): + line = line.decode('utf-8') + if line.startswith(start): + yield json.loads(line[len(start): -1]) def _create_url_param(messages: list[dict[str, str]]): @@ -50,10 +55,4 @@ def _create_header(): return { "accept": "text/event-stream", "referer": "https://you.com/search?fromSearchBar=true&tbm=youchat", - } - - -def _parse_output(output: str) -> str: - regex = r"^data:\s{\"youChatToken\": \"(.*)\"}$" - tokens = [token for token in re.findall(regex, output, re.MULTILINE)] - return "".join(tokens) + }
\ No newline at end of file |