t.me/xtekky commited on
Commit
98d2b41
·
1 Parent(s): d5d5d8b

forefront (gpt-4)

Browse files
README.md CHANGED
@@ -55,8 +55,12 @@ Please note the following:
55
  | **Legal Notice** | Legal notice or disclaimer | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#legal-notice) | - |
56
  | **Copyright** | Copyright information | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#copyright) | - |
57
  | **Usage Examples** | | | |
 
 
58
  | `quora (poe)` | Example usage for quora | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./quora/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) |
 
59
  | `phind` | Example usage for phind | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./phind/README.md) | ![Inactive](https://img.shields.io/badge/Active-brightgreen) |
 
60
  | `you` | Example usage for you | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./you/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen)
61
  | **Try it Out** | | | |
62
  | Google Colab Jupyter Notebook | Example usage for gpt4free | [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DanielShemesh/gpt4free-colab/blob/main/gpt4free.ipynb) | - |
@@ -74,8 +78,9 @@ Please note the following:
74
 
75
  ## Current Sites <a name="current-sites"></a>
76
 
77
- | Website | Model(s) |
78
  | ---------------------------------------------------- | ------------------------------- |
 
79
  | [poe.com](https://poe.com) | GPT-4/3.5 |
80
  | [writesonic.com](https://writesonic.com) | GPT-3.5 / Internet |
81
  | [t3nsor.com](https://t3nsor.com) | GPT-3.5 |
 
55
  | **Legal Notice** | Legal notice or disclaimer | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#legal-notice) | - |
56
  | **Copyright** | Copyright information | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#copyright) | - |
57
  | **Usage Examples** | | | |
58
+ | `forefront` | Example usage for quora | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./forefront/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) |
59
+
60
  | `quora (poe)` | Example usage for quora | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./quora/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) |
61
+
62
  | `phind` | Example usage for phind | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./phind/README.md) | ![Inactive](https://img.shields.io/badge/Active-brightgreen) |
63
+
64
  | `you` | Example usage for you | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./you/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen)
65
  | **Try it Out** | | | |
66
  | Google Colab Jupyter Notebook | Example usage for gpt4free | [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DanielShemesh/gpt4free-colab/blob/main/gpt4free.ipynb) | - |
 
78
 
79
  ## Current Sites <a name="current-sites"></a>
80
 
81
+ | Website s | Model(s) |
82
  | ---------------------------------------------------- | ------------------------------- |
