srcnalt / OpenAI-Unity

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

Build for Oculus Quest 3 not giving a response from OpenAI #131

Open Nixer087 opened 3 months ago

Nixer087 commented 3 months ago

Hey,

I encountered an issue that only shows in my build, everything works fine in unity but in the build the messages are not getting through nothing is being displayed as a text so I am asuming that also the AWS just does not work because of this, however my animation is being triggered.

I building for Android for the Quest 2/3 as my game is in augmented reality.

normally a message should appear and the sound clip from AWS should play, which again, works fine inside of unity but not in the build.

does anybody know what the issue could be here? is it a permission issue?

https://github.com/user-attachments/assets/ea25fb94-52c3-41de-ab90-a2303ba66b0e

srcnalt commented 3 months ago

Hi @Nixer087 could you check project settings to see if internet is allowed?

Nixer087 commented 3 months ago

it is set on auto

image (1)
Nixer087 commented 3 months ago

I'm also not seeing it in my xr Plug-in manager

image
srcnalt commented 3 months ago

Can you make internet always and try?

Nixer087 commented 3 months ago

I changed the setting to internet required and built it, and still no luck I'm afraid.

image
srcnalt commented 3 months ago

Can you debug it via logcat? See if there are any error messages?

Nixer087 commented 3 months ago

Iquickly tested it and it sais I do not have an API key  You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.

though it is in the script but not in a separate script, I put it in the ChatGPT script

srcnalt commented 3 months ago

So did it work at the end? You should put it in there like this: var openai = new OpenAIApi("sk-Me8...6yi");

Nixer087 commented 3 months ago

I am unable to test it until the 20th. But I think it will probably do the trick, I also had to change the manifest for it to allow internet and read and write locally .I will let you know as soon as It is fixed.

markkuope commented 3 months ago

I had the same problem with Quest 3 glasses. I,m building an educational game with my students where player can practise different educational skills by talking with avatars in a friendly environment. My students found out that this is a datatype -error.

When we added one line of code to Datatypes.sc OPenAI started responding again. Here is our solution:

public string? refusal { get; set; }

This line must be in the ChatMessage function like this:

public struct ChatMessage { public string Role { get; set; } public string Content { get; set; } public string? refusal { get; set; } }

and the Datatypes -script can be found in

Packages/OpenAI Unity/Runtime

We hope this helps :)

Nixer087 commented 3 months ago

so to conclude, I did put the OpenAIApi Keys in the code in the end as it was still in a Json file outside my build. So adding it to the dit OpenAIApi script the trick! Here is where I put it:

    public Configuration(string apiKey = null, string organization = null)
    {
        if (apiKey == null)
        {
            Auth = new Auth()
            {
                ApiKey = "sk******gn7",
                Organization = "org-m***f"
            };

Thanks for your help!^^