hexthedev / OpenAi-Api-Unity

Integration for the OpenAi Api in Unity
MIT License
327 stars 71 forks source link

ERROR: status code: Unsupported Media Type #37

Closed wchoujaa closed 3 years ago

wchoujaa commented 3 years ago

Hi,

First, thank you for this great library!

I followed all the instructions, setup, API key, etc. After loading the Example Runtime scene, I get this error:

image

Any idea what could be the problem ?

hexthedev commented 3 years ago

Hey!

Sorry you’re having trouble. I’m gonna go take a look and see if my Unit Tests still work.

The API gets updated a lot and I don’t always get the memo until something breaks.

hexthedev commented 3 years ago

I took a look my side and I’m actually getting a different error. Status code 429.

This means I’ve reached my limit with my access token. Which makes it a little harder to test.

An UnsupportedMediaType request does suggest that the api has changed. Which means there needs to be an update to the Models.

I can’t look into this soon as I have a few other deadlines to hit, but if you want to look yourself you need to go to OpenAi-Api-Unity/Runtime/Scripts/Api/V1/Models. Here you will find all classes used to serialize the arguments for completion functions. If you cross reference this with: API Reference - OpenAI APIhttps://beta.openai.com/docs/api-reference/introduction for the things you want to do you might be able to do a custom quick fix.

I do plan to do a revision of the library to update it. It has been a few months. I’m planning to do this during my vacation between the 28th June to 9th July.

hexthedev commented 3 years ago

Small update, I secured some more tokens so i'll be updating this library end of the month!

wchoujaa commented 3 years ago

I can’t look into this soon as I have a few other deadlines to hit, but if you want to look yourself you need to go to OpenAi-Api-Unity/Runtime/Scripts/Api/V1/Models. Here you will find all classes used to serialize the arguments for completion functions. If you cross reference this with: API Reference - OpenAI APIhttps://beta.openai.com/docs/api-reference/introduction for the things you want to do you might be able to do a custom quick fix.

Great I'll look into it if I have the time!

wchoujaa commented 3 years ago

Ok, after some debugging, I found out that the problem came from the serialization of the data sent to the server. The float temparature in specific. For some reason, when converted to string, a coma is added which invalidate the JSON format.

image

hexthedev commented 3 years ago

That's why it's not happening on my side. Comma's being used in float parsing/serialization comes from language preferences. Using a comma instead of a point is the French way of doing decimal notation. C# actually pulls language optinos from your computer to make this decision.

I will fix this in a release next week, but in the mean time here is what you can try.

In JsonBuilder.cs, replace

image

with

image

Make sure to add

image

Good catch, this one didn't come up in testing. Hope this helps

wchoujaa commented 3 years ago

Great! Thanks for the quick fix!