Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/ProjectTemplates/GeneratedContent.targets
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@
Specifies external packages that get referenced in generated template content.
-->
<PropertyGroup>
<TemplatePackageVersion_Aspire>9.3.0</TemplatePackageVersion_Aspire>
<TemplatePackageVersion_Aspire_Preview>9.3.0-preview.1.25265.20</TemplatePackageVersion_Aspire_Preview>
<TemplatePackageVersion_Aspire>9.4.0</TemplatePackageVersion_Aspire>
<TemplatePackageVersion_Aspire_Preview>9.4.0-preview.1.25378.8</TemplatePackageVersion_Aspire_Preview>
<TemplatePackageVersion_AzureAIOpenAI>2.3.0-beta.1</TemplatePackageVersion_AzureAIOpenAI>
<TemplatePackageVersion_AzureAIProjects>1.0.0-beta.9</TemplatePackageVersion_AzureAIProjects>
<TemplatePackageVersion_AzureIdentity>1.14.0</TemplatePackageVersion_AzureIdentity>
<TemplatePackageVersion_AzureSearchDocuments>11.6.0</TemplatePackageVersion_AzureSearchDocuments>
<TemplatePackageVersion_AzureSearchDocuments>11.6.1</TemplatePackageVersion_AzureSearchDocuments>
<TemplatePackageVersion_CommunityToolkitAspire>9.4.1-beta.291</TemplatePackageVersion_CommunityToolkitAspire>
<TemplatePackageVersion_MicrosoftExtensionsHosting>10.0.0-preview.6.25358.103</TemplatePackageVersion_MicrosoftExtensionsHosting>
<TemplatePackageVersion_MicrosoftExtensionsServiceDiscovery>9.3.0</TemplatePackageVersion_MicrosoftExtensionsServiceDiscovery>
<TemplatePackageVersion_MicrosoftSemanticKernel>1.53.0</TemplatePackageVersion_MicrosoftSemanticKernel>
<TemplatePackageVersion_MicrosoftSemanticKernel_Preview>1.53.0-preview</TemplatePackageVersion_MicrosoftSemanticKernel_Preview>
<TemplatePackageVersion_MicrosoftExtensionsServiceDiscovery>9.3.1</TemplatePackageVersion_MicrosoftExtensionsServiceDiscovery>
<TemplatePackageVersion_MicrosoftSemanticKernel>1.61.0</TemplatePackageVersion_MicrosoftSemanticKernel>
<TemplatePackageVersion_MicrosoftSemanticKernel_Preview>1.61.0-preview</TemplatePackageVersion_MicrosoftSemanticKernel_Preview>
<TemplatePackageVersion_ModelContextProtocol>0.3.0-preview.2</TemplatePackageVersion_ModelContextProtocol>
<TemplatePackageVersion_OllamaSharp>5.1.18</TemplatePackageVersion_OllamaSharp>
<TemplatePackageVersion_OpenTelemetry>1.12.0</TemplatePackageVersion_OpenTelemetry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
<PackageReference Include="Aspire.Hosting.AppHost" Version="${TemplatePackageVersion_Aspire}" />
<!--#if (UseQdrant)
<PackageReference Include="Aspire.Hosting.Qdrant" Version="${TemplatePackageVersion_Aspire}" />
#elif (UseAzureAISearch)
<PackageReference Include="Aspire.Hosting.Azure.Search" Version="${TemplatePackageVersion_Aspire}" />
#endif -->
<!--#if (IsOllama)
<!--#if (IsAzureOpenAI) -->
<PackageReference Include="Aspire.Hosting.Azure.CognitiveServices" Version="${TemplatePackageVersion_Aspire}" />
<!--#elif (IsOllama)
<PackageReference Include="CommunityToolkit.Aspire.Hosting.Ollama" Version="${TemplatePackageVersion_CommunityToolkitAspire}" />
#endif -->
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var builder = DistributedApplication.CreateBuilder(args);
#if (IsOllama) // ASPIRE PARAMETERS
#else // IsAzureOpenAI || IsOpenAI || IsGHModels
#elif (IsOpenAI || IsGHModels)

