mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-12-06 02:30:41 -08:00
Improve providers with tests
This commit is contained in:
parent
847843d120
commit
98d3304108
7 changed files with 40 additions and 40 deletions
|
|
@ -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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue