acheong08 / ChatGPTProxy

Simple Cloudflare bypass for ChatGPT
The Unlicense
1.32k stars 326 forks source link

401 Unauthorized/422 Unprocessable Entity #66

Closed Louvivien closed 1 year ago

Louvivien commented 1 year ago

Hi,

Thanks for this code

I have deployed it on a server and then I have added this: export ACCESS_TOKEN="XXX" export PUID="XXXX"

I do this request: curl -X POST https://chatgpt-proxy-v4-2yszjm3tda-od.a.run.app/api/conversation -H "Content-Type: application/json" -d '{"query": "Hello, how are you?", "model": "gpt-3.5-turbo", "logprobs": 10}'

I get this response:

401 Unauthorized
{
    "detail": {
        "message": "Unauthorized - Access token is missing"
    }
}

if I add the access_token:

curl --location 'https://chatgpt-proxy-v4-2yszjm3tda-od.a.run.app/api/conversation' \
--header 'Content-Type: application/json' \
--header 'Authorization: access_token \
--data '{"query": "Hello, how are you?", "model": "gpt-3.5-turbo", "logprobs": 10}'

I get this:

422 Unprocessable Entity
{
    "detail": [
        {
            "loc": [
                "body",
                "action"
            ],
            "msg": "field required",
            "type": "value_error.missing"
        }
    ]
}

What Am I doing wrong?

acheong08 commented 1 year ago

Looks like you're trying to use this like the official API.

You're looking for https://github.com/acheong08/ChatGPT-to-API I think

Louvivien commented 1 year ago

I am trying to connect without getting cloudflared, how can I do that?

acheong08 commented 1 year ago

I am trying to connect without getting cloudflared, how can I do that?

This repo is exactly that. The problem you are getting is that your request data is wrong

acheong08 commented 1 year ago

I'm not sure where you're getting

{"query": "Hello, how are you?", "model": "gpt-3.5-turbo", "logprobs": 10}

from

acheong08 commented 1 year ago

This is what a ChatGPT request tends to look like

{
    "action": "next",
    "messages": [
        {
            "id": "cd465ab7-3ee4-40e7-8e48-ade9926ad68e",
            "role": "user",
            "content": {
                "content_type": "text",
                "parts": [
                    "What is 4x^2-4x+2=0"
                ]
            }
        }
    ],
    "parent_message_id": "572aca1b-59e5-4262-85b6-b258fa5a38b8",
    "model": "gpt-4-plugins",
    "plugin_ids":["plugin-d1d6eb04-3375-40aa-940a-c2fc57ce0f51"]
}
acheong08 commented 1 year ago

This repo is mainly used for https://github.com/acheong08/ChatGPT/

Louvivien commented 1 year ago

Works. Thanks! Why do i get so many messages in response? Can I limit that number from the request? It means I can use it with the model with plugins and set the plugins I want in the request?

acheong08 commented 1 year ago

The messages is due to streaming. If you're looking to parse and use this API in a reasonable manner, check out https://github.com/acheong08/ChatGPT for Python and https://github.com/transitive-bullshit/chatgpt-api for NodeJS

acheong08 commented 1 year ago

This repo also gets around cloudflare and enables you to use ChatGPT like the OpenAI's official API: https://github.com/acheong08/ChatGPT-to-API which allows you to control whether it streams or not

acheong08 commented 1 year ago

Example of ChatGPT-to-API: (Hosted instance. No need for auth.)

curl https://free.churchless.tech/v1/chat/completions -d '{"messages":[{"role":"user", "content":"Explain the concept of ChatGPT"}], "model":"gpt-3.5-turbo","stream":false}'
Louvivien commented 1 year ago

I see yes to display the text words by words they stream the response so to get the response you need to wait for the last message to be received and get it.

acheong08 commented 1 year ago

I don't have access to plugins in general yet. Only revChatGPT supports it