83
+ | [forefront.ai](https://chat.forefront.ai) | GPT-4/3.5 |
84
  | [poe.com](https://poe.com) | GPT-4/3.5 |
85
  | [writesonic.com](https://writesonic.com) | GPT-3.5 / Internet |
86
  | [t3nsor.com](https://t3nsor.com) | GPT-3.5 |
forefront/README.md ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Example: `forefront` (use like openai pypi package) <a name="example-forefront"></a>
2
+
3
+ ```python
4
+ import forefront
5
+
6
+ # create an account
7
+ token = forefront.Account.create(logging=True)
8
+ print(token)
9
+
10
+ # get a response
11
+ for response in forefront.StreamingCompletion.create(token = token,
12
+ prompt = 'hello world', model='gpt-4'):
13
+
14
+ print(response.completion.choices[0].text, end = '')
15
+ ```
forefront/__init__.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from tls_client import Session
2
+ from forefront.mail import Mail
3
+ from time import time, sleep
4
+ from re import match
5
+ from forefront.typing import ForeFrontResponse
6
+ from uuid import uuid4
7
+ from requests import post
8
+ from json import loads
9
+
10
+
11
+ class Account:
12
+ def create(proxy = None, logging = False):
13
+
14
+ proxies = {
15
+ 'http': 'http://' + proxy,
16
+ 'https': 'http://' + proxy } if proxy else False
17
+
18
+ start = time()
19
+
20
+ mail = Mail(proxies)
21
+ mail_token = None
22
+ mail_adress = mail.get_mail()
23
+
24
+ #print(mail_adress)
25
+
26
+ client = Session(client_identifier='chrome110')
27
+ client.proxies = proxies
28
+ client.headers = {
29
+ "origin": "https://accounts.forefront.ai",
30
+ "user-agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36",
31
+ }
32
+
33
+ response = client.post('https://clerk.forefront.ai/v1/client/sign_ups?_clerk_js_version=4.32.6',
34
+ data = {
35
+ "email_address": mail_adress
36
+ }
37
+ )
38
+
39
+ trace_token = response.json()['response']['id']
40
+ if logging: print(trace_token)
41
+
42
+ response = client.post(f"https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/prepare_verification?_clerk_js_version=4.32.6",
43
+ data = {
44
+ "strategy" : "email_code",
45
+ }
46
+ )
47
+
48
+ if logging: print(response.text)
49
+
50
+ if not 'sign_up_attempt' in response.text:
51
+ return 'Failed to create account!'
52
+
53
+ while True:
54
+ sleep(1)
55
+ for _ in mail.fetch_inbox():
56
+ print(mail.get_message_content(_["id"]))
57
+ mail_token = match(r"(\d){5,6}", mail.get_message_content(_["id"])).group(0)
58
+
59
+ if mail_token:
60
+ break
61
+
62
+ if logging: print(mail_token)
63
+
64
+ response = client.post(f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/attempt_verification?_clerk_js_version=4.38.4', data = {
65
+ 'code': mail_token,
66
+ 'strategy': 'email_code'
67
+ })
68
+
69
+ if logging: print(response.json())
70
+
71
+ token = response.json()['client']['sessions'][0]['last_active_token']['jwt']
72
+
73
+ with open('accounts.txt', 'a') as f:
74
+ f.write(f'{mail_adress}:{token}\n')
75
+
76
+ if logging: print(time() - start)
77
+
78
+ return token
79
+
80
+
81
+ class StreamingCompletion:
82
+ def create(
83
+ token = None,
84
+ chatId = None,
85
+ prompt = '',
86
+ actionType = 'new',
87
+ defaultPersona = '607e41fe-95be-497e-8e97-010a59b2e2c0', # default
88
+ model = 'gpt-4') -> ForeFrontResponse:
89
+
90
+ if not token: raise Exception('Token is required!')
91
+ if not chatId: chatId = str(uuid4())
92
+
93
+ headers = {
94
+ 'authority' : 'chat-server.tenant-forefront-default.knative.chi.coreweave.com',
95
+ 'accept' : '*/*',
96
+ 'accept-language' : 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3',
97
+ 'authorization' : 'Bearer ' + token,
98
+ 'cache-control' : 'no-cache',
99
+ 'content-type' : 'application/json',
100
+ 'origin' : 'https://chat.forefront.ai',
101
+ 'pragma' : 'no-cache',
102
+ 'referer' : 'https://chat.forefront.ai/',
103
+ 'sec-ch-ua' : '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
104
+ 'sec-ch-ua-mobile' : '?0',
105
+ 'sec-ch-ua-platform': '"macOS"',
106
+ 'sec-fetch-dest' : 'empty',
107
+ 'sec-fetch-mode' : 'cors',
108
+ 'sec-fetch-site' : 'cross-site',
109
+ 'user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36',
110
+ }
111
+
112
+ json_data = {
113
+ 'text' : prompt,
114
+ 'action' : actionType,
115
+ 'parentId' : chatId,
116
+ 'workspaceId' : chatId,
117
+ 'messagePersona' : defaultPersona,
118
+ 'model' : model
119
+ }
120
+
121
+ for chunk in post('https://chat-server.tenant-forefront-default.knative.chi.coreweave.com/chat',
122
+ headers=headers, json=json_data, stream=True).iter_lines():
123
+
124
+ if b'finish_reason":null' in chunk:
125
+ data = loads(chunk.decode('utf-8').split('data: ')[1])
126
+ token = data['choices'][0]['delta'].get('content')
127
+
128
+ if token != None:
129
+ yield ForeFrontResponse({
130
+ 'id' : chatId,
131
+ 'object' : 'text_completion',
132
+ 'created': int(time()),
133
+ 'model' : model,
134
+ 'choices': [{
135
+ 'text' : token,
136
+ 'index' : 0,
137
+ 'logprobs' : None,
138
+ 'finish_reason' : 'stop'
139
+ }],
140
+ 'usage': {
141
+ 'prompt_tokens' : len(prompt),
142
+ 'completion_tokens' : len(token),
143
+ 'total_tokens' : len(prompt) + len(token)
144
+ }
145
+ })
forefront/mail.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from requests import Session
2
+ from string import ascii_letters
3
+ from random import choices
4
+
5
+ class Mail:
6
+ def __init__(self, proxies: dict = None) -> None:
7
+ self.client = Session()
8
+ self.client.proxies = proxies
9
+ self.client.headers = {
10
+ "host": "api.mail.tm",
11
+ "connection": "keep-alive",
12
+ "sec-ch-ua": "\"Google Chrome\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"",
13
+ "accept": "application/json, text/plain, */*",
14
+ "content-type": "application/json",
15
+ "sec-ch-ua-mobile": "?0",
16
+ "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36",
17
+ "sec-ch-ua-platform": "\"macOS\"",
18
+ "origin": "https://mail.tm",
19
+ "sec-fetch-site": "same-site",
20
+ "sec-fetch-mode": "cors",
21
+ "sec-fetch-dest": "empty",
22
+ "referer": "https://mail.tm/",
23
+ "accept-encoding": "gzip, deflate, br",
24
+ "accept-language": "en-GB,en-US;q=0.9,en;q=0.8"
25
+ }
26
+
27
+ def get_mail(self) -> str:
28
+ token = ''.join(choices(ascii_letters, k=14)).lower()
29
+ init = self.client.post("https://api.mail.tm/accounts", json={
30
+ "address" : f"{token}@bugfoo.com",
31
+ "password": token
32
+ })
33
+
34
+ if init.status_code == 201:
35
+ resp = self.client.post("https://api.mail.tm/token", json = {
36
+ **init.json(),
37
+ "password": token
38
+ })
39
+
40
+ self.client.headers['authorization'] = 'Bearer ' + resp.json()['token']
41
+
42
+ return f"{token}@bugfoo.com"
43
+
44
+ else:
45
+ raise Exception("Failed to create email")
46
+
47
+ def fetch_inbox(self):
48
+ return self.client.get(f"https://api.mail.tm/messages").json()["hydra:member"]
49
+
50
+ def get_message(self, message_id: str):
51
+ return self.client.get(f"https://api.mail.tm/messages/{message_id}").json()
52
+
53
+ def get_message_content(self, message_id: str):
54
+ return self.get_message(message_id)["text"]
55
+
forefront/typing.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class ForeFrontResponse:
2
+ class Completion:
3
+ class Choices:
4
+ def __init__(self, choice: dict) -> None:
5
+ self.text = choice['text']
6
+ self.content = self.text.encode()
7
+ self.index = choice['index']
8
+ self.logprobs = choice['logprobs']
9
+ self.finish_reason = choice['finish_reason']
10
+
11
+ def __repr__(self) -> str:
12
+ 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>'''
13
+
14
+ def __init__(self, choices: dict) -> None:
15
+ self.choices = [self.Choices(choice) for choice in choices]
16
+
17
+ class Usage:
18
+ def __init__(self, usage_dict: dict) -> None:
19
+ self.prompt_tokens = usage_dict['prompt_tokens']
20
+ self.completion_tokens = usage_dict['completion_tokens']
21
+ self.total_tokens = usage_dict['total_tokens']
22
+
23
+ def __repr__(self):
24
+ 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>'''
25
+
26
+ def __init__(self, response_dict: dict) -> None:
27
+
28
+ self.response_dict = response_dict
29
+ self.id = response_dict['id']
30
+ self.object = response_dict['object']
31
+ self.created = response_dict['created']
32
+ self.model = response_dict['model']
33
+ self.completion = self.Completion(response_dict['choices'])
34
+ self.usage = self.Usage(response_dict['usage'])
35
+
36
+ def json(self) -> dict:
37
+ return self.response_dict
testing/forefront_test.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import forefront
2
+
3
+ # create an account
4
+ token = forefront.Account.create(logging=True)
5
+ print(token)
6
+
7
+ # get a response
8
+ for response in forefront.StreamingCompletion.create(token = token,
9
+ prompt = 'hello world', model='gpt-4'):
10
+
11
+ print(response.completion.choices[0].text, end = '')