OkGoDoIt / OpenAI-API-dotnet

An unofficial C#/.NET SDK for accessing the OpenAI GPT-3 API
https://www.nuget.org/packages/OpenAI/
Other
1.86k stars 433 forks source link

Issue pulling models list #206

Open jaacMusic opened 6 months ago

jaacMusic commented 6 months ago

Hello,

When trying to pull a list of all the models using the following: api.Models.GetModelsAsync().Result My program just get stuck. Does anyone knows how to pull a list of all AI models?

Thanks! Juan

bojake commented 6 months ago

It's likely a deadlock in the .Result call. That can happen if you call the async client from inside a web application.

HttpClient client = new HttpClient();
HttpResponseMessage resp = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
string body = await resp.Content.ReadAsStringAsync();

That may likely fix the problem you are having, if you wanted to edit the source and make a custom build of the library.

jaacMusic commented 6 months ago

Thanks Bojake for the response! I was able to work around this issue using the following and skipping the first 8 values.

            for (int i = 8; i < typeof(OpenAI_API.Models.Model).GetProperties().Length; i++)
            {
                AIModels.Items.Add(typeof(OpenAI_API.Models.Model).GetProperties()[i].Name);
            }

models