OpenAI-API-dotnet icon indicating copy to clipboard operation
OpenAI-API-dotnet copied to clipboard

Issue pulling models list

Open jaacMusic opened this issue 1 year ago • 2 comments

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

jaacMusic avatar May 01 '24 03:05 jaacMusic

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.

bojake avatar May 14 '24 22:05 bojake

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

jaacMusic avatar May 14 '24 23:05 jaacMusic