XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Delete unfinished/writesonic directory

help deleting directory -> I am helping delete the directory of writesonic as per the takedown request.

27add5f4
naa <44613678+naa7@users.noreply.github.com>
提交于

代码差异

2 个文件 +0 -216
Deleted unfinished/writesonic/README.md +0 -53
@@ -1,53 +0,0 @@
1 ### Example: `writesonic` (use like openai pypi package) <a name="example-writesonic"></a>
2
3 ```python
4 # import writesonic
5 import writesonic
6
7 # create account (3-4s)
8 account = writesonic.Account.create(logging = True)
9
10 # with loging:
11 # 2023-04-06 21:50:25 INFO __main__ -> register success : '{"id":"51aa0809-3053-44f7-922a...' (2s)
12 # 2023-04-06 21:50:25 INFO __main__ -> id : '51aa0809-3053-44f7-922a-2b85d8d07edf'
13 # 2023-04-06 21:50:25 INFO __main__ -> token : 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ik...'
14 # 2023-04-06 21:50:28 INFO __main__ -> got key : '194158c4-d249-4be0-82c6-5049e869533c' (2s)
15
16 # simple completion
17 response = writesonic.Completion.create(
18 api_key = account.key,
19 prompt = 'hello world'
20 )
21
22 print(response.completion.choices[0].text) # Hello! How may I assist you today?
23
24 # conversation
25
26 response = writesonic.Completion.create(
27 api_key = account.key,
28 prompt = 'what is my name ?',
29 enable_memory = True,
30 history_data = [
31 {
32 'is_sent': True,
33 'message': 'my name is Tekky'
34 },
35 {
36 'is_sent': False,
37 'message': 'hello Tekky'
38 }
39 ]
40 )
41
42 print(response.completion.choices[0].text) # Your name is Tekky.
43
44 # enable internet
45
46 response = writesonic.Completion.create(
47 api_key = account.key,
48 prompt = 'who won the quatar world cup ?',
49 enable_google_results = True
50 )
51
52 print(response.completion.choices[0].text) # Argentina won the 2022 FIFA World Cup tournament held in Qatar ...
53 ```
Deleted unfinished/writesonic/__init__.py +0 -163
@@ -1,163 +0,0 @@
1 from random import choice
2 from time import time
3
4 from colorama import Fore, init;
5 from names import get_first_name, get_last_name
6 from requests import Session
7 from requests import post
8
9 init()
10
11
12 class logger:
13 @staticmethod
14 def info(string) -> print:
15 import datetime
16 now = datetime.datetime.now()
17 return print(
18 f"{Fore.CYAN}{now.strftime('%Y-%m-%d %H:%M:%S')} {Fore.BLUE}INFO {Fore.MAGENTA}__main__ -> {Fore.RESET}{string}")
19
20
21 class SonicResponse:
22 class Completion:
23 class Choices:
24 def __init__(self, choice: dict) -> None:
25 self.text = choice['text']
26 self.content = self.text.encode()
27 self.index = choice['index']
28 self.logprobs = choice['logprobs']
29 self.finish_reason = choice['finish_reason']
30
31 def __repr__(self) -> str:
32 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>'''
33
34 def __init__(self, choices: dict) -> None:
35 self.choices = [self.Choices(choice) for choice in choices]
36
37 class Usage:
38 def __init__(self, usage_dict: dict) -> None:
39 self.prompt_tokens = usage_dict['prompt_chars']
40 self.completion_tokens = usage_dict['completion_chars']
41 self.total_tokens = usage_dict['total_chars']
42
43 def __repr__(self):
44 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>'''
45
46 def __init__(self, response_dict: dict) -> None:
47 self.response_dict = response_dict
48 self.id = response_dict['id']
49 self.object = response_dict['object']
50 self.created = response_dict['created']
51 self.model = response_dict['model']
52 self.completion = self.Completion(response_dict['choices'])
53 self.usage = self.Usage(response_dict['usage'])
54
55 def json(self) -> dict:
56 return self.response_dict
57
58
59 class Account:
60 session = Session()
61 session.headers = {
62 "connection": "keep-alive",
63 "sec-ch-ua": "\"Not_A Brand\";v=\"99\", \"Google Chrome\";v=\"109\", \"Chromium\";v=\"109\"",
64 "accept": "application/json, text/plain, */*",
65 "content-type": "application/json",
66 "sec-ch-ua-mobile": "?0",
67 "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",
68 "sec-ch-ua-platform": "\"Windows\"",
69 "sec-fetch-site": "same-origin",
70 "sec-fetch-mode": "cors",
71 "sec-fetch-dest": "empty",
72 # "accept-encoding" : "gzip, deflate, br",
73 "accept-language": "en-GB,en-US;q=0.9,en;q=0.8",
74 "cookie": ""
75 }
76
77 @staticmethod
78 def get_user():
79 password = f'0opsYouGoTme@1234'
80 f_name = get_first_name()
81 l_name = get_last_name()
82 hosts = ['gmail.com', 'protonmail.com', 'proton.me', 'outlook.com']
83
84 return {
85 "email": f"{f_name.lower()}.{l_name.lower()}@{choice(hosts)}",
86 "password": password,
87 "confirm_password": password,
88 "full_name": f'{f_name} {l_name}'
89 }
90
91 @staticmethod
92 def create(logging: bool = False):
93 while True:
94 try:
95 user = Account.get_user()
96 start = time()
97 response = Account.session.post("https://app.writesonic.com/api/session-login", json=user | {
98 "utmParams": "{}",
99 "visitorId": "0",
100 "locale": "en",
101 "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
102 "signInWith": "password",
103 "request_type": "signup",
104 })
105
106 if logging:
107 logger.info(f"\x1b[31mregister success\x1b[0m : '{response.text[:30]}...' ({int(time() - start)}s)")
108 logger.info(f"\x1b[31mid\x1b[0m : '{response.json()['id']}'")
109 logger.info(f"\x1b[31mtoken\x1b[0m : '{response.json()['token'][:30]}...'")
110
111 start = time()
112 response = Account.session.post("https://api.writesonic.com/v1/business/set-business-active",
113 headers={"authorization": "Bearer " + response.json()['token']})
114 key = response.json()["business"]["api_key"]
115 if logging: logger.info(f"\x1b[31mgot key\x1b[0m : '{key}' ({int(time() - start)}s)")
116
117 return Account.AccountResponse(user['email'], user['password'], key)
118
119 except Exception as e:
120 if logging: logger.info(f"\x1b[31merror\x1b[0m : '{e}'")
121 continue
122
123 class AccountResponse:
124 def __init__(self, email, password, key):
125 self.email = email
126 self.password = password
127 self.key = key
128
129
130 class Completion:
131 def create(
132 api_key: str,
133 prompt: str,
134 enable_memory: bool = False,
135 enable_google_results: bool = False,
136 history_data: list = []) -> SonicResponse:
137 response = post('https://api.writesonic.com/v2/business/content/chatsonic?engine=premium',
138 headers={"X-API-KEY": api_key},
139 json={
140 "enable_memory": enable_memory,
141 "enable_google_results": enable_google_results,
142 "input_text": prompt,
143 "history_data": history_data}).json()
144
145 return SonicResponse({
146 'id': f'cmpl-premium-{int(time())}',
147 'object': 'text_completion',
148 'created': int(time()),
149 'model': 'premium',
150
151 'choices': [{
152 'text': response['message'],
153 'index': 0,
154 'logprobs': None,
155 'finish_reason': 'stop'
156 }],
157
158 'usage': {
159 'prompt_chars': len(prompt),
160 'completion_chars': len(response['message']),
161 'total_chars': len(prompt) + len(response['message'])
162 }
163 })