Visual Studio pro 2022でChatMessageがエラーになってしまう。

mitttttsu 20 Reputation points
2024-01-12T04:42:08.5733333+00:00
Visual Studio Professional 2022 を用いてAzureOpenAIのチャット機能を利用したいと考えております。

以下コードのように単純な回答をさせたいのですが、

ChatMessageでエラーになってしまします。(CS0246)

何が原因か、解決方法を教えて頂きたいです。

 ※"dotnet add package Azure.AI.OpenAI --prerelease" をパッケージマネージャーコンソールで実施済みです。

using Azure.AI.OpenAI;
using Azure;

ーーーー一部省略ーーーーー

Console.Write("prompt:");
string prompt = Console.ReadLine() ?? "Hello.";

 

var response = client.GetChatCompletions( MODEL_NAME,
    new ChatCompletionsOptions()
    {
        Messages = {
            new ChatMessage(ChatRole.User,prompt),
        },
    });


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

Accepted answer
  1. AshokPeddakotla-MSFT 35,971 Reputation points Moderator
    2024-01-18T03:09:20.7766667+00:00

    Hi mitttttsu
    I'm glad that your issue is resolved and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that the question author cannot accept their own answer, they can only accept answers by others, I'll repost your solution in case you'd like to Accept the answer. Error Message:

    Visual Studio Professional 2022 を用いてAzureOpenAIのチャット機能を利用したいと考えております。
    
    以下コードのように単純な回答をさせたいのですが、
    
    ChatMessageでエラーになってしまします。(CS0246)
    
    何が原因か、解決方法を教えて頂きたいです。
    
     ※"dotnet add package Azure.AI.OpenAI --prerelease" をパッケージマネージャーコンソールで実施済みです。
    
    using Azure.AI.OpenAI;
    using Azure;
    
    ーーーー一部省略ーーーーー
    
    Console.Write("prompt:");
    string prompt = Console.ReadLine() ?? "Hello.";
    
     
    
    var response = client.GetChatCompletions( MODEL_NAME,
        new ChatCompletionsOptions()
        {
            Messages = {
                new ChatMessage(ChatRole.User,prompt),
            },
        });
    

    Solution: I solved it with this code

    Console.Write("prompt:");
    string prompt = Console.ReadLine() ?? "Hello.";
    var response = client.GetChatCompletions(
         new ChatCompletionsOptions()
         {
             Messages = {
                 new ChatRequestUserMessage(prompt),
             },
             DeploymentName = MODEL_NAME,
         });
    

    If you have any other questions, please let me know. Thank you again for your time and patience throughout this issue.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. mitttttsu 20 Reputation points
    2024-01-17T00:01:54.4433333+00:00

    I solved it with this code

    Console.Write("prompt:");
    string prompt = Console.ReadLine() ?? "Hello.";
    var response = client.GetChatCompletions(
         new ChatCompletionsOptions()
         {
             Messages = {
                 new ChatRequestUserMessage(prompt),
             },
             DeploymentName = MODEL_NAME,
         });
    
    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.