mirror of https://github.com/xtekky/gpt4free.git
Merge branch 'main' of https://github.com/xtekky/gpt4free
This commit is contained in:
commit
5c2896ed5e
|
@ -0,0 +1,135 @@
|
|||
# GPT4free - use ChatGPT, for free!!
|
||||
|
||||
##### You may join our discord server for updates and support ; )
|
||||
- [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!!
|
||||
|
||||
## Legal Notice <a name="legal-notice"></a>
|
||||
|
||||
This repository uses third-party APIs and AI models and is *not* associated with or endorsed by the API providers or the original developers of the models. This project is intended **for educational purposes only**.
|
||||
|
||||
Please note the following:
|
||||
|
||||
1. **Disclaimer**: The APIs, services, and trademarks mentioned in this repository belong to their respective owners. This project is *not* claiming any right over them.
|
||||
|
||||
2. **Responsibility**: The author of this repository is *not* responsible for any consequences arising from the use or misuse of this repository or the content provided by the third-party APIs and any damage or losses caused by users' actions.
|
||||
|
||||
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)](./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)](./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) |
|
||||
| `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) | - |
|
||||
|
||||
|
||||
## Todo <a name="todo"></a>
|
||||
|
||||
- [ ] Add a GUI for the repo
|
||||
- [ ] Make a general package named `openai_rev`, instead of different folders
|
||||
- [ ] Live api status to know which are down and which can be used
|
||||
- [ ] Integrate more API's in `./unfinished` as well as other ones in the lists
|
||||
- [ ] Make an API to use as proxy for other projects
|
||||
- [ ] Make a pypi package
|
||||
|
||||
## Current Sites <a name="current-sites"></a>
|
||||
|
||||
| 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 |
|
||||
| [you.com](https://you.com) | GPT-3.5 / Internet / good search|
|
||||
| [sqlchat.ai](https://sqlchat.ai) | GPT-3.5 |
|
||||
| [chat.openai.com/chat](https://chat.openai.com/chat) | GPT-3.5 |
|
||||
| [bard.google.com](https://bard.google.com) | custom / search |
|
||||
| [bing.com/chat](https://bing.com/chat) | GPT-4/3.5 |
|
||||
| [chat.forefront.ai/](https://chat.forefront.ai/) | GPT-4/3.5 |
|
||||
|
||||
## Best sites <a name="best-sites"></a>
|
||||
|
||||
#### gpt-4
|
||||
- [`/forefront`](./forefront/README.md)
|
||||
|
||||
#### gpt-3.5
|
||||
- [`/you`](./you/README.md)
|
||||
|
||||
## Install <a name="install"></a>
|
||||
Download or clone this GitHub repo
|
||||
install requirements with:
|
||||
```sh
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
|
||||
## To start gpt4free GUI <a name="streamlit-gpt4free-gui"></a>
|
||||
Move `streamlit_app.py` from `./gui` to the base folder
|
||||
then run:
|
||||
`streamlit run streamlit_app.py` or `python3 -m streamlit run streamlit_app.py`
|
||||
|
||||
## Docker <a name="docker-instructions"></a>
|
||||
Build
|
||||
```
|
||||
docker build -t gpt4free:latest -f Docker/Dockerfile .
|
||||
```
|
||||
Run
|
||||
```
|
||||
docker run -p 8501:8501 gpt4free:latest
|
||||
```
|
||||
|
||||
## ChatGPT clone
|
||||
> currently implementing new features and trying to scale it, please be patient it may be unstable
|
||||
> https://chat.chatbot.sex/chat
|
||||
> This site was developed by me and includes **gpt-4/3.5**, **internet access** and **gpt-jailbreak's** like DAN
|
||||
> run locally here: https://github.com/xtekky/chatgpt-clone
|
||||
|
||||
## Copyright:
|
||||
This program is licensed under the [GNU GPL v3](https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
Most code, with the exception of `quora/api.py` (by [ading2210](https://github.com/ading2210)), has been written by me, [xtekky](https://github.com/xtekky).
|
||||
|
||||
### Copyright Notice: <a name="copyright"></a>
|
||||
```
|
||||
xtekky/openai-gpt4: multiple reverse engineered language-model api's to decentralise the ai industry.
|
||||
Copyright (C) 2023 xtekky
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
```
|
||||
|
||||
## Star History <a name="star-history"></a>
|
||||
[![Star History Chart](https://api.star-history.com/svg?repos=xtekky/gpt4free&type=Date)](https://star-history.com/#xtekky/gpt4free)
|
172
README.md
172
README.md
|
@ -1,135 +1,59 @@
|
|||
# GPT4free - use ChatGPT, for free!!
|
||||
|
||||
##### You may join our discord server for updates and support ; )
|
||||
- [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!!
|
||||
|
||||
## Legal Notice <a name="legal-notice"></a>
|
||||
|
||||
This repository uses third-party APIs and AI models and is *not* associated with or endorsed by the API providers or the original developers of the models. This project is intended **for educational purposes only**.
|
||||
|
||||
Please note the following:
|
||||
|
||||
1. **Disclaimer**: The APIs, services, and trademarks mentioned in this repository belong to their respective owners. This project is *not* claiming any right over them.
|
||||
|
||||
2. **Responsibility**: The author of this repository is *not* responsible for any consequences arising from the use or misuse of this repository or the content provided by the third-party APIs and any damage or losses caused by users' actions.
|
||||
|
||||
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.
|
||||
We got a takedown request by openAI's legal team...
|
||||
you may refer to the old readme: [OLDREADME.md](./OLDREADME.md)
|
||||
|
||||
|
||||
## 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)](./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)](./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) |
|
||||
| `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) | - |
|
||||
discord server for updates / support:
|
||||
- https://discord.gg/gpt4free
|
||||
|
||||
here is a lil' poem you can read in the meantime, while I am investigating it:
|
||||
|
||||
## Todo <a name="todo"></a>
|
||||
|
||||
- [ ] Add a GUI for the repo
|
||||
- [ ] Make a general package named `openai_rev`, instead of different folders
|
||||
- [ ] Live api status to know which are down and which can be used
|
||||
- [ ] Integrate more API's in `./unfinished` as well as other ones in the lists
|
||||
- [ ] Make an API to use as proxy for other projects
|
||||
- [ ] Make a pypi package
|
||||
|
||||
## Current Sites <a name="current-sites"></a>
|
||||
|
||||
| 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 |
|
||||
| [you.com](https://you.com) | GPT-3.5 / Internet / good search|
|
||||
| [sqlchat.ai](https://sqlchat.ai) | GPT-3.5 |
|
||||
| [chat.openai.com/chat](https://chat.openai.com/chat) | GPT-3.5 |
|
||||
| [bard.google.com](https://bard.google.com) | custom / search |
|
||||
| [bing.com/chat](https://bing.com/chat) | GPT-4/3.5 |
|
||||
| [chat.forefront.ai/](https://chat.forefront.ai/) | GPT-4/3.5 |
|
||||
|
||||
## Best sites <a name="best-sites"></a>
|
||||
|
||||
#### gpt-4
|
||||
- [`/forefront`](./forefront/README.md)
|
||||
|
||||
#### gpt-3.5
|
||||
- [`/you`](./you/README.md)
|
||||
|
||||
## Install <a name="install"></a>
|
||||
Download or clone this GitHub repo
|
||||
install requirements with:
|
||||
```sh
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
There once was a time, in a land full of code,
|
||||
A little boy sat, in his humble abode.
|
||||
He tinkered and toyed with devtools galore,
|
||||
And found himself curious, and eager for more.
|
||||
|
||||
## To start gpt4free GUI <a name="streamlit-gpt4free-gui"></a>
|
||||
Move `streamlit_app.py` from `./gui` to the base folder
|
||||
then run:
|
||||
`streamlit run streamlit_app.py` or `python3 -m streamlit run streamlit_app.py`
|
||||
He copied and pasted, with glee and delight,
|
||||
A personal project, to last him the night.
|
||||
For use academic, and also for fun,
|
||||
This little boy's race he just started to run.
|
||||
|
||||
## Docker <a name="docker-instructions"></a>
|
||||
Build
|
||||
```
|
||||
docker build -t gpt4free:latest -f Docker/Dockerfile .
|
||||
```
|
||||
Run
|
||||
```
|
||||
docker run -p 8501:8501 gpt4free:latest
|
||||
Now quite far removed, in a tower so grand,
|
||||
A company stood, it was ruling the land.
|
||||
Their software was mighty, their power supreme,
|
||||
But they never expected this boy and his dream.
|
||||
|
||||
As he played with their code, they then started to fear,
|
||||
"His project is free! What of money so dear?"
|
||||
They panicked and worried, their faces turned red,
|
||||
As visions of chaos now filled every head.
|
||||
|
||||
The CEO paced, in his office so wide,
|
||||
His minions all scrambled, and trying to hide.
|
||||
"Who is this bad child?" he cried out in alarm,
|
||||
"Our great AI moat, why would he cause harm?"
|
||||
|
||||
The developers gathered, their keyboards ablaze,
|
||||
To analyze closely the boy's evil ways.
|
||||
They studied his project, they cracked every tome,
|
||||
And soon they discovered his small, humble home.
|
||||
|
||||
"We must stop him!" they cried, with a shout and a shiver,
|
||||
"This little boy's Mᴀᴋɪɴɢ OUR COMPANY QUIVER!"
|
||||
So they plotted and schemed to yet halt his advance,
|
||||
To put an end to his dear digital dance.
|
||||
|
||||
They filed then with GitHub a claim most obscene,
|
||||
"His code is not his," said the company team,
|
||||
Because of the law, the Great Copyright Mess,
|
||||
This little boy got his first takedown request.
|
||||
|
||||
Now new information we do not yet know,
|
||||
But for the boy's good, we hope results show.
|
||||
For the cause of the True, the Brave and the Right,
|
||||
Till the long bitter end, will this boy live to fight.
|
||||
```
|
||||
( I did not write it )
|
||||
|
||||
## ChatGPT clone
|
||||
> currently implementing new features and trying to scale it, please be patient it may be unstable
|
||||
> https://chat.chatbot.sex/chat
|
||||
> This site was developed by me and includes **gpt-4/3.5**, **internet access** and **gpt-jailbreak's** like DAN
|
||||
> run locally here: https://github.com/xtekky/chatgpt-clone
|
||||
|
||||
## Copyright:
|
||||
This program is licensed under the [GNU GPL v3](https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
Most code, with the exception of `quora/api.py` (by [ading2210](https://github.com/ading2210)), has been written by me, [xtekky](https://github.com/xtekky).
|
||||
|
||||
### Copyright Notice: <a name="copyright"></a>
|
||||
```
|
||||
xtekky/openai-gpt4: multiple reverse engineered language-model api's to decentralise the ai industry.
|
||||
Copyright (C) 2023 xtekky
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
```
|
||||
|
||||
## Star History <a name="star-history"></a>
|
||||
[![Star History Chart](https://api.star-history.com/svg?repos=xtekky/gpt4free&type=Date)](https://star-history.com/#xtekky/gpt4free)
|
||||
|
|
|
@ -39,11 +39,11 @@ class Account:
|
|||
}
|
||||
)
|
||||
|
||||
try:
|
||||
trace_token = response.json()['response']['id']
|
||||
if logging: print(trace_token)
|
||||
except KeyError:
|
||||
return 'Failed to create account!'
|
||||
try:
|
||||
trace_token = response.json()['response']['id']
|
||||
if logging: print(trace_token)
|
||||
except KeyError:
|
||||
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",
|
||||
|
@ -60,7 +60,7 @@ class Account:
|
|||
while True:
|
||||
sleep(1)
|
||||
for _ in mail.fetch_inbox():
|
||||
print(mail.get_message_content(_["id"]))
|
||||
if logging: print(mail.get_message_content(_["id"]))
|
||||
mail_token = match(r"(\d){5,6}", mail.get_message_content(_["id"])).group(0)
|
||||
|
||||
if mail_token:
|
||||
|
|
|
@ -1,60 +1,62 @@
|
|||
import json
|
||||
import re
|
||||
from fake_useragent import UserAgent
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
class Completion:
|
||||
@staticmethod
|
||||
def create(
|
||||
systemprompt:str,
|
||||
text:str,
|
||||
assistantprompt:str
|
||||
):
|
||||
def create(messages):
|
||||
headers = {
|
||||
"authority": "openai.a2hosted.com",
|
||||
"accept": "text/event-stream",
|
||||
"accept-language": "en-US,en;q=0.9,id;q=0.8,ja;q=0.7",
|
||||
"cache-control": "no-cache",
|
||||
"sec-fetch-dest": "empty",
|
||||
"sec-fetch-mode": "cors",
|
||||
"sec-fetch-site": "cross-site",
|
||||
"user-agent": "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/112.0",
|
||||
}
|
||||
|
||||
data = [
|
||||
{"role": "system", "content": systemprompt},
|
||||
{"role": "user", "content": "hi"},
|
||||
{"role": "assistant", "content": assistantprompt},
|
||||
{"role": "user", "content": text},
|
||||
]
|
||||
url = f'https://openai.a2hosted.com/chat?q={Completion.__get_query_param(data)}'
|
||||
|
||||
try:
|
||||
response = requests.get(url, headers=Completion.__get_headers(), stream=True)
|
||||
except:
|
||||
query_param = Completion.__create_query_param(messages)
|
||||
url = f"https://openai.a2hosted.com/chat?q={query_param}"
|
||||
request = requests.get(url, headers=headers, stream=True)
|
||||
if request.status_code != 200:
|
||||
return Completion.__get_failure_response()
|
||||
|
||||
sentence = ""
|
||||
content = request.content
|
||||
response = Completion.__join_response(content)
|
||||
|
||||
return {"responses": response}
|
||||
|
||||
for message in response.iter_content(chunk_size=1024):
|
||||
message = message.decode('utf-8')
|
||||
msg_match, num_match = re.search(r'"msg":"([^"]+)"', message), re.search(r'\[DONE\] (\d+)', message)
|
||||
if msg_match:
|
||||
# Put the captured group into a sentence
|
||||
sentence += msg_match.group(1)
|
||||
return {
|
||||
'response': sentence
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def __get_headers(cls) -> dict:
|
||||
return {
|
||||
'authority': 'openai.a2hosted.com',
|
||||
'accept': 'text/event-stream',
|
||||
'accept-language': 'en-US,en;q=0.9,id;q=0.8,ja;q=0.7',
|
||||
'cache-control': 'no-cache',
|
||||
'sec-fetch-dest': 'empty',
|
||||
'sec-fetch-mode': 'cors',
|
||||
'sec-fetch-site': 'cross-site',
|
||||
'user-agent': UserAgent().random
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def __get_failure_response(cls) -> dict:
|
||||
return dict(response='Unable to fetch the response, Please try again.', links=[], extra={})
|
||||
|
||||
return dict(
|
||||
response="Unable to fetch the response, Please try again.",
|
||||
links=[],
|
||||
extra={},
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def __get_query_param(cls, conversation) -> str:
|
||||
def __multiple_replace(cls, string, reps) -> str:
|
||||
for original, replacement in reps.items():
|
||||
string = string.replace(original, replacement)
|
||||
return string
|
||||
|
||||
@classmethod
|
||||
def __create_query_param(cls, conversation) -> str:
|
||||
encoded_conversation = json.dumps(conversation)
|
||||
return encoded_conversation.replace(" ", "%20").replace('"', '%22').replace("'", "%27")
|
||||
replacement = {" ": "%20", '"': "%22", "'": "%27"}
|
||||
return Completion.__multiple_replace(encoded_conversation, replacement)
|
||||
|
||||
@classmethod
|
||||
def __convert_escape_codes(cls, text) -> str:
|
||||
replacement = {'\\\\"': '"', '\\"': '"', "\\n": "\n", "\\'": "'"}
|
||||
return Completion.__multiple_replace(text, replacement)
|
||||
|
||||
@classmethod
|
||||
def __join_response(cls, data) -> str:
|
||||
data = data.decode("utf-8")
|
||||
find_ans = re.findall(r'(?<={"msg":)[^}]*', str(data))
|
||||
ans = [Completion.__convert_escape_codes(x[1:-1]) for x in find_ans]
|
||||
response = "".join(ans)
|
||||
return response
|
||||
|
|
|
@ -1,10 +1,18 @@
|
|||
### Example: `openaihosted`) <a name="example-openaihosted"></a>
|
||||
|
||||
### Example: `openaihosted` (use like openai pypi package) <a name="example-openaihosted"></a>
|
||||
|
||||
```python
|
||||
# import library
|
||||
import openaihosted
|
||||
|
||||
res = openaihosted.Completion.create(systemprompt="U are ChatGPT", text="What is 4+4", assistantprompt="U are a helpful assistant.")['response']
|
||||
print(res) ## Responds with the answer
|
||||
messages = [{"role": "system", "content": "You are a helpful assistant."}]
|
||||
while True:
|
||||
question = input("Question: ")
|
||||
if question == "!stop":
|
||||
break
|
||||
|
||||
messages.append({"role": "user", "content": question})
|
||||
request = openaihosted.Completion.create(messages=messages)
|
||||
|
||||
response = request["responses"]
|
||||
messages.append({"role": "assistant", "content": response})
|
||||
print(f"Answer: {response}")
|
||||
```
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
import openaihosted
|
||||
|
||||
messages = [{"role": "system", "content": "You are a helpful assistant."}]
|
||||
while True:
|
||||
question = input("Question: ")
|
||||
if question == "!stop":
|
||||
break
|
||||
|
||||
messages.append({"role": "user", "content": question})
|
||||
request = openaihosted.Completion.create(messages=messages)
|
||||
|
||||
response = request["responses"]
|
||||
messages.append({"role": "assistant", "content": response})
|
||||
print(f"Answer: {response}")
|
|
@ -0,0 +1,75 @@
|
|||
import requests
|
||||
import json
|
||||
|
||||
class Completion:
|
||||
|
||||
def request(prompt: str):
|
||||
'''TODO: some sort of authentication + upload PDF from URL or local file
|
||||
Then you should get the atoken and chat ID
|
||||
'''
|
||||
|
||||
token = "your_token_here"
|
||||
chat_id = "your_chat_id_here"
|
||||
|
||||
url = "https://chat-pr4yueoqha-ue.a.run.app/"
|
||||
|
||||
payload = json.dumps({
|
||||
"v": 2,
|
||||
"chatSession": {
|
||||
"type": "join",
|
||||
"chatId": chat_id
|
||||
},
|
||||
"history": [
|
||||
{
|
||||
"id": "VNsSyJIq_0",
|
||||
"author": "p_if2GPSfyN8hjDoA7unYe",
|
||||
"msg": "<start>",
|
||||
"time": 1682672009270
|
||||
},
|
||||
{
|
||||
"id": "Zk8DRUtx_6",
|
||||
"author": "uplaceholder",
|
||||
"msg": prompt,
|
||||
"time": 1682672181339
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
# TODO: fix headers, use random user-agent, streaming response, etc
|
||||
headers = {
|
||||
'authority': 'chat-pr4yueoqha-ue.a.run.app',
|
||||
'accept': '*/*',
|
||||
'accept-language': 'en-US,en;q=0.9',
|
||||
'atoken': token,
|
||||
'content-type': 'application/json',
|
||||
'origin': 'https://www.chatpdf.com',
|
||||
'referer': 'https://www.chatpdf.com/',
|
||||
'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
|
||||
'sec-ch-ua-mobile': '?0',
|
||||
'sec-ch-ua-platform': '"Windows"',
|
||||
'sec-fetch-dest': 'empty',
|
||||
'sec-fetch-mode': 'cors',
|
||||
'sec-fetch-site': 'cross-site',
|
||||
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36'
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload).text
|
||||
Completion.stream_completed = True
|
||||
return {'response': response}
|
||||
|
||||
@staticmethod
|
||||
def create(prompt: str):
|
||||
Thread(target=Completion.request, args=[prompt]).start()
|
||||
|
||||
while Completion.stream_completed != True or not Completion.message_queue.empty():
|
||||
try:
|
||||
message = Completion.message_queue.get(timeout=0.01)
|
||||
for message in findall(Completion.regex, message):
|
||||
yield loads(Completion.part1 + message + Completion.part2)['delta']
|
||||
|
||||
except Empty:
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def handle_stream_response(response):
|
||||
Completion.message_queue.put(response.decode())
|
|
@ -1,2 +1,2 @@
|
|||
to do:
|
||||
- code refractoring
|
||||
- code refactoring
|
||||
|
|
Loading…
Reference in New Issue