acheong08 / ChatGPT-to-API

Scalable unofficial ChatGPT API for production.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Different streamed response format compared to official API

bi1101 opened this issue · comments

commented

First of all, thank you so much for your wonderful work. I want to report something that may affect user when switching from Open AI API to this API

Notice in the examples below the "role" attributes are located differently.

  • In the official API, the role is passed in the first chunk along with another "content" chunk. These two chunks are streamed at the same time as you can see from the time stamp.
  • In the Chat GPT API, the "role" attribute is passed in every chunk next to the "content" attribute.

The difference may affect programs when parsing the response. It did affect mine

The official response format for streamed response:

2023-06-10 18: 11: 51 - data: {
    "id": "chatcmpl-7PxLzmRT6HFGu1ploxTA4k4ZWxnFb",
    "object": "chat.completion.chunk",
    "created": 1686420711,
    "model": "gpt-3.5-turbo-0301",
    "choices": [
        {
            "delta": {
                "role": "assistant"
            },
            "index": 0,
            "finish_reason": null
        }
    ]
}

data: {
    "id": "chatcmpl-7PxLzmRT6HFGu1ploxTA4k4ZWxnFb",
    "object": "chat.completion.chunk",
    "created": 1686420711,
    "model": "gpt-3.5-turbo-0301",
    "choices": [
        {
            "delta": {
                "content": "1"
            },
            "index": 0,
            "finish_reason": null
        }
    ]
}
2023-06-10 18: 11: 51 - data: {
    "id": "chatcmpl-7PxLzmRT6HFGu1ploxTA4k4ZWxnFb",
    "object": "chat.completion.chunk",
    "created": 1686420711,
    "model": "gpt-3.5-turbo-0301",
    "choices": [
        {
            "delta": {
                "content": "."
            },
            "index": 0,
            "finish_reason": null
        }
    ]
}
2023-06-10 18: 11: 51 - data: {
    "id": "chatcmpl-7PxLzmRT6HFGu1ploxTA4k4ZWxnFb",
    "object": "chat.completion.chunk",
    "created": 1686420711,
    "model": "gpt-3.5-turbo-0301",
    "choices": [
        {
            "delta": {
                "content": " Error"
            },
            "index": 0,
            "finish_reason": null
        }
    ]
}
...

The Chat GPT API Response format:

2023-06-10 18: 12: 16 - data: {
    "id": "chatcmpl-QXlha2FBbmROaXhpZUFyZUF3ZXNvbWUK",
    "object": "chat.completion.chunk",
    "created": 0,
    "model": "gpt-3.5-turbo-0301",
    "choices": [
        {
            "delta": {
                "content": "1. \"",
                "role": "assistant"
            },
            "index": 0,
            "finish_reason": null
        }
    ]
}
2023-06-10 18: 12: 16 - data: {
    "id": "chatcmpl-QXlha2FBbmROaXhpZUFyZUF3ZXNvbWUK",
    "object": "chat.completion.chunk",
    "created": 0,
    "model": "gpt-3.5-turbo-0301",
    "choices": [
        {
            "delta": {
                "content": "all",
                "role": "assistant"
            },
            "index": 0,
            "finish_reason": null
        }
    ]
}

I had the same problem, my web couldn't handle the GPT response after the update

As stated in the readme, this repo was made for personal use. It happens that this change will break other stuff I'm using this for (they expect content/role to be in every response). If anyone is willing, fork this and add full compatibility

Fixed the other program.

Will look into this now

commented

I figured out the problem, it was the missing space fixed in this commit: 23f48ec

commented

Thankyou very much again for your contribution to this project!