Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwolfmsft committed Jul 18, 2024
1 parent 06b7a7d commit acf6e17
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
10 changes: 4 additions & 6 deletions docs/ai/quickstarts/quickstart-ai-chat-with-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ The `AzureOpenAIChatCompletionService` service facilitates the requests and resp
AzureOpenAIChatCompletionService service = new(deployment, endpoint, key);
```

Once the `AzureOpenAIChatCompletionService` client is created, we read the content of the file `hikes.md` and use it to provide more context to the model by adding a system prompt. This instructs the model how you'd like it to act during the conversation.
Once the `OpenAIChatCompletionService` client is created, the app reads the content of the file `hikes.md` and uses it to provide more context to the model by adding a system prompt. This influences model behavior and the generated completions during the conversation.
:::zone-end

```csharp
Expand All @@ -138,9 +138,7 @@ ChatHistory chatHistory = new($"""
Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}");
```
Then you can add a user message to the model by using the `AddUserMessage` function.
To have the model generate a response based off the system prompt and the user request, use the `GetChatMessageContentAsync` function.
Add a user prompt to the model by using the `AddUserMessage` function.Call the `GetChatMessageContentAsync` function to instruct the model to generate a response based off the system and user prompts.
```csharp
// Start the conversation
Expand All @@ -154,12 +152,12 @@ chatHistory.Add(
Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}");
```
To maintain the chat history or context, make sure you add the response from the model to the `chatHistory`. It's time to make our user request about our data again using the `AddUserMessage` and `GetChatMessageContentAsync` function.
To maintain the chat history or context, add the response from the model to the `chatHistory`.
```csharp
// Continue the conversation with a question.
chatHistory.AddUserMessage(
"I would like to know the ratio of the hikesI've done in Canada compared to other countries.");
"I would like to know the ratio of the hikes I've done in Canada compared to other countries.");
Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}");
chatHistory.Add(await service.GetChatMessageContentAsync(
Expand Down
17 changes: 6 additions & 11 deletions docs/ai/quickstarts/quickstart-openai-generate-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ zone_pivot_groups: openai-library

# Generate images using AI with .NET

<!-- markdownlint-disable MD044 -->
:::zone target="docs" pivot="openai"
<!-- markdownlint-enable MD044 -->

Get started with AI by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `dall-e-3` model to generate postal card images so you can invite your friends for a hike! Follow these steps to get access to OpenAI and learn how to use Semantic Kernel.

[!INCLUDE [download-alert](includes/prerequisites-openai.md)]

:::zone-end

<!-- markdownlint-disable MD044 -->
:::zone target="docs" pivot="azure-openai"
<!-- markdownlint-enable MD044 -->

Get started with AI by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `dall-e-3` model to generate postal card images so you can invite your friends for a hike! Follow these steps to provision Azure OpenAI and learn how to use the .NET Azure OpenAI SDK.

Expand All @@ -44,7 +40,6 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap

## Try the the Hiking Images sample

<!-- markdownlint-disable MD029 MD044 -->
:::zone target="docs" pivot="openai"

1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples)
Expand Down Expand Up @@ -78,15 +73,13 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap
> If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again.

:::zone-end
<!-- markdownlint-enable MD029 MD044 -->

## Explore the code

<!-- markdownlint-disable MD044 -->
:::zone target="docs" pivot="openai"
The application uses the [`Microsoft.SemanticKernel`](https://www.nuget.org/packages/Microsoft.SemanticKernel) package to send and receive requests to the OpenAI service.

The entire application is contained within the **Program.cs** file. The first several lines of code set configuration values and gets the OpenAI Key that was previously set using the `dotnet user-secrets` command.
The **Program.cs** file contains all of the app code. The first several lines of code set configuration values and get the OpenAI Key that was previously set using the `dotnet user-secrets` command.

```csharp
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
Expand All @@ -102,13 +95,13 @@ OpenAITextToImageService textToImageService = new(key, null);
:::zone-end

:::zone target="docs" pivot="azure-openai"
<!-- markdownlint-enable MD044 -->

The application uses the [`Microsoft.SemanticKernel`](https://www.nuget.org/packages/Microsoft.SemanticKernel) package to send and receive requests to the Azure OpenAI service.

The entire application is contained within the _Program.cs_ file. The first several lines of code load secrets and configuration values that were set in the `dotnet user-secrets` for you during the application provisioning.

```csharp
// == Retrieve the local secrets saved during the Azure deployment ==========
// Retrieve the local secrets saved during the Azure deployment
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
string endpoint = config["AZURE_OPENAI_ENDPOINT"];
string deployment = config["AZURE_OPENAI_GPT_NAME"];
Expand All @@ -123,7 +116,9 @@ AzureOpenAITextToImageService textToImageService = new(deployment, endpoint, key

:::zone-end

Once the `textToImageService` service is created, provide more context to the model by adding a system prompt. A good prompt to generate images requires a clear description: what is in the images, specific color to use, style (drawing, painting, realistic or cartoony). The model will use this prompt to generate the image. To have the model generate a response based off the user request, use the `GenerateImageAsync` function, and specify the size and quality.
Provide context and instructions to the model by adding a system prompt. A good prompt to generate images requires a clear description: what is in the image, the specific color to use, style (drawing, painting, realistic or cartoony).

Check failure on line 119 in docs/ai/quickstarts/quickstart-openai-generate-images.md

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces [Expected: 0 or 2; Actual: 1]

Use the `GenerateImageAsync` function to have the model generate a response based off the user request and specify the size and quality.

```csharp
// Generate the image
Expand Down
17 changes: 5 additions & 12 deletions docs/ai/quickstarts/quickstart-openai-summarize-text.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ zone_pivot_groups: openai-library

# Summarize text using AI chat app with .NET

<!-- markdownlint-disable MD044 -->
:::zone target="docs" pivot="openai"
<!-- markdownlint-enable MD044 -->

Get started with AI by creating a simple .NET 8 console chat application to summarize text. The application runs locally and uses the OpenAI `gpt-3.5-turbo` model. Follow these steps to get access to OpenAI and learn how to use Semantic Kernel.

[!INCLUDE [download-alert](includes/prerequisites-openai.md)]

:::zone-end

<!-- markdownlint-disable MD044 -->
:::zone target="docs" pivot="azure-openai"
<!-- markdownlint-enable MD044 -->

Get started with AI by creating a simple .NET 8 console chat application to summarize text. The app runs locally and connects to the OpenAI `gpt-35-turbo` model deployed into Azure OpenAI. Follow these steps to provision the Azure OpenAI service and learn how to use Semantic Kernel.

Expand All @@ -44,7 +40,6 @@ Get started with AI by creating a simple .NET 8 console chat application to summ

## Try the Hiking Benefits Summary sample

<!-- markdownlint-disable MD029 MD044 -->
:::zone target="docs" pivot="openai"

1. From a terminal or command prompt, navigate to the `openai\01-HikeBenefitsSummary` directory.
Expand Down Expand Up @@ -81,13 +76,11 @@ Get started with AI by creating a simple .NET 8 console chat application to summ

## Explore the code

<!-- markdownlint-disable MD044 -->
:::zone target="docs" pivot="openai"
<!-- markdownlint-enable MD044 -->

The app uses the [`Microsoft.SemanticKernel`](https://www.nuget.org/packages/Microsoft.SemanticKernel) package to send and receive requests to the OpenAI service.

The entire application is contained within the **Program.cs** file. The first several lines of code set configuration values and gets the OpenAI Key that was previously set using the `dotnet user-secrets` command.
The **Program.cs** file contains all of the app code. The first several lines of code set configuration values and get the OpenAI Key that was previously set using the `dotnet user-secrets` command.

```csharp
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
Expand All @@ -109,10 +102,10 @@ Kernel kernel = Kernel.CreateBuilder()
:::zone target="docs" pivot="azure-openai"
The application uses the [`Microsoft.SemanticKernel`](https://www.nuget.org/packages/Microsoft.SemanticKernel) package to send and receive requests to the Azure OpenAI service.

The entire application is contained within the **Program.cs** file. The first several lines of code retrieve secrets and configuration values that were set in the `dotnet user-secrets` for you during the application provisioning.
The **Program.cs** file contains all of the app code. The first several lines of code load secrets and configuration values that were set in the `dotnet user-secrets` for you during the application provisioning.

```csharp
// == Retrieve the local secrets saved during the Azure deployment ==========
// Retrieve the local secrets saved during the Azure deployment
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
string endpoint = config["AZURE_OPENAI_ENDPOINT"];
string deployment = config["AZURE_OPENAI_GPT_NAME"];
Expand All @@ -130,7 +123,7 @@ Kernel kernel = Kernel.CreateBuilder()

:::zone-end

Once the `Kernel` is created, read the contents of the file `benefits.md` and create a `prompt` to ask the the model to summarize that text.
Once the `Kernel` is created, the app code reads the `benefits.md` file content and uses it to create a `prompt` for model. The prompt instructs the model to summarize the text.

```csharp
// Create and print out the prompt
Expand All @@ -141,7 +134,7 @@ string prompt = $"""
Console.WriteLine($"user >>> {prompt}");
```

Use the `InvokePromptAsync` function to have the model generate a response based on the `prompt` value.
The `InvokePromptAsync` function sends the `prompt` to the model to generate a response.

```csharp
// Submit the prompt and print out the response
Expand Down

0 comments on commit acf6e17

Please sign in to comment.