Skip to content

Commit aaece61

Browse files
committed
code updates
1 parent 571167c commit aaece61

File tree

3 files changed

+41
-62
lines changed

3 files changed

+41
-62
lines changed

articles/ai-services/openai/includes/chatgpt-dotnet.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ This will wait until the model has generated its entire response before printing
8888
```csharp
8989
using Azure;
9090
using Azure.AI.OpenAI;
91+
using OpenAI.Chat;
9192
using static System.Environment;
9293

9394
string endpoint = GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
@@ -98,7 +99,7 @@ AzureOpenAIClient azureClient = new(
9899
new AzureKeyCredential(key));
99100

100101
// This must match the custom deployment name you chose for your model
101-
ChatClient chatClient = azureClient.GetChatClient("trubo");
102+
ChatClient chatClient = azureClient.GetChatClient("gpt-35-turbo");
102103

103104
var chatUpdates = chatClient.CompleteChatStreamingAsync(
104105
[

articles/ai-services/openai/includes/dall-e-dotnet.md

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -70,38 +70,30 @@ dotnet add package Azure.AI.OpenAI --version 1.0.0-beta.6
7070
From the project directory, open the *program.cs* file and replace with the following code:
7171

7272
```csharp
73-
using System;
74-
using System.IO;
75-
using System.Threading.Tasks;
73+
using Azure;
7674
using Azure.AI.OpenAI;
75+
using OpenAI.Images;
76+
using static System.Environment;
7777

78-
namespace Azure.AI.OpenAI.Tests.Samples
79-
{
80-
public partial class GenerateImages
81-
{
82-
// add an async Main method:
83-
public static async Task Main(string[] args)
78+
string endpoint = GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
79+
string key = GetEnvironmentVariable("AZURE_OPENAI_API_KEY");
80+
81+
AzureOpenAIClient azureClient = new(
82+
new Uri(endpoint),
83+
new AzureKeyCredential(key));
84+
85+
// This must match the custom deployment name you chose for your model
86+
ImageClient chatClient = azureClient.GetImageClient("dalle-3");
87+
88+
var imageGeneration = await chatClient.GenerateImageAsync(
89+
"a happy monkey sitting in a tree, in watercolor",
90+
new ImageGenerationOptions()
8491
{
85-
string endpoint = GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
86-
string key = GetEnvironmentVariable("AZURE_OPENAI_API_KEY");
87-
88-
OpenAIClient client = new(new Uri(endpoint), new AzureKeyCredential(key));
89-
90-
Response<ImageGenerations> imageGenerations = await client.GetImageGenerationsAsync(
91-
new ImageGenerationOptions()
92-
{
93-
Prompt = "a happy monkey eating a banana, in watercolor",
94-
Size = ImageSize.Size256x256,
95-
});
96-
97-
// Image Generations responses provide URLs you can use to retrieve requested images
98-
Uri imageUri = imageGenerations.Value.Data[0].Url;
99-
100-
// Print the image URI to console:
101-
Console.WriteLine(imageUri);
92+
Size = GeneratedImageSize.W1024xH1024
10293
}
103-
}
104-
}
94+
);
95+
96+
Console.WriteLine(imageGeneration.Value.ImageUri);
10597
```
10698

10799
Build and run the application from your application directory with these commands:

articles/ai-services/openai/includes/use-your-data-dotnet.md

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ This will wait until the model has generated its entire response before printing
125125
```csharp
126126
using Azure;
127127
using Azure.AI.OpenAI;
128-
using System.Text.Json;
128+
using Azure.AI.OpenAI.Chat;
129+
using OpenAI.Chat;
129130
using static System.Environment;
130131

131132
string azureOpenAIEndpoint = GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
@@ -135,40 +136,25 @@ string searchEndpoint = GetEnvironmentVariable("AZURE_AI_SEARCH_ENDPOINT");
135136
string searchKey = GetEnvironmentVariable("AZURE_AI_SEARCH_API_KEY");
136137
string searchIndex = GetEnvironmentVariable("AZURE_AI_SEARCH_INDEX");
137138

139+
AzureOpenAIClient azureClient = new(
140+
new Uri(azureOpenAIEndpoint),
141+
new AzureKeyCredential(azureOpenAIKey));
142+
ChatClient chatClient = azureClient.GetChatClient(deploymentName);
138143

139-
var client = new OpenAIClient(new Uri(azureOpenAIEndpoint), new AzureKeyCredential(azureOpenAIKey));
140-
141-
var chatCompletionsOptions = new ChatCompletionsOptions()
144+
ChatCompletionOptions options = new();
145+
options.AddDataSource(new AzureSearchChatDataSource()
142146
{
143-
DeploymentName = deploymentName,
144-
Messages =
145-
{
146-
new ChatRequestUserMessage("What are my available health plans?"),
147-
},
148-
AzureExtensionsOptions = new AzureChatExtensionsOptions()
149-
{
150-
Extensions =
151-
{
152-
new AzureCognitiveSearchChatExtensionConfiguration()
153-
{
154-
SearchEndpoint = new Uri(searchEndpoint),
155-
Key = searchKey,
156-
IndexName = searchIndex,
157-
},
158-
}
159-
}
160-
};
161-
await foreach (StreamingChatCompletionsUpdate chatUpdate in client.GetChatCompletionsStreaming(chatCompletionsOptions))
162-
{
163-
if (chatUpdate.Role.HasValue)
164-
{
165-
Console.Write($"{chatUpdate.Role.Value.ToString().ToUpperInvariant()}: ");
166-
}
167-
if (!string.IsNullOrEmpty(chatUpdate.ContentUpdate))
168-
{
169-
Console.Write(chatUpdate.ContentUpdate);
170-
}
171-
}
147+
Endpoint = new Uri(searchEndpoint),
148+
IndexName = searchIndex,
149+
Authentication = DataSourceAuthentication.FromApiKey(searchKey),
150+
});
151+
152+
ChatCompletion completion = chatClient.CompleteChat(
153+
[
154+
new UserChatMessage("What are the best-selling Contoso products this month?"),
155+
], options);
156+
157+
Console.WriteLine(completion.Content[0].Text);
172158
```
173159

174160
> [!div class="nextstepaction"]

0 commit comments

Comments
 (0)