summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/You.py
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2023-08-25 18:22:38 +0200
committerGitHub <noreply@github.com>2023-08-25 18:22:38 +0200
commitb2baf46e3cb2ad27d666217bb14c54d89fbb8c66 (patch)
tree60052aad3746053eb4aec5b7e44d75404f4d11fe /g4f/Provider/You.py
parent~ | Merge pull request #841 (diff)
parentMerge branch 'main' into up (diff)
downloadgpt4free-b2baf46e3cb2ad27d666217bb14c54d89fbb8c66.tar
gpt4free-b2baf46e3cb2ad27d666217bb14c54d89fbb8c66.tar.gz
gpt4free-b2baf46e3cb2ad27d666217bb14c54d89fbb8c66.tar.bz2
gpt4free-b2baf46e3cb2ad27d666217bb14c54d89fbb8c66.tar.lz
gpt4free-b2baf46e3cb2ad27d666217bb14c54d89fbb8c66.tar.xz
gpt4free-b2baf46e3cb2ad27d666217bb14c54d89fbb8c66.tar.zst
gpt4free-b2baf46e3cb2ad27d666217bb14c54d89fbb8c66.zip
Diffstat (limited to 'g4f/Provider/You.py')
-rw-r--r--g4f/Provider/You.py17
1 files changed, 8 insertions, 9 deletions
diff --git a/g4f/Provider/You.py b/g4f/Provider/You.py
index a8de7dec..7ea699a2 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,8 +29,12 @@ class You(BaseProvider):
impersonate="chrome107",
)
response.raise_for_status()
- yield _parse_output(response.text).encode().decode("unicode_escape")
-
+
+ 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]], history: list[dict[str, str]]):
prompt = ""
@@ -53,10 +58,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