79323448

Date: 2025-01-02 10:41:25
Score: 0.5
Natty:
Report link

my best guess is that Azure.AI.OpenAI --prerelease could be an old version of the package. here is a working version of c# sample for chat completion based on ("Azure.AI.OpenAI" Version="2.1.0")

using System;
using System.ClientModel;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Azure.AI.OpenAI;
using OpenAI.Chat;

class Program
{
    static async Task Main(string[] args)
    {

        var deploymentName = "xxxxx";
        var endpointUrl = "https://xxxxx-openai.openai.azure.com/";
        var key = "xxxx";

        var client = new AzureOpenAIClient(new Uri(endpointUrl), new ApiKeyCredential(key));
        var chatClient = client.GetChatClient(deploymentName);
        var messages = new List<ChatMessage>();
        messages.Add(new SystemChatMessage("You are an AI assistant that helps people find information."));
        messages.Add(new UserChatMessage("hi"));

        var response = await chatClient.CompleteChatAsync(messages,  new ChatCompletionOptions()
                    {
                        Temperature = (float)0.7,
                        FrequencyPenalty = (float)0,
                        PresencePenalty = (float)0,
                    });
        var chatResponse = response.Value.Content.Last().Text;

        Console.WriteLine(chatResponse);

    }
}

it should return below

enter image description here

Not sure which page in azure portal you got the sample c# code. here are a few repos for more example c# codes:

https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/openai/Azure.AI.OpenAI/README.md

https://www.nuget.org/packages/Azure.AI.OpenAI

Reasons:
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: qkfang