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

Azure OpenAI issue

Open davidd00 opened this issue 2 years ago • 8 comments

I'm trying to use this library with an Azure OpenIA resource. I'm using the example in the readme: OpenAIAPI api = OpenAIAPI.ForAzure("YourResourceName", "deploymentId", "api-key");, but Url created seems to be wrong.

OpenAIAPI api object initialization: OpenAIAPI api = OpenAIAPI.ForAzure("opeanai-resource", "deployedEngine", "apikey"); CreatedUrl: https://opeanai-resource.openai.azure.com/openai/deployments/deployedEngine)/{1}?api-version={0}

It adds a clos parenthesis to the resource engine, so I get this error: The API deployment for the resource does not exist.

I guess the ApiVersion {0} and the completion {1} are added when doing the requests, but are not showed in the Url

davidd00 avatar Mar 07 '23 19:03 davidd00

I have fixed the extra parenthesis in the generated URL, sorry about that. Beyond that, I don't have any insight into what those values should be or how to test it. Microsoft denied my application to access the Azure OpenAI endpoint, so I'm just guessing based on documentation. Can you give me an example of a correct HTTP request that works for you, including all headers except authorization? That way to can try to make sure this SDK works similarly.

OkGoDoIt avatar Mar 09 '23 00:03 OkGoDoIt

I have access to Azure OpenAI. I will look into this today and provide feedback. I hope I can be of help.

realchrisparker avatar Mar 20 '23 16:03 realchrisparker

Sorry, I missed the answer to the issue. I'll try to test it today too. Thanks!

davidd00 avatar Mar 20 '23 16:03 davidd00

Just wanted to add to this thread that - it's all working fine for me, with an Azure OpenAI deployment. The parenthesis fix was all that was needed.

AndrewGretton avatar Mar 21 '23 10:03 AndrewGretton

Just wanted to add to this thread that - it's all working fine for me, with an Azure OpenAI deployment. The parenthesis fix was all that was needed.

I confirm that the parenthesis issue is fixed and it's working fine now 👍 Thanks!

davidd00 avatar Mar 21 '23 11:03 davidd00

I have fixed the extra parenthesis in the generated URL, sorry about that. Beyond that, I don't have any insight into what those values should be or how to test it. Microsoft denied my application to access the Azure OpenAI endpoint, so I'm just guessing based on documentation. Can you give me an example of a correct HTTP request that works for you, including all headers except authorization? That way to can try to make sure this SDK works similarly.

image

This's the console of Azure OpenAI. The blue part is 'YourResourceName' and the red part is 'deploymentId'.

Response: image image

Hope this helps you.

And don't worry. Your SDK is perfectly usable. Thanks.

jiangweifang avatar Mar 22 '23 10:03 jiangweifang

This works for me.

HttpRequestMessage request = new() { Method = HttpMethod.Post, RequestUri = new Uri( $"https://{resourceName}.openai.azure.com/openai/deployments/{deploymentName}/completions?api-version=2022-12-01" ), Content = new StringContent( completionMessage.ToString(), Encoding.UTF8, "application/json" ), }; request.Headers.Clear(); request.Headers.Accept.Add( new MediaTypeWithQualityHeaderValue( "application/json" ) ); request.Headers.Add( "api-key", apiKey );

            var response = await _httpClient.SendAsync( request );

{ "prompt": "", "temperature": 1, "top_p": 0.5, "frequency_penalty": 0, "presence_penalty": 0, "max_tokens": 100, "best_of": 1, "stop": null }

realchrisparker avatar Mar 22 '23 14:03 realchrisparker

I have tried with gpt-35-turbo (version 0301) and 2023-03-15-preview and it's ok.

nicogis avatar May 08 '23 09:05 nicogis