acheong08 / ChatGPT

Reverse engineered ChatGPT API
GNU General Public License v2.0
28.01k stars 4.48k forks source link

[Feature Request]: A solution for V1 Standard ChatGPT #1379

Closed AkashiCoin closed 1 year ago

AkashiCoin commented 1 year ago

Is there an existing issue for this?

What would your feature do ?

The API used Playwright to pretend to click and pass the Cloudflare Challenge.

Then we can sent a request to the ChatGPT server by using this API.

This project is a simple way to package the requests that are made visible.

I hope to add my repo to your awesome list.

Proposed workflow

Installation

pip3 install UnlimitedChatGPTWebAPI

then you should run playwright install chromium

For windows, maybe you should use it -> playwright install-deps chromium

Configuration

  1. Make sure your network or agent can access https://chat.openai.com
  2. Please make sure that the VPS RAM is not too small.

Usage

Basic example

import asyncio

from UnlimitedChatGPTWebAPI import ChatSession

async def main():
    async with ChatSession(proxies="socks5://localhost:7890") as session:
        # or use this if you want to use the same session for multiple requests
        # example:
        # session = ChatSession(proxies="socks5://localhost:7890")
        # await session.init_page()
        async with session.fetch(
            method="GET",
            url="/backend-api/models",
            headers={"Authorization": "Bearer xxx"}
        ) as resp:
            print(await resp.json())

if __name__ == "__main__":
    asyncio.run(main())

Streaming example

import asyncio

from UnlimitedChatGPTWebAPI import ChatSession

async def main():
    async with ChatSession(proxies="socks5://localhost:7890") as session:
        # or use this if you want to use the same session for multiple requests
        # example:
        # session = ChatSession(proxies="socks5://localhost:7890")
        # await session.init_page()
        async with session.fetch(
            method="GET",
            url="/backend-api/models",
            headers={"Authorization": "Bearer xxx"}
        ) as resp:
            data = b""
            async for chunk in resp.iter_chunked():
                data += chunk
            print(data.decode())

if __name__ == "__main__":
    asyncio.run(main())

Additional information

https://github.com/AkashiCoin/UnlimitedChatGPTWebAPI

acheong08 commented 1 year ago

Why use chromium when you can access it with just TLS spoofing?

AkashiCoin commented 1 year ago

Why use chromium when you can access it with just TLS spoofing?

emm. chromium is always used in resolve the cloudflare challenge, and as for TLS spoofing, I will try to use it in a later update...

acheong08 commented 1 year ago

It has already been done a lot Reference: https://github.com/linweiyuan/go-chatgpt-api https://github.com/acheong08/ChatGPT-Proxy-V4

... and some others

AkashiCoin commented 1 year ago

It has already been done a lot Reference: https://github.com/linweiyuan/go-chatgpt-api https://github.com/acheong08/ChatGPT-Proxy-V4

... and some others

Awesome, I will try to learn

AkashiCoin commented 1 year ago

I found that cloudflare challenge has not been solved in these repo. Is it because this challenge does not appear frequently? As I use it, it always comes up. with PUID, it's running. But what if PUID doesn't work, like before?

acheong08 commented 1 year ago

This is an IP thing. It seems that some but not all residential IP addresses are able to get around cloudflare with just TLS spoofing while clean proxies tend to trigger a challenge

acheong08 commented 1 year ago

I'm using an IP from an academic institution as a proxy, which is probably why cloudflare lets it pass

AkashiCoin commented 1 year ago

Awesome, I think cloudlfare may be more strict in the future, and this can be used as a backup. I've used it to create a proxy site that might be easy to use. (May not be trusted due to security issues) https://chat.loli.vet

acheong08 commented 1 year ago

Nice. I'll check it out once it is required