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 432 forks source link

problem getting list of models from Models.GetModelsAsync() using Azure OpenAI #140

Open Timbot-42 opened 1 year ago

Timbot-42 commented 1 year ago

Has anyone managed to use Models.GetModelsAsync() with Azure OpenAI? I can successfully use the chat and completions endpoints but I am getting an error trying to get the list of models. I know it seems to work a bit differently in Azure where you select your model with your deployment, but I was hoping to be able to access all models with one deployment :)

using this code

OpenAI_API.OpenAIAPI api = OpenAI_API.OpenAIAPI.ForAzure(_settings.AzureOpenAiResourceName, _settings.AzureOpenAiDeploymentId, _settings.AzureOpenAiApiKey);
                api.ApiVersion = "2023-05-15";
var response = await api.Models.GetModelsAsync();

I am getting this error

Error at models (https://resource-name.openai.azure.com/openai/deployments/deployment-name/models?api-version=2023-05-15) with HTTP status code: NotFound. Content: {"error":{"code":"404","message": "Resource not found"}}

Doesn't seem to work with api-version=2022-12-01 either.

I think its something to do with the endpoint, as according to docs it should be

GET {endpoint}/openai/models?api-version=2022-12-01 https://learn.microsoft.com/en-us/rest/api/cognitiveservices/azureopenaistable/models/list

Thanks for your help and putting this sdk together.