// You will need to set the connection string to your own value
// You can do this using Visual Studio's "Manage User Secrets" UI, or on the command line:
Expand All @@ -13,14 +13,27 @@
// dotnet user-secrets set ConnectionStrings:openai "Endpoint=https://YOUR-DEPLOYMENT-NAME.openai.azure.com;Key=YOUR-API-KEY"
#endif
var openai = builder.AddConnectionString("openai");
#else // IsAzureOpenAI

// See https://learn.microsoft.com/dotnet/aspire/azure/local-provisioning#configuration
// for instructions providing configuration values
var openai = builder.AddAzureOpenAI("openai");

openai.AddDeployment(
name: "gpt-4o-mini",
modelName: "gpt-4o-mini",
modelVersion: "2024-07-18");

openai.AddDeployment(
name: "text-embedding-3-small",
modelName: "text-embedding-3-small",
modelVersion: "1");
#endif
#if (UseAzureAISearch)

// You will need to set the connection string to your own value
// You can do this using Visual Studio's "Manage User Secrets" UI, or on the command line:
// cd this-project-directory
// dotnet user-secrets set ConnectionStrings:azureAISearch "Endpoint=https://YOUR-DEPLOYMENT-NAME.search.windows.net;Key=YOUR-API-KEY"
var azureAISearch = builder.AddConnectionString("azureAISearch");
// See https://learn.microsoft.com/dotnet/aspire/azure/local-provisioning#configuration
// for instructions providing configuration values
var search = builder.AddAzureSearch("search");
#endif
#if (IsOllama) // AI SERVICE PROVIDER CONFIGURATION

Expand All @@ -45,11 +58,17 @@
.WithReference(embeddings)
.WaitFor(chat)
.WaitFor(embeddings);
#else // IsAzureOpenAI || IsOpenAI || IsGHModels
#elif (IsOpenAI || IsGHModels)
webApp.WithReference(openai);
#else // IsAzureOpenAI
webApp
.WithReference(openai)
.WaitFor(openai);
#endif
#if (UseAzureAISearch) // VECTOR DATABASE REFERENCES
webApp.WithReference(azureAISearch);
webApp
.WithReference(search)
.WaitFor(search);
#elif (UseQdrant)
webApp
.WithReference(vectorDB)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="${TemplatePackageVersion_MicrosoftExtensionsAIOpenAI}" />
#endif -->
<!--#if ((IsAzureOpenAI || IsOpenAI || IsGHModels) && IsAspire) -->
<PackageReference Include="Azure.AI.OpenAI" Version="${TemplatePackageVersion_AzureAIOpenAI}" />
<PackageReference Include="Aspire.Azure.AI.OpenAI" Version="${TemplatePackageVersion_Aspire_Preview}" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="${TemplatePackageVersion_MicrosoftExtensionsAIOpenAI}" />
<!--#endif -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
using ChatWithCustomData_CSharp.Web.Services;
using ChatWithCustomData_CSharp.Web.Services.Ingestion;
#if (IsOllama)
#else // IsAzureOpenAI || IsOpenAI || IsGHModels
#elif (IsOpenAI || IsGHModels)
using OpenAI;
#else // IsAzureOpenAI
#endif

var builder = WebApplication.CreateBuilder(args);
Expand Down Expand Up @@ -34,7 +35,7 @@
#endif

#if (UseAzureAISearch)
builder.AddAzureSearchClient("azureAISearch");
builder.AddAzureSearchClient("search");
builder.Services.AddAzureAISearchCollection<IngestedChunk>("data-ChatWithCustomData-CSharp.Web-chunks");
builder.Services.AddAzureAISearchCollection<IngestedDocument>("data-ChatWithCustomData-CSharp.Web-documents");
#elif (UseQdrant)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,75 +81,41 @@ Download, install, and run Docker Desktop from the [official website](https://ww
Note: Ollama and Docker are excellent open source products, but are not maintained by Microsoft.

#### ---#endif
#### ---#if (IsAzureOpenAI)
## Using Azure OpenAI
#### ---#if (IsAzureOpenAI || UseAzureAISearch)
## Using Azure Provisioning

