gpt4free icon indicating copy to clipboard operation
gpt4free copied to clipboard

chatforai missing fields make it impossible to run

Open vmjcv opened this issue 2 years ago • 4 comments
trafficstars

Bug description chatforai missing fields make it impossible to run They have new fields that : conversationId and sign and timestamp. If you don't pass the right value, they will return "https://chatforai.store" image

根据这个代码:

        if (e.conversationId !== "temp") {
            const s = Date.now()
              , n = e.messages?.[e.messages.length - 1]?.content || ""
              , i = await generateSignature({
                t: s,
                m: n,
                id: e.conversationId
            });
            r.sign = i,
            r.timestamp = s
        }
        var sha256Exports = sha256.exports;
    async function digestMessage(t) {
        if (typeof crypto < "u" && crypto?.subtle?.digest) {
            const e = new TextEncoder().encode(t)
              , a = await crypto.subtle.digest("SHA-256", e);
            return Array.from(new Uint8Array(a)).map(o=>o.toString(16).padStart(2, "0")).join("")
        } else
            return sha256Exports.sha256(t).toString()
    }
    const generateSignature = async t=>{
        const {t: e, m: a, id: r} = t
          , s = `${e}:${r}:${a}:7YN8z6d6`;
        return await digestMessage(s)
    }

You can get the value of sign.

conversationId is ${t.id}_${Date.now()}

vmjcv avatar Oct 10 '23 21:10 vmjcv

@xtekky if you need code, the code is

        timestamp = int(time.time()*1000)
        cls._conversation_id = "id_"+str(timestamp)

        json_data["conversationId"] = cls._conversation_id
        json_data["timestamp"] = int(time.time()*1000)
        json_data["sign"] = generateSignature({"t":json_data["timestamp"],"m":messages[-1]
        ["content"],"id":json_data["conversationId"]})
        
def digestMessage(t):
    if hasattr(hashlib, "sha256"):
        e = t.encode()
        a = hashlib.sha256(e).digest()
        return "".join(format(x, "02x") for x in a)
    else:
        raise Exception("SHA-256 not supported")

def generateSignature(t):
    e, a, r = t["t"], t["m"], t["id"]
    s = f"{e}:{r}:{a}:7YN8z6d6"
    return digestMessage(s)

i test it , everything is okey

vmjcv avatar Oct 10 '23 21:10 vmjcv

They changed they Algo already 5 days ago. You are free to make a PR.

hlohaus avatar Oct 11 '23 08:10 hlohaus

The website doesn't work anymore too. I disabled the provider in my PR.

hlohaus avatar Oct 13 '23 09:10 hlohaus

Bumping this issue because it has been open for 7 days with no activity. Closing automatically in 7 days unless it becomes active again.

github-actions[bot] avatar Oct 21 '23 00:10 github-actions[bot]