N.Achyuth Reddy
commited on
Commit
·
9a0f230
1
Parent(s):
d46b278
Create gpt4.py
Browse files
g4f/Provider/Providers/gpt4.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
freeGPT's gpt4 module
|
3 |
+
"""
|
4 |
+
|
5 |
+
from uuid import uuid4
|
6 |
+
from re import findall
|
7 |
+
from curl_cffi.requests import get, RequestsError
|
8 |
+
|
9 |
+
|
10 |
+
class Completion:
|
11 |
+
"""
|
12 |
+
This class provides methods for generating completions based on prompts.
|
13 |
+
"""
|
14 |
+
|
15 |
+
async def create(self, prompt):
|
16 |
+
"""
|
17 |
+
Generate a completion based on the provided prompt.
|
18 |
+
|
19 |
+
Args:
|
20 |
+
prompt (str): The input prompt to generate a completion from.
|
21 |
+
|
22 |
+
Returns:
|
23 |
+
str: The generated completion as a text string.
|
24 |
+
|
25 |
+
Raises:
|
26 |
+
Exception: If the response does not contain the expected "youChatToken".
|
27 |
+
"""
|
28 |
+
resp = get(
|
29 |
+
"https://you.com/api/streamingSearch",
|
30 |
+
headers={
|
31 |
+
"cache-control": "no-cache",
|
32 |
+
"referer": "https://you.com/search?q=gpt4&tbm=youchat",
|
33 |
+
"cookie": f"safesearch_guest=Off; uuid_guest={str(uuid4())}",
|
34 |
+
},
|
35 |
+
params={
|
36 |
+
"q": prompt,
|
37 |
+
"page": 1,
|
38 |
+
"count": 10,
|
39 |
+
"safeSearch": "Off",
|
40 |
+
"onShoppingPage": False,
|
41 |
+
"mkt": "",
|
42 |
+
"responseFilter": "WebPages,Translations,TimeZone,Computation,RelatedSearches",
|
43 |
+
"domain": "youchat",
|
44 |
+
"queryTraceId": str(uuid4()),
|
45 |
+
"chat": [],
|
46 |
+
},
|
47 |
+
impersonate="chrome107",
|
48 |
+
)
|
49 |
+
if "youChatToken" not in resp.text:
|
50 |
+
raise RequestsError("Unable to fetch response.")
|
51 |
+
return (
|
52 |
+
"".join(findall(r"{\"youChatToken\": \"(.*?)\"}", resp.text))
|
53 |
+
.replace("\\n", "\n")
|
54 |
+
.replace("\\\\", "\\")
|
55 |
+
.replace('\\"', '"')
|
56 |
+
)
|