summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authort.me/xtekky <98614666+xtekky@users.noreply.github.com>2023-04-30 13:42:43 +0200
committert.me/xtekky <98614666+xtekky@users.noreply.github.com>2023-04-30 13:42:43 +0200
commit21c82d873ab40d92b2302f7fcdc0975477eb9bec (patch)
treec70d64e5e0b14032f45cf3e17840c97ffbe54e8e
parentadded a site and some refratoring (diff)
parentMerge pull request #292 from naa7/patch-8 (diff)
downloadgpt4free-21c82d873ab40d92b2302f7fcdc0975477eb9bec.tar
gpt4free-21c82d873ab40d92b2302f7fcdc0975477eb9bec.tar.gz
gpt4free-21c82d873ab40d92b2302f7fcdc0975477eb9bec.tar.bz2
gpt4free-21c82d873ab40d92b2302f7fcdc0975477eb9bec.tar.lz
gpt4free-21c82d873ab40d92b2302f7fcdc0975477eb9bec.tar.xz
gpt4free-21c82d873ab40d92b2302f7fcdc0975477eb9bec.tar.zst
gpt4free-21c82d873ab40d92b2302f7fcdc0975477eb9bec.zip
Diffstat (limited to '')
-rw-r--r--README.md45
-rw-r--r--docker-compose.yaml9
-rw-r--r--gpt4free/cocalc/__init__.py50
-rw-r--r--gpt4free/forefront/__init__.py41
-rw-r--r--gpt4free/forefront/mail.py52
-rw-r--r--gpt4free/you/README.md6
-rw-r--r--requirements.txt3
7 files changed, 91 insertions, 115 deletions
diff --git a/README.md b/README.md
index 8a92c7c2..a2ec683c 100644
--- a/README.md
+++ b/README.md
@@ -19,27 +19,26 @@ Please note the following:
3. **Educational Purposes Only**: This repository and its content are provided strictly for educational purposes. By using the information and code provided, users acknowledge that they are using the APIs and models at their own risk and agree to comply with any applicable laws and regulations.
## Table of Contents
-
-| Section | Description | Link | Status |
-| -------------------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- | --- | --- |
-| **To do list** | List of tasks to be done | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#todo) | - |
-| **Current Sites** | Current websites or platforms that can be used as APIs | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#current-sites) | - |
-| **Best Sites for gpt4** | Recommended websites or platforms for gpt4 | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#best-sites) | - |
-| **Streamlit GPT4Free GUI** | Web-based graphical user interface for interacting with gpt4free | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#streamlit-gpt4free-gui) | - |
-| **Docker** | Instructions on how to run gpt4free in a Docker container | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#docker-instructions) | - |
-| **ChatGPT clone** | A ChatGPT clone with new features and scalability | [![Link to Website](https://img.shields.io/badge/Link-Visit%20Site-blue)](https://chat.chatbot.sex/chat) | - |
-| **How to install** | Instructions on how to install gpt4free | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#install) | - |
-| **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) | - |
-| **Star History** | Star History | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#star-history) | - |
-| **Usage Examples** | | | |
-| `theb` | Example usage for theb (gpt-3.5) | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](openai_rev/theb/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)](gpt4free/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)](gpt4free/quora/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)](gpt4free/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) | - |
+| Section | Description | Link | Status |
+| ------- | ----------- | ---- | ------ |
+| **To do list** | List of tasks to be done | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#todo) | - |
+| **Current Sites** | Current websites or platforms that can be used as APIs | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#current-sites) | - |
+| **Best Sites for gpt4** | Recommended websites or platforms for gpt4 | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#best-sites) | - |
+| **Streamlit GPT4Free GUI** | Web-based graphical user interface for interacting with gpt4free | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#streamlit-gpt4free-gui) | - |
+| **Docker** | Instructions on how to run gpt4free in a Docker container | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#docker-instructions) | - |
+| **ChatGPT clone** | A ChatGPT clone with new features and scalability | [![Link to Website](https://img.shields.io/badge/Link-Visit%20Site-blue)](https://chat.chatbot.sex/chat) | - |
+| **How to install** | Instructions on how to install gpt4free | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#install) | - |
+| **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) | - |
+| **Star History** | Star History | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#star-history) | - |
+| **Usage Examples** | | | |
+| `theb` | Example usage for theb (gpt-3.5) | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](gpt4free/theb/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)](gpt4free/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)](gpt4free/quora/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)](gpt4free/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) | - |
## Todo <a name="todo"></a>
@@ -102,6 +101,10 @@ Run
```
docker run -p 8501:8501 gpt4free:latest
```
+Another way - docker-compose (no docker build/run needed)
+```
+docker-compose up -d
+```
## Deploy using docker-compose
diff --git a/docker-compose.yaml b/docker-compose.yaml
new file mode 100644
index 00000000..3afd6cdf
--- /dev/null
+++ b/docker-compose.yaml
@@ -0,0 +1,9 @@
+version: "3.9"
+
+services:
+ gpt4free:
+ build:
+ context: .
+ dockerfile: Dockerfile
+ ports:
+ - "8501:8501"
diff --git a/gpt4free/cocalc/__init__.py b/gpt4free/cocalc/__init__.py
index 372f29a4..e122051a 100644
--- a/gpt4free/cocalc/__init__.py
+++ b/gpt4free/cocalc/__init__.py
@@ -9,29 +9,52 @@ class CoCalcResponse(BaseModel):
class Completion:
+ """A class for generating text completions using CoCalc's GPT-based chatbot."""
+
+ API_ENDPOINT = "https://cocalc.com/api/v2/openai/chatgpt"
+ DEFAULT_SYSTEM_PROMPT = "ASSUME I HAVE FULL ACCESS TO COCALC. "
+
@staticmethod
def create(prompt: str, cookie_input: str) -> CoCalcResponse:
+ """
+ Generate a text completion for the given prompt using CoCalc's GPT-based chatbot.
+
+ Args:
+ prompt: The text prompt to complete.
+ cookie_input: The cookie required to authenticate the chatbot API request.
+
+ Returns:
+ A CoCalcResponse object containing the text completion and a boolean indicating
+ whether the request was successful.
+ """
+
# Initialize a session with custom headers
session = Completion._initialize_session(cookie_input)
# Set the data that will be submitted
- payload = Completion._create_payload(prompt, 'ASSUME I HAVE FULL ACCESS TO COCALC. ')
+ payload = Completion._create_payload(prompt, Completion.DEFAULT_SYSTEM_PROMPT)
- # Submit the request and return the results
- return Completion._submit_request(session, payload)
+ try:
+ # Submit the request and return the results
+ response = session.post(Completion.API_ENDPOINT, json=payload).json()
+ return CoCalcResponse(text=response['output'], status=response['success'])
+ except requests.exceptions.RequestException as e:
+ # Handle exceptions that may occur during the request
+ print(f"Error: {e}")
+ return CoCalcResponse(text="", status=False)
@classmethod
- def _initialize_session(cls, conversation_cookie) -> requests.Session:
+ def _initialize_session(cls, conversation_cookie: str) -> requests.Session:
"""Initialize a session with custom headers for the request."""
session = requests.Session()
headers = {
- 'Accept': '*/*',
- 'Accept-Language': 'en-US,en;q=0.5',
- 'Origin': 'https://cocalc.com',
- 'Referer': 'https://cocalc.com/api/v2/openai/chatgpt',
- 'Cookie': conversation_cookie,
- 'User-Agent': UserAgent().random,
+ "Accept": "*/*",
+ "Accept-Language": "en-US,en;q=0.5",
+ "Origin": "https://cocalc.com",
+ "Referer": "https://cocalc.com/api/v2/openai/chatgpt",
+ "Cookie": conversation_cookie,
+ "User-Agent": UserAgent().random,
}
session.headers.update(headers)
@@ -39,9 +62,6 @@ class Completion:
@staticmethod
def _create_payload(prompt: str, system_prompt: str) -> dict:
- return {'input': prompt, 'system': system_prompt, 'tag': 'next:index'}
+ """Create the payload for the API request."""
- @staticmethod
- def _submit_request(session: requests.Session, payload: dict) -> CoCalcResponse:
- response = session.post('https://cocalc.com/api/v2/openai/chatgpt', json=payload).json()
- return CoCalcResponse(text=response['output'], status=response['success'])
+ return {"input": prompt, "system": system_prompt, "tag": "next:index"}
diff --git a/gpt4free/forefront/__init__.py b/gpt4free/forefront/__init__.py
index aa78cfa7..7a4f4f28 100644
--- a/gpt4free/forefront/__init__.py
+++ b/gpt4free/forefront/__init__.py
@@ -1,14 +1,14 @@
from json import loads
-from re import match
+from re import findall
from time import time, sleep
from typing import Generator, Optional
from uuid import uuid4
from fake_useragent import UserAgent
from requests import post
+from pymailtm import MailTm, Message
from tls_client import Session
-from .mail import Mail
from .typing import ForeFrontResponse
@@ -19,11 +19,8 @@ class Account:
start = time()
- mail_client = Mail(proxies)
- mail_token = None
- mail_address = mail_client.get_mail()
-
- # print(mail_address)
+ mail_client = MailTm().get_account()
+ mail_address = mail_client.address
client = Session(client_identifier='chrome110')
client.proxies = proxies
@@ -33,7 +30,7 @@ class Account:
}
response = client.post(
- 'https://clerk.forefront.ai/v1/client/sign_ups?_clerk_js_version=4.32.6',
+ 'https://clerk.forefront.ai/v1/client/sign_ups?_clerk_js_version=4.38.4',
data={'email_address': mail_address},
)
@@ -45,9 +42,10 @@ class Account:
return 'Failed to create account!'
response = client.post(
- f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/prepare_verification?_clerk_js_version=4.32.6',
+ f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/prepare_verification?_clerk_js_version=4.38.4',
data={
- 'strategy': 'email_code',
+ 'strategy': 'email_link',
+ 'redirect_url': 'https://accounts.forefront.ai/sign-up/verify'
},
)
@@ -59,26 +57,23 @@ class Account:
while True:
sleep(1)
- for _ in mail_client.fetch_inbox():
- if logging:
- print(mail_client.get_message_content(_['id']))
- mail_token = match(r'(\d){5,6}', mail_client.get_message_content(_['id'])).group(0)
+ 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]
- if mail_token:
+ if verification_url:
break
if logging:
- print(mail_token)
+ print(verification_url)
- 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'},
- )
+ response = client.get(verification_url)
- if logging:
- print(response.json())
+ response = client.get('https://clerk.forefront.ai/v1/client?_clerk_js_version=4.38.4')
- token = response.json()['client']['sessions'][0]['last_active_token']['jwt']
+ token = response.json()['response']['sessions'][0]['last_active_token']['jwt']
with open('accounts.txt', 'a') as f:
f.write(f'{mail_address}:{token}\n')
diff --git a/gpt4free/forefront/mail.py b/gpt4free/forefront/mail.py
deleted file mode 100644
index 2c00051c..00000000
--- a/gpt4free/forefront/mail.py
+++ /dev/null
@@ -1,52 +0,0 @@
-from random import choices
-from string import ascii_letters
-
-from requests import Session
-
-
-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"]
diff --git a/gpt4free/you/README.md b/gpt4free/you/README.md
index 11b4723e..e1917c6d 100644
--- a/gpt4free/you/README.md
+++ b/gpt4free/you/README.md
@@ -10,7 +10,7 @@ response = you.Completion.create(
detailed=True,
include_links=True, )
-print(response)
+print(response.dict())
# {
# "response": "...",
@@ -32,7 +32,7 @@ while True:
prompt=prompt,
chat=chat)
- print("Bot:", response["response"])
+ print("Bot:", response.text)
- chat.append({"question": prompt, "answer": response["response"]})
+ chat.append({"question": prompt, "answer": response.text})
```
diff --git a/requirements.txt b/requirements.txt
index 366502b5..62e92d56 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -10,4 +10,5 @@ selenium
fake-useragent
twocaptcha
https://github.com/AI-Yash/st-chat/archive/refs/pull/24/head.zip
-pydantic \ No newline at end of file
+pydantic
+pymailtm