OpenAI-Unity icon indicating copy to clipboard operation
OpenAI-Unity copied to clipboard

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

Open baudii opened this issue 1 year ago • 0 comments

Снимок экрана 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.

baudii avatar Mar 14 '24 17:03 baudii