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 Apr 27, 2023
2 parents d2d81b7 + e4aefb0 commit d8ec09c
Show file tree
Hide file tree
Showing 13 changed files with 546 additions and 302 deletions.
30 changes: 7 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
# GPT4free - use ChatGPT, for free!!

##### You may join our discord server for updates and support ; )
- https://discord.gg/gpt4free
- [Discord Link](https://discord.gg/gpt4free)

<img width="1383" alt="image" src="https://user-images.githubusercontent.com/98614666/233799515-1a7cb6a3-b17f-42c4-956d-8d2a0664466f.png">

Have you ever come across some amazing projects that you couldn't use **just because you didn't have an OpenAI API key?**

**We've got you covered!** This repository offers **reverse-engineered** third-party APIs for `GPT-4/3.5`, sourced from various websites. You can simply **download** this repository, and use the available modules, which are designed to be used **just like OpenAI's official package**. **Unleash ChatGPT's potential for your projects, now!** You are welcome ; ).

By the way, thank you so much for [![Stars](https://img.shields.io/github/stars/xtekky/gpt4free?style=social)](https://github.com/xtekky/gpt4free/stargazers) and all the support!!

## Announcement
Dear Gpt4free Community,

I want to thank you for your interest in and support of this project, which I only intended to be for entertainment and educational purposes; I had no idea it would end up being so popular.

I'm aware of the concerns about the project's legality and its impact on smaller sites hosting APIs. I take these concerns seriously and plan to address them.

Here's what I'm doing to fix these issues:

1. Removing APIs from smaller sites: To reduce the impact on smaller sites, I have removed their APIs from the repository. Please shoot me a dm if you are an owner of a site and want it removed.

2. Commitment to ethical use: I want to emphasize my commitment to promoting ethical use of language models. I don't support any illegal or unethical behavior, and I expect users to follow the same principles.

Thank you for your support and understanding. I appreciate your continued interest in gpt4free and am committed to addressing your concerns.

Sincerely,
xtekky
By the way, thank you so much for `11k` stars and all the support!!

## Legal Notice <a name="legal-notice"></a>

Expand Down Expand Up @@ -55,9 +37,10 @@ Please note the following:
| **Legal Notice** | Legal notice or disclaimer | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#legal-notice) | - |
| **Copyright** | Copyright information | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#copyright) | - |
| **Usage Examples** | | | |
| `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) |
| `forefront` | Example usage for forefront (gpt-4) | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./forefront/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) | | |
| `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) | |
| `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) |
| `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)
| `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) |
| **Try it Out** | | | |
| 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) | - |
| replit Example (feel free to fork this repl) | Example usage for gpt4free | [![](https://img.shields.io/badge/Open%20in-Replit-1A1E27?logo=replit)](https://replit.com/@gpt4free/gpt4free-webui) | - |
Expand All @@ -74,8 +57,9 @@ Please note the following:

## Current Sites <a name="current-sites"></a>

| Website | Model(s) |
| Website s | Model(s) |
| ---------------------------------------------------- | ------------------------------- |
| [forefront.ai](https://chat.forefront.ai) | GPT-4/3.5 |
| [poe.com](https://poe.com) | GPT-4/3.5 |
| [writesonic.com](https://writesonic.com) | GPT-3.5 / Internet |
| [t3nsor.com](https://t3nsor.com) | GPT-3.5 |
Expand Down
15 changes: 15 additions & 0 deletions Singularity/gpt4free.sif
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Bootstrap: docker
From: python:3.10-slim

%post
apt-get update && apt-get install -y git
git clone https://github.com/xtekky/gpt4free.git
cd gpt4free
pip install --no-cache-dir -r requirements.txt
cp gui/streamlit_app.py .

%expose
8501

%startscript
exec streamlit run streamlit_app.py
15 changes: 15 additions & 0 deletions forefront/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### Example: `forefront` (use like openai pypi package) <a name="example-forefront"></a>

```python
import forefront

# create an account
token = forefront.Account.create(logging=True)
print(token)

# get a response
for response in forefront.StreamingCompletion.create(token = token,
prompt = 'hello world', model='gpt-4'):

print(response.completion.choices[0].text, end = '')
```
145 changes: 145 additions & 0 deletions forefront/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
from tls_client import Session
from forefront.mail import Mail
from time import time, sleep
from re import match
from forefront.typing import ForeFrontResponse
from uuid import uuid4
from requests import post
from json import loads


class Account:
def create(proxy = None, logging = False):

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

start = time()

mail = Mail(proxies)
mail_token = None
mail_adress = mail.get_mail()

#print(mail_adress)

client = Session(client_identifier='chrome110')
client.proxies = proxies
client.headers = {
"origin": "https://accounts.forefront.ai",
"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",
}

response = client.post('https://clerk.forefront.ai/v1/client/sign_ups?_clerk_js_version=4.32.6',
data = {
"email_address": mail_adress
}
)

trace_token = response.json()['response']['id']
if logging: print(trace_token)

response = client.post(f"https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/prepare_verification?_clerk_js_version=4.32.6",
data = {
"strategy" : "email_code",
}
)

if logging: print(response.text)

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

while True:
sleep(1)
for _ in mail.fetch_inbox():
print(mail.get_message_content(_["id"]))
mail_token = match(r"(\d){5,6}", mail.get_message_content(_["id"])).group(0)

if mail_token:
break

if logging: print(mail_token)

response = client.post(f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/attempt_verification?_clerk_js_version=4.38.4', data = {
'code': mail_token,
'strategy': 'email_code'
})

if logging: print(response.json())

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

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

if logging: print(time() - start)

return token


class StreamingCompletion:
def create(
token = None,
chatId = None,
prompt = '',
actionType = 'new',
defaultPersona = '607e41fe-95be-497e-8e97-010a59b2e2c0', # default
model = 'gpt-4') -> ForeFrontResponse:

if not token: raise Exception('Token is required!')
if not chatId: chatId = str(uuid4())

headers = {
'authority' : 'chat-server.tenant-forefront-default.knative.chi.coreweave.com',
'accept' : '*/*',
'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',
'authorization' : 'Bearer ' + token,
'cache-control' : 'no-cache',
'content-type' : 'application/json',
'origin' : 'https://chat.forefront.ai',
'pragma' : 'no-cache',
'referer' : 'https://chat.forefront.ai/',
'sec-ch-ua' : '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
'sec-ch-ua-mobile' : '?0',
'sec-ch-ua-platform': '"macOS"',
'sec-fetch-dest' : 'empty',
'sec-fetch-mode' : 'cors',
'sec-fetch-site' : 'cross-site',
'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',
}

json_data = {
'text' : prompt,
'action' : actionType,
'parentId' : chatId,
'workspaceId' : chatId,
'messagePersona' : defaultPersona,
'model' : model
}

for chunk in post('https://chat-server.tenant-forefront-default.knative.chi.coreweave.com/chat',
headers=headers, json=json_data, stream=True).iter_lines():

if b'finish_reason":null' in chunk:
data = loads(chunk.decode('utf-8').split('data: ')[1])
token = data['choices'][0]['delta'].get('content')

if token != None:
yield ForeFrontResponse({
'id' : chatId,
'object' : 'text_completion',
'created': int(time()),
'model' : model,
'choices': [{
'text' : token,
'index' : 0,
'logprobs' : None,
'finish_reason' : 'stop'
}],
'usage': {
'prompt_tokens' : len(prompt),
'completion_tokens' : len(token),
'total_tokens' : len(prompt) + len(token)
}
})
55 changes: 55 additions & 0 deletions forefront/mail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from requests import Session
from string import ascii_letters
from random import choices

class Mail:
def __init__(self, proxies: dict = None) -> None:
self.client = Session()
self.client.proxies = proxies
self.client.headers = {
"host": "api.mail.tm",
"connection": "keep-alive",
"sec-ch-ua": "\"Google Chrome\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"",
"accept": "application/json, text/plain, */*",
"content-type": "application/json",
"sec-ch-ua-mobile": "?0",
"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",
"sec-ch-ua-platform": "\"macOS\"",
"origin": "https://mail.tm",
"sec-fetch-site": "same-site",
"sec-fetch-mode": "cors",
"sec-fetch-dest": "empty",
"referer": "https://mail.tm/",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8"
}

def get_mail(self) -> str:
token = ''.join(choices(ascii_letters, k=14)).lower()
init = self.client.post("https://api.mail.tm/accounts", json={
"address" : f"{token}@bugfoo.com",
"password": token
})

if init.status_code == 201:
resp = self.client.post("https://api.mail.tm/token", json = {
**init.json(),
"password": token
})

self.client.headers['authorization'] = 'Bearer ' + resp.json()['token']

return f"{token}@bugfoo.com"

else:
raise Exception("Failed to create email")

def fetch_inbox(self):
return self.client.get(f"https://api.mail.tm/messages").json()["hydra:member"]

def get_message(self, message_id: str):
return self.client.get(f"https://api.mail.tm/messages/{message_id}").json()

def get_message_content(self, message_id: str):
return self.get_message(message_id)["text"]

37 changes: 37 additions & 0 deletions forefront/typing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class ForeFrontResponse:
class Completion:
class Choices:
def __init__(self, choice: dict) -> None:
self.text = choice['text']
self.content = self.text.encode()
self.index = choice['index']
self.logprobs = choice['logprobs']
self.finish_reason = choice['finish_reason']

def __repr__(self) -> str:
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>'''

def __init__(self, choices: dict) -> None:
self.choices = [self.Choices(choice) for choice in choices]

class Usage:
def __init__(self, usage_dict: dict) -> None:
self.prompt_tokens = usage_dict['prompt_tokens']
self.completion_tokens = usage_dict['completion_tokens']
self.total_tokens = usage_dict['total_tokens']

def __repr__(self):
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>'''

def __init__(self, response_dict: dict) -> None:

self.response_dict = response_dict
self.id = response_dict['id']
self.object = response_dict['object']
self.created = response_dict['created']
self.model = response_dict['model']
self.completion = self.Completion(response_dict['choices'])
self.usage = self.Usage(response_dict['usage'])

def json(self) -> dict:
return self.response_dict
5 changes: 5 additions & 0 deletions gui/streamlit_app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), os.path.pardir))

import streamlit as st
import phind

Expand Down
2 changes: 1 addition & 1 deletion quora/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ from quora import Poe

# available models: ['Sage', 'GPT-4', 'Claude+', 'Claude-instant', 'ChatGPT', 'Dragonfly', 'NeevaAI']

poe = Poe(model='ChatGPT')
poe = Poe(model='ChatGPT', driver='firefox', cookie_path='cookie.json', driver_path='path_of_driver')
poe.chat('who won the football world cup most?')

# new bot creation
Expand Down
Loading

0 comments on commit d8ec09c

Please sign in to comment.