srcnalt / OpenAI-Unity

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

NullReferenceException: Object reference not set to an instance of an object #3

Closed jalemanyf closed 1 year ago

jalemanyf commented 1 year ago

I followed all the steps but when I push the button to send the text I always receive this error message:

NullReferenceException: Object reference not set to an instance of an object OpenAI.ChatGPT.SendReply () (at Assets/Samples/OpenAI Unity/0.1.0/ChatGPT/ChatGPT.cs:41)

I have checked all the rederences in the editor ( the ChatGPT publics ) and all are correct.

I'm using Unity 2021.3.0f1 on a Mac.

Any help is welcome. Thanks!

srcnalt commented 1 year ago

Hi @jalemanyf,

The line mentioned in the error message is textArea.text = completionResponse.Choices[0].Text; In this case, either the textArea field is not set in the ChatGPT component, or the Choices array is empty. In the latter case, OpenAI did not send an empty response, which I never faced. So I suppose it's that the UI reference is missing.

jalemanyf commented 1 year ago

Hi, @srcnalt ,

Thanks for your quick response ;)

I also supposed the same thing ( the UI reference is missing ) but, as I told you, I have checked all the references in the editor and all are correct, including the textArea.text.

I have debbuged the line and i attach an image. As you can see the textArea as value ( in green ) but the problem is on the completionResponse. It is null! :(

On the debug I have checked also thar my api_key and organization key are correct on the auth.json and they are correct and readed before the call to the API...

Any suggestion?

Best Regards,

Josep Alemany

Captura de pantalla 2023-01-15 a las 13 07 00

jalemanyf commented 1 year ago

I have come in on the openAI page to read more abaout the API ( my first idea was to make a simple, simple test with an API REST client ) but I have a surprise... it seems the service is disabled at the moment.

For these reason I'm not receiving any response...

I will try it again when it is working, it seems is a backend problem.

Thanks!

Captura de pantalla 2023-01-15 a las 13 39 15

srcnalt commented 1 year ago

Hi @jalemanyf,

I do not have error messaging covered in the requests just yet, all the fields of the response null means it could not cast the JSON correctly, which most probably was the error message. I'll create a task for that so I get that covered, in any case, a response error comes from OpenAI I can give this info to the user.

You can debug the DispatchRequest method to see the actual JSON you receive.

COSMYIN90 commented 1 year ago

Hello, @jalemanyf I think is not a server side issue I have the same problem on Windows when I try to make an API Call from ChatGPT Scene.Please see the attachment.

2023-01-17_11h18_26

srcnalt commented 1 year ago

Hi @COSMYIN90, @jalemanyf,

I just released v0.1.1 #5 which has error handling. This should at least help you see what the problem is.

brunno0204 commented 1 year ago

image

@COSMYIN90 @srcnalt I'm having the same error as COSMYIN90, do you know how to fix that?

srcnalt commented 1 year ago

Hi @brunno0204 @COSMYIN90 I just realized the issue is happening during JSON parsing in the Configuration.cs script. Which means something with the auth.json might be wrong. Could you check your /.openai/auth.json file to if it is a valid JSON?

brunno0204 commented 1 year ago

image image It looks ok for me...

brunno0204 commented 1 year ago

image did this and its working, and i think i'll stick with that as ill be using webgl

srcnalt commented 1 year ago

@brunno0204 It has to be called api_key instead of private_api_key or any other word. You might as well keep the API key in your source code, but this poses danger.

brunno0204 commented 1 year ago

@srcnalt Hi! I was able to compile on WebGL, problem is, it's giving me errors when i try to interact with the API(the libc error on console), i suspect it has to do with threading not supported on webgl, do you know a workaround for this? image

srcnalt commented 1 year ago

Hi @brunno0204, WebGL app cannot read your local files such auth.json This project is not intended for production use, it might pose issues if your API key is compromised.

brunno0204 commented 1 year ago

@srcnalt on my last pic before this one ,i told ya i put the api key on the configurator.cs code, so thats not the problem really. And i really dont Care about the security of the key. I saw that on the openaiapi.cs theres multithread lib included. Do you think that is the culprit or might be something else?

srcnalt commented 1 year ago

Probably since Tasks and async code are still a problem in Unity WebGL builds.

brunno0204 commented 1 year ago

I'll try to replace them with unitask tomorrow and see what happens

srcnalt commented 1 year ago

auth.json file check, json to data object field name mapping, and api_key as a required field brought in #6, closing the issue.