I am trying to use azure open AI service in dotnet core 6.0 application. getting proxy error when I call GetCompletions()

var key = "somekey";
            var httpClient = GetProxyHttpclient(_configuration);
            //OpenAIClient client = new OpenAIClient(new Uri("https://azopenaikk.openai.azure.com/"),new AzureKeyCredential(key));

            string endpoint = "https://azopenaikait.openai.azure.com/";
            var client = new OpenAIClient(new Uri(endpoint), new DefaultAzureCredential());

            string deploymentName = "text-davinci-003";
            string prompt = "What is Azure OpenAI?";
            Console.Write($"Input: {prompt}");

            Response<Completions> completionsResponse = client.GetCompletions(deploymentName, prompt);
            string completion = completionsResponse.Value.Choices[0].Text;
            Console.WriteLine($"Chatbot: {completion}");
1

There are 1 best solutions below

0
On

I have reproduced this issue with few modifications and it worked for me

I have referred ms docs and used the below modified code which gave me result.

Code

using Azure.AI.OpenAI;
using Azure;

var key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

string endpoint = "Your endpoint";
var client = new OpenAIClient(new Uri(endpoint), new AzureKeyCredential(key));

string deploymentName = "Your deployment name";
string prompt = "What is Azure OpenAI?";
Console.WriteLine($"Input: {prompt}");

Response<Completions> completionsResponse = await client.GetCompletionsAsync(deploymentName, prompt);
string completion = completionsResponse.Value.Choices[0].Text;
Console.WriteLine($"Chatbot: {completion}"); 

Output

enter image description here