Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
xtekky authored May 4, 2023
2 parents 82a3a03 + 4a26913 commit e865fcb
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 258 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.tabCompletion": "on",
"diffEditor.codeLens": true
}
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ Just API's from some language model sites.
<td><a href="https://github.com/xtekky/gpt4free/issues"><img alt="Issues" src="https://img.shields.io/github/issues/xtekky/gpt4free?style=flat-square&labelColor=343b41"/></a></td>
<td><a href="https://github.com/xtekky/gpt4free/pulls"><img alt="Pull Requests" src="https://img.shields.io/github/issues-pr/xtekky/gpt4free?style=flat-square&labelColor=343b41"/></a></td>
</tr>
<tr>
<td><a href="https://github.com/xiangsx/gpt4free-ts"><b>gpt4free-ts</b></a></td>
<td><a href="https://github.com/xiangsx/gpt4free-ts/stargazers"><img alt="Stars" src="https://img.shields.io/github/stars/xiangsx/gpt4free-ts?style=flat-square&labelColor=343b41"/></a></td>
<td><a href="https://github.com/xiangsx/gpt4free-ts/network/members"><img alt="Forks" src="https://img.shields.io/github/forks/xiangsx/gpt4free-ts?style=flat-square&labelColor=343b41"/></a></td>
<td><a href="https://github.com/xiangsx/gpt4free-ts/issues"><img alt="Issues" src="https://img.shields.io/github/issues/xiangsx/gpt4free-ts?style=flat-square&labelColor=343b41"/></a></td>
<td><a href="https://github.com/xiangsx/gpt4free-ts/pulls"><img alt="Pull Requests" src="https://img.shields.io/github/issues-pr/xiangsx/gpt4free-ts?style=flat-square&labelColor=343b41"/></a></td>
</tr>
<tr>
<td><a href="https://github.com/xtekky/chatgpt-clone"><b>ChatGPT-Clone</b></a></td>
<td><a href="https://github.com/xtekky/chatgpt-clone/stargazers"><img alt="Stars" src="https://img.shields.io/github/stars/xtekky/chatgpt-clone?style=flat-square&labelColor=343b41"/></a></td>
Expand Down
79 changes: 24 additions & 55 deletions gpt4free/forefront/__init__.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,27 @@
import os
import pickle
from json import loads
from xtempmail import Email
from re import findall
from typing import Optional, Generator
from faker import Faker
from time import time, sleep
from typing import Generator, Optional
from uuid import uuid4

from fake_useragent import UserAgent
from pymailtm import MailTm, Message
from requests import post
from tls_client import Session

from .typing import ForeFrontResponse


class Account:
COOKIES_FILE_NAME = 'cookies.pickle'

@staticmethod
def login(proxy: Optional[str] = None, logging: bool = False) -> str:
if not os.path.isfile(Account.COOKIES_FILE_NAME):
return Account.create(proxy, logging)

with open(Account.COOKIES_FILE_NAME, 'rb') as f:
cookies = pickle.load(f)
proxies = {'http': 'http://' + proxy, 'https': 'http://' + proxy} if proxy else False

client = Session(client_identifier='chrome110')
client.proxies = proxies
client.cookies.update(cookies)

if Account.is_cookie_enabled(client):
response = client.get('https://clerk.forefront.ai/v1/client?_clerk_js_version=4.38.4')
return response.json()['response']['sessions'][0]['last_active_token']['jwt']
else:
return Account.create(proxy, logging)

@staticmethod
def create(proxy: Optional[str] = None, logging: bool = False, save_cookies: bool = False) -> str:
def create(proxy: Optional[str] = None, logging: bool = False):
proxies = {'http': 'http://' + proxy, 'https': 'http://' + proxy} if proxy else False
faker = Faker()
name = (faker.name().replace(' ', '_')).lower()

start = time()

mail_client = MailTm().get_account()
mail_address = mail_client.address
mail_client = Email(name=name)
mail_address = mail_client.email