To use Azure OpenAI, you will need an Azure account and an Azure OpenAI Service resource. For detailed instructions, see the [Azure OpenAI Service documentation](https://learn.microsoft.com/azure/ai-services/openai/how-to/create-resource).
The project is set up to automatically provision Azure resources, but local configuration is configured. For detailed instructions, see the [Local Provisioning documentation](https://learn.microsoft.com/dotnet/aspire/azure/local-provisioning#configuration).

### 1. Create an Azure OpenAI Service Resource
[Create an Azure OpenAI Service resource](https://learn.microsoft.com/azure/ai-services/openai/how-to/create-resource?pivots=web-portal).

### 2. Deploy the Models
Deploy the `gpt-4o-mini` and `text-embedding-3-small` models to your Azure OpenAI Service resource. When creating those deployments, give them the same names as the models (`gpt-4o-mini` and `text-embedding-3-small`). See the Azure OpenAI documentation to learn how to [Deploy a model](https://learn.microsoft.com/azure/ai-services/openai/how-to/create-resource?pivots=web-portal#deploy-a-model).

### 3. Configure API Key and Endpoint
Configure your Azure OpenAI API key and endpoint for this project, using .NET User Secrets:
1. In the Azure Portal, navigate to your Azure OpenAI resource.
2. Copy the "Endpoint" URL and "Key 1" from the "Keys and Endpoint" section.
#### ---#if (hostIdentifier == "vs")
3. In Visual Studio, right-click on the ChatWithCustomData-CSharp.AppHost project in the Solution Explorer and select "Manage User Secrets".
4. This will open a secrets.json file where you can store your API key and endpoint without it being tracked in source control. Add the following keys & values to the file:

```json
{
"ConnectionStrings:openai": "Endpoint=https://YOUR-DEPLOYMENT-NAME.openai.azure.com;Key=YOUR-API-KEY"
}
```
#### ---#else
3. From the command line, configure your API key and endpoint for this project using .NET User Secrets by running the following commands:

```sh
cd ChatWithCustomData-CSharp.AppHost
dotnet user-secrets set ConnectionStrings:openai "Endpoint=https://YOUR-DEPLOYMENT-NAME.openai.azure.com;Key=YOUR-API-KEY"
```
#### ---#endif

Make sure to replace `YOUR-API-KEY` and `YOUR-DEPLOYMENT-NAME` with your actual Azure OpenAI key and endpoint. Make sure your endpoint URL is formatted like https://YOUR-DEPLOYMENT-NAME.openai.azure.com/ (do not include any path after .openai.azure.com/).
#### ---#endif
#### ---#if (UseAzureAISearch)

## Configure Azure AI Search

To use Azure AI Search, you will need an Azure account and an Azure AI Search resource. For detailed instructions, see the [Azure AI Search documentation](https://learn.microsoft.com/azure/search/search-create-service-portal).
Configure local provisioning for this project using .NET User Secrets:

### 1. Create an Azure AI Search Resource
Follow the instructions in the [Azure portal](https://portal.azure.com/) to create an Azure AI Search resource. Note that there is a free tier for the service but it is not currently the default setting on the portal.
1. In Visual Studio, right-click on the ChatWithCustomData-CSharp.AppHost project in the Solution Explorer and select "Manage User Secrets".
2. This opens a `secrets.json` file where you can store your API keys without them being tracked in source control. Add the following configuration:

Note that if you previously used the same Azure AI Search resource with different model using this project name, you may need to delete your `data-ChatWithCustomData-CSharp.Web-chunks` and `data-ChatWithCustomData-CSharp.Web-documents` indexes using the [Azure portal](https://portal.azure.com/) first before continuing; otherwise, data ingestion may fail due to a vector dimension mismatch.
```json
{
"Azure": {
"SubscriptionId": "<Your subscription id>",
"AllowResourceGroupCreation": true,
"ResourceGroup": "<Valid resource group name>",
"Location": "<Valid Azure location>"
}
}
```

### 3. Configure API Key and Endpoint
Configure your Azure AI Search API key and endpoint for this project, using .NET User Secrets:
1. In the Azure Portal, navigate to your Azure AI Search resource.
2. Copy the "Endpoint" URL and "Primary admin key" from the "Keys" section.
#### ---#if (hostIdentifier == "vs")
3. In Visual Studio, right-click on the ChatWithCustomData-CSharp.AppHost project in the Solution Explorer and select "Manage User Secrets".
4. This will open a `secrets.json` file where you can store your API key and endpoint without them being tracked in source control. Add the following keys and values to the file:

```json
{
"ConnectionStrings:azureAISearch": "Endpoint=https://YOUR-DEPLOYMENT-NAME.search.windows.net;Key=YOUR-API-KEY"
}
```
#### ---#else
3. From the command line, configure your API key and endpoint for this project using .NET User Secrets by running the following commands:
From the command line, configure local provisioning for this project using .NET User Secrets by running the following commands:

```sh
cd ChatWithCustomData-CSharp.AppHost
dotnet user-secrets set ConnectionStrings:azureAISearch "Endpoint=https://YOUR-DEPLOYMENT-NAME.search.windows.net;Key=YOUR-API-KEY"
```
```sh
cd ChatWithCustomData-CSharp.AppHost
dotnet user-secrets set Azure:SubscriptionId "<Your subscription id>"
dotnet user-secrets set Azure:AllowResourceGroupCreation "true"
dotnet user-secrets set Azure:ResourceGroup "<Valid resource group name>"
dotnet user-secrets set Azure:Location "<Valid Azure location>"
```
#### ---#endif

Make sure to replace `YOUR-DEPLOYMENT-NAME` and `YOUR-API-KEY` with your actual Azure AI Search deployment name and key.
Make sure to replace placeholder values with real configuration values.
#### ---#endif
#### ---#if (UseQdrant)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,21 @@ This incompatibility can be addressed by upgrading to Docker Desktop 4.41.1. See

# Configure the AI Model Provider

## Using Azure OpenAI
## Using Azure Provisioning

To use Azure OpenAI, you will need an Azure account and an Azure OpenAI Service resource. For detailed instructions, see the [Azure OpenAI Service documentation](https://learn.microsoft.com/azure/ai-services/openai/how-to/create-resource).
The project is set up to automatically provision Azure resources, but local configuration is configured. For detailed instructions, see the [Local Provisioning documentation](https://learn.microsoft.com/dotnet/aspire/azure/local-provisioning#configuration).

### 1. Create an Azure OpenAI Service Resource
[Create an Azure OpenAI Service resource](https://learn.microsoft.com/azure/ai-services/openai/how-to/create-resource?pivots=web-portal).
From the command line, configure local provisioning for this project using .NET User Secrets by running the following commands:

### 2. Deploy the Models
Deploy the `gpt-4o-mini` and `text-embedding-3-small` models to your Azure OpenAI Service resource. When creating those deployments, give them the same names as the models (`gpt-4o-mini` and `text-embedding-3-small`). See the Azure OpenAI documentation to learn how to [Deploy a model](https://learn.microsoft.com/azure/ai-services/openai/how-to/create-resource?pivots=web-portal#deploy-a-model).
```sh
cd aichatweb.AppHost
dotnet user-secrets set Azure:SubscriptionId "<Your subscription id>"
dotnet user-secrets set Azure:AllowResourceGroupCreation "true"
dotnet user-secrets set Azure:ResourceGroup "<Valid resource group name>"
dotnet user-secrets set Azure:Location "<Valid Azure location>"
```

### 3. Configure API Key and Endpoint
Configure your Azure OpenAI API key and endpoint for this project, using .NET User Secrets:
1. In the Azure Portal, navigate to your Azure OpenAI resource.
2. Copy the "Endpoint" URL and "Key 1" from the "Keys and Endpoint" section.
3. From the command line, configure your API key and endpoint for this project using .NET User Secrets by running the following commands:

```sh
cd aichatweb.AppHost
dotnet user-secrets set ConnectionStrings:openai "Endpoint=https://YOUR-DEPLOYMENT-NAME.openai.azure.com;Key=YOUR-API-KEY"
```

Make sure to replace `YOUR-API-KEY` and `YOUR-DEPLOYMENT-NAME` with your actual Azure OpenAI key and endpoint. Make sure your endpoint URL is formatted like https://YOUR-DEPLOYMENT-NAME.openai.azure.com/ (do not include any path after .openai.azure.com/).

## Configure Azure AI Search

To use Azure AI Search, you will need an Azure account and an Azure AI Search resource. For detailed instructions, see the [Azure AI Search documentation](https://learn.microsoft.com/azure/search/search-create-service-portal).

### 1. Create an Azure AI Search Resource
Follow the instructions in the [Azure portal](https://portal.azure.com/) to create an Azure AI Search resource. Note that there is a free tier for the service but it is not currently the default setting on the portal.

Note that if you previously used the same Azure AI Search resource with different model using this project name, you may need to delete your `data-aichatweb-chunks` and `data-aichatweb-documents` indexes using the [Azure portal](https://portal.azure.com/) first before continuing; otherwise, data ingestion may fail due to a vector dimension mismatch.

### 3. Configure API Key and Endpoint
Configure your Azure AI Search API key and endpoint for this project, using .NET User Secrets:
1. In the Azure Portal, navigate to your Azure AI Search resource.
2. Copy the "Endpoint" URL and "Primary admin key" from the "Keys" section.
3. From the command line, configure your API key and endpoint for this project using .NET User Secrets by running the following commands:

```sh
cd aichatweb.AppHost
dotnet user-secrets set ConnectionStrings:azureAISearch "Endpoint=https://YOUR-DEPLOYMENT-NAME.search.windows.net;Key=YOUR-API-KEY"
```

Make sure to replace `YOUR-DEPLOYMENT-NAME` and `YOUR-API-KEY` with your actual Azure AI Search deployment name and key.
Make sure to replace placeholder values with real configuration values.

# Running the application

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
var builder = DistributedApplication.CreateBuilder(args);

// You will need to set the connection string to your own value
// You can do this using Visual Studio's "Manage User Secrets" UI, or on the command line:
// cd this-project-directory
// dotnet user-secrets set ConnectionStrings:openai "Endpoint=https://YOUR-DEPLOYMENT-NAME.openai.azure.com;Key=YOUR-API-KEY"
var openai = builder.AddConnectionString("openai");
// See https://learn.microsoft.com/dotnet/aspire/azure/local-provisioning#configuration
// for instructions providing configuration values
var openai = builder.AddAzureOpenAI("openai");

// You will need to set the connection string to your own value
// You can do this using Visual Studio's "Manage User Secrets" UI, or on the command line:
// cd this-project-directory
// dotnet user-secrets set ConnectionStrings:azureAISearch "Endpoint=https://YOUR-DEPLOYMENT-NAME.search.windows.net;Key=YOUR-API-KEY"
var azureAISearch = builder.AddConnectionString("azureAISearch");
openai.AddDeployment(
name: "gpt-4o-mini",
modelName: "gpt-4o-mini",
modelVersion: "2024-07-18");

openai.AddDeployment(
name: "text-embedding-3-small",
modelName: "text-embedding-3-small",
modelVersion: "1");

// See https://learn.microsoft.com/dotnet/aspire/azure/local-provisioning#configuration
// for instructions providing configuration values
var search = builder.AddAzureSearch("search");

var webApp = builder.AddProject<Projects.aichatweb_Web>("aichatweb-app");
webApp.WithReference(openai);
webApp.WithReference(azureAISearch);
webApp
.WithReference(openai)
.WaitFor(openai);
webApp
.WithReference(search)
.WaitFor(search);

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<Sdk Name="Aspire.AppHost.Sdk" Version="9.3.0" />
<Sdk Name="Aspire.AppHost.Sdk" Version="9.4.0" />

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -12,7 +12,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.3.0" />
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.4.0" />
<PackageReference Include="Aspire.Hosting.Azure.Search" Version="9.4.0" />
<PackageReference Include="Aspire.Hosting.Azure.CognitiveServices" Version="9.4.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<FrameworkReference Include="Microsoft.AspNetCore.App" />

<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.9.0" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="9.3.0" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="9.3.1" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.12.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.12.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.12.0" />
Expand Down
Loading
Loading