while creating object for ChatCompletionsOptions class, Messages = new ChatMessage {role, "sdsds"}, here ChatMessage object is not acceptingaccepting

arsule, dattatray 0 Reputation points
2024-07-18T13:48:25.7866667+00:00

Response<ChatCompletions> responseWithoutStream = await client1.GetChatCompletionsAsync(

"OpenAIService-demo",

new ChatCompletionsOptions()

{

Messages =

{

  new ChatMessage(ChatRole.System, @"You are an AI assistant that helps people find information based on there queries."),

  new ChatMessage(ChatRole.User, @"what is the capital of India"),      

  new ChatMessage(ChatRole.Assistant, @"Capital of India is New Delhi."),

},

Temperature = (float)0.5,

MaxTokens = 800,

NucleusSamplingFactor = (float)0.95,

FrequencyPenalty = 0,

PresencePenalty = 0,

});

In the above code, I am not getting the reference for ChatMessage class. I have added reference

using Azure;

using Azure.AI.OpenAI;

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,092 questions
{count} votes

1 answer

Sort by: Most helpful
  1. navba-MSFT 27,545 Reputation points Microsoft Employee Moderator
    2024-07-22T05:55:17.7033333+00:00

    @arsule, dattatray Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    I understand that you are encountering an issue with creating a ChatCompletionsOptions object and initializing the Messages property. The problem seems to be with the way you’re trying to create the ChatMessage objects.

    Could you please check and let me know if the below helps ?

    Response<ChatCompletions> responseWithoutStream = await client1.GetChatCompletionsAsync(
        "OpenAIService-demo",
        new ChatCompletionsOptions
        {
            Messages = new List<ChatMessage>
            {
                new ChatMessage(ChatRole.System, "You are an AI assistant that helps people find information based on their queries."),
                new ChatMessage(ChatRole.User, "What is the capital of India?"),
                new ChatMessage(ChatRole.Assistant, "The capital of India is New Delhi.")
            },
            Temperature = 0.5f,
            MaxTokens = 800,
            NucleusSamplingFactor = 0.95f,
            FrequencyPenalty = 0,
            PresencePenalty = 0
        }
    );
    
    
    

    Hope this helps. If you have any follow-up questions, please let me know. I would be happy to help.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.