Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Azure OpenAI Service .NET SDK のアップデート情報 - .NETの...

Azure OpenAI Service .NET SDK のアップデート情報 - .NETの日 〜.NETコミュニティ合同イベント〜

Jumpei Ishikawa

June 25, 2024
Tweet

More Decks by Jumpei Ishikawa

Other Decks in Programming

Transcript

  1. リリース履歴 7 バージョン リリース⽇ 1.0.0-beta.1 2023/02/06 1.0.0-beta.5 2023/03/22 1.0.0-beta.10 2023/12/06

    1.0.0-beta.15 2024/03/20 1.0.0-beta.17 2024/05/03 2.0.0-beta.1 2024/06/07 2.0.0-beta.2 2024/06/14
  2. リリース履歴 8 バージョン リリース⽇ 1.0.0-beta.1 2023/02/06 1.0.0-beta.5 2023/03/22 1.0.0-beta.10 2023/12/06

    1.0.0-beta.15 2024/03/20 1.0.0-beta.17 2024/05/03 2.0.0-beta.1 2024/06/07 2.0.0-beta.2 2024/06/14 ←破壊的変更
  3. var client = new OpenAIClient( new Uri("<AOAI Endpoint>"), new AzureKeyCredential("AOAI

    Key")); var response = await client.GetChatCompletionsAsync( new ChatCompletionsOptions { DeploymentName = "<Deployment Name>", Messages = { new ChatRequestSystemMessage("System prompt"), new ChatRequestUserMessage("User prompt") } }); Console.WriteLine(response.Value.Choices[0].Message.Content); 1.0.0-betaまで 12
  4. var client = new OpenAIClient( new Uri("<AOAI Endpoint>"), new AzureKeyCredential("AOAI

    Key")); var response = await client.GetChatCompletionsAsync( new ChatCompletionsOptions { DeploymentName = "<Deployment Name>", Messages = { new ChatRequestSystemMessage("System prompt"), new ChatRequestUserMessage("User prompt") } }); Console.WriteLine(response.Value.Choices[0].Message.Content); 1.0.0-betaまで 14 Azure 専⽤ Client の 作成 作成した Azure 専⽤ Client を 使い ChatCompletions の取得
  5. var aoaiClient = new AzureOpenAIClient( new Uri("<AOAI Endpoint>"), new AzureKeyCredential("AOAI

    Key")); var client = aoaiClient.GetChatClient("<Deployment Name>"); var response = await client.CompleteChatAsync( new ChatMessage[] { new SystemChatMessage("System prompt"), new UserChatMessage("User prompt") }); Console.WriteLine(response.Value.Content[0].Text); 2.0.0-betaから 15
  6. var aoaiClient = new AzureOpenAIClient( new Uri("<AOAI Endpoint>"), new AzureKeyCredential("AOAI

    Key")); var client = aoaiClient.GetChatClient("<Deployment Name>"); var response = await client.CompleteChatAsync( new ChatMessage[] { new SystemChatMessage("System prompt"), new UserChatMessage("User prompt") }); Console.WriteLine(response.Value.Content[0].Text); 2.0.0-betaから 18 Azure 専⽤ Client の 作成 本家 OpenAI の ChatClient を 取得 取得した ChatClient を使い ChatCompletions の取得
  7. using var sr = new FileStream(@"./car.jpg", FileMode.Open); var client =

    new OpenAIClient( new Uri("<AOAI Endpoint>"), new AzureKeyCredential("AOAI Key")); var response = await client.GetChatCompletionsAsync( new ChatCompletionsOptions { DeploymentName = "<Deployment Name>", Messages = { new ChatRequestSystemMessage("System"), new ChatRequestUserMessage(new ChatMessageImageContentItem(sr, "image/jpg")), new ChatRequestUserMessage("User") }, }); Console.WriteLine(response.Value.Choices[0].Message.Content); 1.0.0-betaまで 20
  8. using var sr = new FileStream(@"./car.jpg", FileMode.Open); var client =

    new OpenAIClient( new Uri("<AOAI Endpoint>"), new AzureKeyCredential("AOAI Key")); var response = await client.GetChatCompletionsAsync( new ChatCompletionsOptions { DeploymentName = "<Deployment Name>", Messages = { new ChatRequestSystemMessage("System"), new ChatRequestUserMessage(new ChatMessageImageContentItem(sr, "image/jpg")), new ChatRequestUserMessage("User") }, }); Console.WriteLine(response.Value.Choices[0].Message.Content); 1.0.0-betaまで 22 Azure 専⽤ Client の 作成 ChatRequestUserMessageに ChatMessageImageContentItemを 詰めて渡す
  9. using var fs = new FileStream(@"./car.jpg", FileMode.Open); var aoaiClient =

    new AzureOpenAIClient( new Uri("<AOAI Endpoint>"), new AzureKeyCredential("AOAI Key")); var client = aoaiClient.GetChatClient("<Deployment Name>"); var userPrompt = new UserChatMessage("User prompt"); userPrompt.Content.Add( ChatMessageContentPart.CreateImageMessageContentPart(BinaryData.FromStream(fs), "image/jpg")); var response = await client.CompleteChatAsync( new ChatMessage[] { new SystemChatMessage("System prompt"), userPrompt }); Console.WriteLine(response.Value.Content[0].Text); 2.0.0-betaから 23
  10. using var fs = new FileStream(@"./car.jpg", FileMode.Open); var aoaiClient =

    new AzureOpenAIClient( new Uri("<AOAI Endpoint>"), new AzureKeyCredential("AOAI Key")); var client = aoaiClient.GetChatClient("<Deployment Name>"); var userPrompt = new UserChatMessage("User prompt"); userPrompt.Content.Add( ChatMessageContentPart.CreateImageMessageContentPart(BinaryData.FromStream(fs), "image/jpg")); var response = await client.CompleteChatAsync( new ChatMessage[] { new SystemChatMessage("System prompt"), userPrompt }); Console.WriteLine(response.Value.Content[0].Text); 本家 OpenAI の ChatClient を 取得 2.0.0-betaから 27 Azure 専⽤ Client の 作成 作成したUserChatMessageを 使い、ChatCompletions の取得 ChatMessageContentPartを含んだ UserChatMessageの作成
  11. var client = new OpenAIClient( new Uri("<AOAI Endpoint>"), new AzureKeyCredential("<AOAI

    Key>")); var response = await client.GetImageGenerationsAsync( new ImageGenerationOptions { DeploymentName = "<Deployment Name>", Prompt = "<User prompt>", Size = ImageSize.Size1024x1024, ImageCount = 1 }); Console.WriteLine(response.Value.Data[0].Url); 1.0.0-betaまで 29
  12. var client = new OpenAIClient( new Uri("<AOAI Endpoint>"), new AzureKeyCredential("<AOAI

    Key>")); var response = await client.GetImageGenerationsAsync( new ImageGenerationOptions { DeploymentName = "<Deployment Name>", Prompt = "<User prompt>", Size = ImageSize.Size1024x1024, ImageCount = 1 }); Console.WriteLine(response.Value.Data[0].Url); 1.0.0-betaまで 31 Azure 専⽤ Client の 作成 GetImageGenerationsの呼び出し
  13. var aoaiClient = new AzureOpenAIClient( new Uri("<AOAI Endpoint>"), new AzureKeyCredential("<AOAI

    Key>")); var client = aoaiClient.GetImageClient("<Deployment Name>"); var response = await client.GenerateImageAsync( "<User prompt>" new ImageGenerationOptions { Size = GeneratedImageSize.W1024xH1024, ResponseFormat = GeneratedImageFormat.Uri }); Console.WriteLine(response.Value.ImageUri); 2.0.0-betaから 32
  14. var aoaiClient = new AzureOpenAIClient( new Uri("<AOAI Endpoint>"), new AzureKeyCredential("<AOAI

    Key>")); var client = aoaiClient.GetImageClient("<Deployment Name>"); var response = await client.GenerateImageAsync( "<User prompt>" new ImageGenerationOptions { Size = GeneratedImageSize.W1024xH1024, ResponseFormat = GeneratedImageFormat.Uri }); Console.WriteLine(response.Value.ImageUri); 2.0.0-betaから 35 本家 OpenAI の ImageClient を取得 取得した ChatClient を使い ChatCompletions の取得 Azure 専⽤ Client の 作成