t.me/xtekky
commited on
Commit
•
8b4e40d
1
Parent(s):
ab75098
writesonic.com api (gpt3.5 with internet)
Browse files- README.md +57 -1
- testing/{t3nsor.py → t3nsor_test.py} +0 -0
- testing/writesonic_test.py +49 -0
- writesonic/__init__.py +158 -0
README.md
CHANGED
@@ -12,6 +12,7 @@ This repository provides reverse-engineered language models from various sources
|
|
12 |
- [`poe`](#example-poe)
|
13 |
- [`t3nsor`](#example-t3nsor)
|
14 |
- [`ora`](#example-ora)
|
|
|
15 |
|
16 |
## Current Sites <a name="current-sites"></a>
|
17 |
|
@@ -158,6 +159,60 @@ while True:
|
|
158 |
print(response.completion.choices[0].text)
|
159 |
```
|
160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
## Dependencies
|
162 |
|
163 |
The repository is written in Python and requires the following packages:
|
@@ -174,5 +229,6 @@ You can install these packages using the provided `requirements.txt` file.
|
|
174 |
├── ora/
|
175 |
├── poe/
|
176 |
├── t3nsor/
|
|
|
177 |
├── README.md <-- this file.
|
178 |
-
└── requirements.txt
|
|
|
12 |
- [`poe`](#example-poe)
|
13 |
- [`t3nsor`](#example-t3nsor)
|
14 |
- [`ora`](#example-ora)
|
15 |
+
- [`writesonic`](#example-writesonic)
|
16 |
|
17 |
## Current Sites <a name="current-sites"></a>
|
18 |
|
|
|
159 |
print(response.completion.choices[0].text)
|
160 |
```
|
161 |
|
162 |
+
### Example: `writesonic` (use like openai pypi package) <a name="example-writesonic"></a>
|
163 |
+
|
164 |
+
```python
|
165 |
+
# import writesonic
|
166 |
+
import writesonic
|
167 |
+
|
168 |
+
# create account (3-4s)
|
169 |
+
account = writesonic.Account.create(logging = True)
|
170 |
+
|
171 |
+
# with loging:
|
172 |
+
# 2023-04-06 21:50:25 INFO __main__ -> register success : '{"id":"51aa0809-3053-44f7-922a...' (2s)
|
173 |
+
# 2023-04-06 21:50:25 INFO __main__ -> id : '51aa0809-3053-44f7-922a-2b85d8d07edf'
|
174 |
+
# 2023-04-06 21:50:25 INFO __main__ -> token : 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ik...'
|
175 |
+
# 2023-04-06 21:50:28 INFO __main__ -> got key : '194158c4-d249-4be0-82c6-5049e869533c' (2s)
|
176 |
+
|
177 |
+
# simple completion
|
178 |
+
response = writesonic.Completion.create(
|
179 |
+
api_key = account.key,
|
180 |
+
prompt = 'hello world'
|
181 |
+
)
|
182 |
+
|
183 |
+
print(response.completion.choices[0].text) # Hello! How may I assist you today?
|
184 |
+
|
185 |
+
# conversation
|
186 |
+
|
187 |
+
response = writesonic.Completion.create(
|
188 |
+
api_key = account.key,
|
189 |
+
prompt = 'what is my name ?',
|
190 |
+
enable_memory = True,
|
191 |
+
history_data = [
|
192 |
+
{
|
193 |
+
'is_sent': True,
|
194 |
+
'message': 'my name is Tekky'
|
195 |
+
},
|
196 |
+
{
|
197 |
+
'is_sent': False,
|
198 |
+
'message': 'hello Tekky'
|
199 |
+
}
|
200 |
+
]
|
201 |
+
)
|
202 |
+
|
203 |
+
print(response.completion.choices[0].text) # Your name is Tekky.
|
204 |
+
|
205 |
+
# enable internet
|
206 |
+
|
207 |
+
response = writesonic.Completion.create(
|
208 |
+
api_key = account.key,
|
209 |
+
prompt = 'who won the quatar world cup ?',
|
210 |
+
enable_google_results = True
|
211 |
+
)
|
212 |
+
|
213 |
+
print(response.completion.choices[0].text) # Argentina won the 2022 FIFA World Cup tournament held in Qatar ...
|
214 |
+
```
|
215 |
+
|
216 |
## Dependencies
|
217 |
|
218 |
The repository is written in Python and requires the following packages:
|
|
|
229 |
├── ora/
|
230 |
├── poe/
|
231 |
├── t3nsor/
|
232 |
+
├── writesonic/
|
233 |
├── README.md <-- this file.
|
234 |
+
└── requirements.txt
|
testing/{t3nsor.py → t3nsor_test.py}
RENAMED
File without changes
|
testing/writesonic_test.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# import writesonic
|
2 |
+
import writesonic
|
3 |
+
|
4 |
+
# create account (3-4s)
|
5 |
+
account = writesonic.Account.create(logging = True)
|
6 |
+
|
7 |
+
# with loging:
|
8 |
+
# 2023-04-06 21:50:25 INFO __main__ -> register success : '{"id":"51aa0809-3053-44f7-922a...' (2s)
|
9 |
+
# 2023-04-06 21:50:25 INFO __main__ -> id : '51aa0809-3053-44f7-922a-2b85d8d07edf'
|
10 |
+
# 2023-04-06 21:50:25 INFO __main__ -> token : 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ik...'
|
11 |
+
# 2023-04-06 21:50:28 INFO __main__ -> got key : '194158c4-d249-4be0-82c6-5049e869533c' (2s)
|
12 |
+
|
13 |
+
# simple completion
|
14 |
+
response = writesonic.Completion.create(
|
15 |
+
api_key = account.key,
|
16 |
+
prompt = 'hello world'
|
17 |
+
)
|
18 |
+
|
19 |
+
print(response.completion.choices[0].text) # Hello! How may I assist you today?
|
20 |
+
|
21 |
+
# conversation
|
22 |
+
|
23 |
+
response = writesonic.Completion.create(
|
24 |
+
api_key = account.key,
|
25 |
+
prompt = 'what is my name ?',
|
26 |
+
enable_memory = True,
|
27 |
+
history_data = [
|
28 |
+
{
|
29 |
+
'is_sent': True,
|
30 |
+
'message': 'my name is Tekky'
|
31 |
+
},
|
32 |
+
{
|
33 |
+
'is_sent': False,
|
34 |
+
'message': 'hello Tekky'
|
35 |
+
}
|
36 |
+
]
|
37 |
+
)
|
38 |
+
|
39 |
+
print(response.completion.choices[0].text) # Your name is Tekky.
|
40 |
+
|
41 |
+
# enable internet
|
42 |
+
|
43 |
+
response = writesonic.Completion.create(
|
44 |
+
api_key = account.key,
|
45 |
+
prompt = 'who won the quatar world cup ?',
|
46 |
+
enable_google_results = True
|
47 |
+
)
|
48 |
+
|
49 |
+
print(response.completion.choices[0].text) # Argentina won the 2022 FIFA World Cup tournament held in Qatar ...
|
writesonic/__init__.py
ADDED
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from requests import Session
|
2 |
+
from names import get_first_name, get_last_name
|
3 |
+
from random import choice
|
4 |
+
from requests import post
|
5 |
+
from time import time
|
6 |
+
from colorama import Fore, init; init()
|
7 |
+
|
8 |
+
class logger:
|
9 |
+
@staticmethod
|
10 |
+
def info(string) -> print:
|
11 |
+
import datetime
|
12 |
+
now = datetime.datetime.now()
|
13 |
+
return print(f"{Fore.CYAN}{now.strftime('%Y-%m-%d %H:%M:%S')} {Fore.BLUE}INFO {Fore.MAGENTA}__main__ -> {Fore.RESET}{string}")
|
14 |
+
|
15 |
+
class SonicResponse:
|
16 |
+
|
17 |
+
class Completion:
|
18 |
+
|
19 |
+
class Choices:
|
20 |
+
def __init__(self, choice: dict) -> None:
|
21 |
+
self.text = choice['text']
|
22 |
+
self.content = self.text.encode()
|
23 |
+
self.index = choice['index']
|
24 |
+
self.logprobs = choice['logprobs']
|
25 |
+
self.finish_reason = choice['finish_reason']
|
26 |
+
|
27 |
+
def __repr__(self) -> str:
|
28 |
+
return f'''<__main__.APIResponse.Completion.Choices(\n text = {self.text.encode()},\n index = {self.index},\n logprobs = {self.logprobs},\n finish_reason = {self.finish_reason})object at 0x1337>'''
|
29 |
+
|
30 |
+
def __init__(self, choices: dict) -> None:
|
31 |
+
self.choices = [self.Choices(choice) for choice in choices]
|
32 |
+
|
33 |
+
class Usage:
|
34 |
+
def __init__(self, usage_dict: dict) -> None:
|
35 |
+
self.prompt_tokens = usage_dict['prompt_chars']
|
36 |
+
self.completion_tokens = usage_dict['completion_chars']
|
37 |
+
self.total_tokens = usage_dict['total_chars']
|
38 |
+
|
39 |
+
def __repr__(self):
|
40 |
+
return f'''<__main__.APIResponse.Usage(\n prompt_tokens = {self.prompt_tokens},\n completion_tokens = {self.completion_tokens},\n total_tokens = {self.total_tokens})object at 0x1337>'''
|
41 |
+
|
42 |
+
def __init__(self, response_dict: dict) -> None:
|
43 |
+
|
44 |
+
self.response_dict = response_dict
|
45 |
+
self.id = response_dict['id']
|
46 |
+
self.object = response_dict['object']
|
47 |
+
self.created = response_dict['created']
|
48 |
+
self.model = response_dict['model']
|
49 |
+
self.completion = self.Completion(response_dict['choices'])
|
50 |
+
self.usage = self.Usage(response_dict['usage'])
|
51 |
+
|
52 |
+
def json(self) -> dict:
|
53 |
+
return self.response_dict
|
54 |
+
|
55 |
+
class Account:
|
56 |
+
session = Session()
|
57 |
+
session.headers = {
|
58 |
+
"connection" : "keep-alive",
|
59 |
+
"sec-ch-ua" : "\"Not_A Brand\";v=\"99\", \"Google Chrome\";v=\"109\", \"Chromium\";v=\"109\"",
|
60 |
+
"accept" : "application/json, text/plain, */*",
|
61 |
+
"content-type" : "application/json",
|
62 |
+
"sec-ch-ua-mobile" : "?0",
|
63 |
+
"user-agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
|
64 |
+
"sec-ch-ua-platform": "\"Windows\"",
|
65 |
+
"sec-fetch-site" : "same-origin",
|
66 |
+
"sec-fetch-mode" : "cors",
|
67 |
+
"sec-fetch-dest" : "empty",
|
68 |
+
# "accept-encoding" : "gzip, deflate, br",
|
69 |
+
"accept-language" : "en-GB,en-US;q=0.9,en;q=0.8",
|
70 |
+
"cookie" : ""
|
71 |
+
}
|
72 |
+
|
73 |
+
@staticmethod
|
74 |
+
def get_user():
|
75 |
+
password = f'0opsYouGoTme@1234'
|
76 |
+
f_name = get_first_name()
|
77 |
+
l_name = get_last_name()
|
78 |
+
hosts = ['gmail.com', 'protonmail.com', 'proton.me', 'outlook.com']
|
79 |
+
|
80 |
+
return {
|
81 |
+
"email" : f"{f_name.lower()}.{l_name.lower()}@{choice(hosts)}",
|
82 |
+
"password" : password,
|
83 |
+
"confirm_password" : password,
|
84 |
+
"full_name" : f'{f_name} {l_name}'
|
85 |
+
}
|
86 |
+
|
87 |
+
@staticmethod
|
88 |
+
def create(logging: bool = False):
|
89 |
+
while True:
|
90 |
+
try:
|
91 |
+
user = Account.get_user()
|
92 |
+
start = time()
|
93 |
+
response = Account.session.post("https://app.writesonic.com/api/session-login", json = user | {
|
94 |
+
"utmParams" : "{}",
|
95 |
+
"visitorId" : "0",
|
96 |
+
"locale" : "en",
|
97 |
+
"userAgent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
|
98 |
+
"signInWith" : "password",
|
99 |
+
"request_type" : "signup",
|
100 |
+
})
|
101 |
+
|
102 |
+
if logging:
|
103 |
+
logger.info(f"\x1b[31mregister success\x1b[0m : '{response.text[:30]}...' ({int(time() - start)}s)")
|
104 |
+
logger.info(f"\x1b[31mid\x1b[0m : '{response.json()['id']}'")
|
105 |
+
logger.info(f"\x1b[31mtoken\x1b[0m : '{response.json()['token'][:30]}...'")
|
106 |
+
|
107 |
+
start = time()
|
108 |
+
response = Account.session.post("https://api.writesonic.com/v1/business/set-business-active", headers={"authorization": "Bearer " + response.json()['token']})
|
109 |
+
key = response.json()["business"]["api_key"]
|
110 |
+
if logging: logger.info(f"\x1b[31mgot key\x1b[0m : '{key}' ({int(time() - start)}s)")
|
111 |
+
|
112 |
+
return Account.AccountResponse(user['email'], user['password'], key)
|
113 |
+
|
114 |
+
except Exception as e:
|
115 |
+
if logging: logger.info(f"\x1b[31merror\x1b[0m : '{e}'")
|
116 |
+
continue
|
117 |
+
|
118 |
+
class AccountResponse:
|
119 |
+
def __init__(self, email, password, key):
|
120 |
+
self.email = email
|
121 |
+
self.password = password
|
122 |
+
self.key = key
|
123 |
+
|
124 |
+
|
125 |
+
class Completion:
|
126 |
+
def create(
|
127 |
+
api_key: str,
|
128 |
+
prompt: str,
|
129 |
+
enable_memory: bool = False,
|
130 |
+
enable_google_results: bool = False,
|
131 |
+
history_data: list = []) -> SonicResponse:
|
132 |
+
|
133 |
+
response = post('https://api.writesonic.com/v2/business/content/chatsonic?engine=premium', headers = {"X-API-KEY": api_key},
|
134 |
+
json = {
|
135 |
+
"enable_memory" : enable_memory,
|
136 |
+
"enable_google_results" : enable_google_results,
|
137 |
+
"input_text" : prompt,
|
138 |
+
"history_data" : history_data}).json()
|
139 |
+
|
140 |
+
return SonicResponse({
|
141 |
+
'id' : f'cmpl-premium-{int(time())}',
|
142 |
+
'object' : 'text_completion',
|
143 |
+
'created': int(time()),
|
144 |
+
'model' : 'premium',
|
145 |
+
|
146 |
+
'choices': [{
|
147 |
+
'text' : response['message'],
|
148 |
+
'index' : 0,
|
149 |
+
'logprobs' : None,
|
150 |
+
'finish_reason' : 'stop'
|
151 |
+
}],
|
152 |
+
|
153 |
+
'usage': {
|
154 |
+
'prompt_chars' : len(prompt),
|
155 |
+
'completion_chars' : len(response['message']),
|
156 |
+
'total_chars' : len(prompt) + len(response['message'])
|
157 |
+
}
|
158 |
+
})
|