summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/needs_auth
diff options
context:
space:
mode:
authorAndPim4912 <52836885+AndPim4912@users.noreply.github.com>2023-10-23 14:10:28 +0200
committerGitHub <noreply@github.com>2023-10-23 14:10:28 +0200
commit8d7ad98fcb314453c01f6dcd4bfe59016efd78ce (patch)
tree4d39804e1aa1724560e1688f0b6d4c124b9771c7 /g4f/Provider/needs_auth
parentRefactor API initialization to accept a list of ignored providers. (diff)
parentDebug config in api (diff)
downloadgpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar
gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.gz
gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.bz2
gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.lz
gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.xz
gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.zst
gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.zip
Diffstat (limited to 'g4f/Provider/needs_auth')
-rw-r--r--g4f/Provider/needs_auth/Bard.py14
-rw-r--r--g4f/Provider/needs_auth/Raycast.py10
-rw-r--r--g4f/Provider/needs_auth/Theb.py40
3 files changed, 31 insertions, 33 deletions
diff --git a/g4f/Provider/needs_auth/Bard.py b/g4f/Provider/needs_auth/Bard.py
index fe9777db..092268f8 100644
--- a/g4f/Provider/needs_auth/Bard.py
+++ b/g4f/Provider/needs_auth/Bard.py
@@ -38,18 +38,18 @@ class Bard(AsyncProvider):
'x-same-domain': '1',
}
async with ClientSession(
- cookies=cookies,
- headers=headers
- ) as session:
+ cookies=cookies,
+ headers=headers
+ ) as session:
if not cls._snlm0e:
async with session.get(cls.url, proxy=proxy) as response:
text = await response.text()
- match = re.search(r'SNlM0e\":\"(.*?)\"', text)
- if not match:
+ if match := re.search(r'SNlM0e\":\"(.*?)\"', text):
+ cls._snlm0e = match.group(1)
+
+ else:
raise RuntimeError("No snlm0e value.")
- cls._snlm0e = match.group(1)
-
params = {
'bl': 'boq_assistant-bard-web-server_20230326.21_p0',
'_reqid': random.randint(1111, 9999),
diff --git a/g4f/Provider/needs_auth/Raycast.py b/g4f/Provider/needs_auth/Raycast.py
index 4b448985..4570fd9f 100644
--- a/g4f/Provider/needs_auth/Raycast.py
+++ b/g4f/Provider/needs_auth/Raycast.py
@@ -32,12 +32,10 @@ class Raycast(BaseProvider):
'Content-Type': 'application/json',
'User-Agent': 'Raycast/0 CFNetwork/1410.0.3 Darwin/22.6.0',
}
- parsed_messages = []
- for message in messages:
- parsed_messages.append({
- 'author': message['role'],
- 'content': {'text': message['content']}
- })
+ parsed_messages = [
+ {'author': message['role'], 'content': {'text': message['content']}}
+ for message in messages
+ ]
data = {
"debug": False,
"locale": "en-CN",
diff --git a/g4f/Provider/needs_auth/Theb.py b/g4f/Provider/needs_auth/Theb.py
index 9803db97..b3c9019d 100644
--- a/g4f/Provider/needs_auth/Theb.py
+++ b/g4f/Provider/needs_auth/Theb.py
@@ -28,28 +28,28 @@ class Theb(BaseProvider):
"bearer_token":"free",
"org_id":"theb",
})
-
+
bearer_token = auth["bearer_token"]
org_id = auth["org_id"]
-
+
headers = {
- 'authority' : 'beta.theb.ai',
- 'accept' : 'text/event-stream',
- 'accept-language' : 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7',
- 'authorization' : 'Bearer '+bearer_token,
- 'content-type' : 'application/json',
- 'origin' : 'https://beta.theb.ai',
- 'referer' : 'https://beta.theb.ai/home',
- 'sec-ch-ua' : '"Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116"',
- 'sec-ch-ua-mobile' : '?0',
+ 'authority': 'beta.theb.ai',
+ 'accept': 'text/event-stream',
+ 'accept-language': 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7',
+ 'authorization': f'Bearer {bearer_token}',
+ 'content-type': 'application/json',
+ 'origin': 'https://beta.theb.ai',
+ 'referer': 'https://beta.theb.ai/home',
+ 'sec-ch-ua': '"Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116"',
+ 'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
- 'sec-fetch-dest' : 'empty',
- 'sec-fetch-mode' : 'cors',
- 'sec-fetch-site' : 'same-origin',
- 'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
- 'x-ai-model' : 'ee8d4f29cb7047f78cbe84313ed6ace8',
+ 'sec-fetch-dest': 'empty',
+ 'sec-fetch-mode': 'cors',
+ 'sec-fetch-site': 'same-origin',
+ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
+ 'x-ai-model': 'ee8d4f29cb7047f78cbe84313ed6ace8',
}
-
+
req_rand = random.randint(100000000, 9999999999)
json_data: dict[str, Any] = {
@@ -65,7 +65,7 @@ class Theb(BaseProvider):
"long_term_memory" : "auto"
}
}
-
+
response = requests.post(
f"https://beta.theb.ai/api/conversation?org_id={org_id}&req_rand={req_rand}",
headers=headers,
@@ -73,7 +73,7 @@ class Theb(BaseProvider):
stream=True,
proxies={"https": proxy}
)
-
+
response.raise_for_status()
content = ""
next_content = ""
@@ -82,7 +82,7 @@ class Theb(BaseProvider):
next_content = content
data = json.loads(chunk.decode().split("data: ")[1])
content = data["content"]
- yield data["content"].replace(next_content, "")
+ yield content.replace(next_content, "")
@classmethod
@property