client = Session(client_identifier='chrome110')
client.proxies = proxies
Expand All @@ -66,39 +44,34 @@ def create(proxy: Optional[str] = None, logging: bool = False, save_cookies: boo

response = client.post(
f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/prepare_verification?_clerk_js_version=4.38.4',
data={'strategy': 'email_link', 'redirect_url': 'https://accounts.forefront.ai/sign-up/verify'},
data={
'strategy': 'email_link',
'redirect_url': 'https://accounts.forefront.ai/sign-up/verify'
},
)

if logging:
print(response.text)

if 'sign_up_attempt' not in response.text:
return 'Failed to create account!'

while True:
sleep(1)
new_message: Message = mail_client.wait_for_message()
if logging:
print(new_message.data['id'])

verification_url = findall(r'https:\/\/clerk\.forefront\.ai\/v1\/verify\?token=\w.+', new_message.text)[0]

verification_url = None
new_message = mail_client.get_new_message(5)
for msg in new_message:
verification_url = findall(r'https:\/\/clerk\.forefront\.ai\/v1\/verify\?token=\w.+', msg.text)[0]
if verification_url:
break


if verification_url is None or not verification_url:
raise RuntimeError('Error while obtaining verfication URL!')
if logging:
print(verification_url)

response = client.get(verification_url)

response = client.get('https://clerk.forefront.ai/v1/client?_clerk_js_version=4.38.4')

token = response.json()['response']['sessions'][0]['last_active_token']['jwt']

if save_cookies:
with open(Account.COOKIES_FILE_NAME, 'wb') as f:
pickle.dump(client.cookies, f)

with open('accounts.txt', 'a') as f:
f.write(f'{mail_address}:{token}\n')

Expand All @@ -107,11 +80,6 @@ def create(proxy: Optional[str] = None, logging: bool = False, save_cookies: boo

return token

@staticmethod
def is_cookie_enabled(client: Session) -> bool:
response = client.get('https://chat.forefront.ai/')
return 'window.startClerk' in response.text


class StreamingCompletion:
@staticmethod
Expand All @@ -122,14 +90,14 @@ def create(
action_type='new',
default_persona='607e41fe-95be-497e-8e97-010a59b2e2c0', # default
model='gpt-4',
proxy=None,
proxy=None
) -> Generator[ForeFrontResponse, None, None]:
if not token:
raise Exception('Token is required!')
if not chat_id:
chat_id = str(uuid4())

proxies = {'http': 'http://' + proxy, 'https': 'http://' + proxy} if proxy else None
proxies = { 'http': 'http://' + proxy, 'https': 'http://' + proxy } if proxy else None

headers = {
'authority': 'chat-server.tenant-forefront-default.knative.chi.coreweave.com',
Expand Down Expand Up @@ -197,7 +165,7 @@ def create(
action_type='new',
default_persona='607e41fe-95be-497e-8e97-010a59b2e2c0', # default
model='gpt-4',
proxy=None,
proxy=None
) -> ForeFrontResponse:
text = ''
final_response = None
Expand All @@ -208,7 +176,7 @@ def create(
action_type=action_type,
default_persona=default_persona,
model=model,
proxy=proxy,
proxy=proxy
):
if response:
final_response = response
Expand All @@ -220,3 +188,4 @@ def create(
raise Exception('Unable to get the response, Please try again')

return final_response

18 changes: 0 additions & 18 deletions gpt4free/italygpt/README.md

This file was deleted.

28 changes: 0 additions & 28 deletions gpt4free/italygpt/__init__.py

This file was deleted.

4 changes: 2 additions & 2 deletions gpt4free/quora/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class Model:
def create(
token: str,
model: str = 'gpt-3.5-turbo', # claude-instant
system_prompt: str = 'You are ChatGPT a large language model developed by Openai. Answer as consisely as possible',
description: str = 'gpt-3.5 language model from openai, skidded by poe.com',
system_prompt: str = 'You are ChatGPT a large language model. Answer as consisely as possible',
description: str = 'gpt-3.5 language model',
handle: str = None,
) -> ModelResponse:
if not handle:
Expand Down
4 changes: 4 additions & 0 deletions gpt4free/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import forefront
token = forefront.Account.create()
response = forefront.Completion.create(token=token, prompt='Hello!')
print(response)
2 changes: 2 additions & 0 deletions gpt4free/theb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ def get_response(prompt: str, proxy: Optional[str] = None) -> str:
for message in Completion.create(prompt, proxy):
response_list.append(message)
return ''.join(response_list)

Completion.message_queue.put(response.decode(errors='replace'))
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.poetry]
name = "openai-rev"
name = "gpt4free"
version = "0.1.0"
description = ""
authors = []
Expand Down
8 changes: 0 additions & 8 deletions unfinished/test.py

This file was deleted.

41 changes: 0 additions & 41 deletions unfinished/vercelai/__init__.py

This file was deleted.

33 changes: 0 additions & 33 deletions unfinished/vercelai/test.js

This file was deleted.

Loading

0 comments on commit e865fcb

Please sign in to comment.