srcnalt / OpenAI-Unity

An unofficial OpenAI Unity Package that aims to help you use OpenAI API directly in Unity Game engine.
MIT License
694 stars 153 forks source link

JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0. #118

Open baudii opened 6 months ago

baudii commented 6 months ago

Снимок экрана 2024-03-14 205601

I have no idea what this is. Can anyone help? I didn't change anything in the code. Purely empty project, imported openAI package, added my API key etc., opened sample scene "ChatGPT", pressed "Play" and sent a message. And it happens every single time. So I couldn't get a single request through. EDIT: Ok, found out that the problem is with this method:

private async Task<T> DispatchRequest<T>(string path, string method, byte[] payload = null) where T: IResponse
{
    T data;

    using (var request = UnityWebRequest.Put(path, payload))
    {
        request.method = method;
        request.SetHeaders(Configuration, ContentType.ApplicationJson);

        var asyncOperation = request.SendWebRequest();

        while (!asyncOperation.isDone) await Task.Yield();
        data = JsonConvert.DeserializeObject<T>(request.downloadHandler.text, jsonSerializerSettings);
    }

    if (data?.Error != null)
    {
        ApiError error = data.Error;
        Debug.LogError($"Error Message: {error.Message}\nError Type: {error.Type}\n");
    }

    if (data?.Warning != null)
    {
        Debug.LogWarning(data.Warning);
    }

    return data;
}

this variable: request.downloadHandler.text returns a whole html page in a string and not a JSON file

EDIT 2 This is the html page I got: image Everything makes sense now since OpenAI doesn't work in Russia. You need a VPN to gain access. I guess, additional check of the response and dedicated error message wouldn't hurt this project.