Skip to content

Commit

Permalink
Merge branch 'main' into feature-semantic-memory
Browse files Browse the repository at this point in the history
  • Loading branch information
crickman committed Aug 8, 2023
2 parents 239f11c + 4b408e8 commit 0a9b8d7
Show file tree
Hide file tree
Showing 129 changed files with 525 additions and 653 deletions.
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies:

# Add 'deployment' label to any change within the 'deploy' directory
deployment:
- deploy/**/*
- scripts/deploy/**/*

# Add 'documentation' label to any change of '.md' files
documentation:
Expand Down
60 changes: 30 additions & 30 deletions .github/workflows/copilot-chat-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ name: copilot-chat-package

on:
pull_request:
branches: [ "main" ]
branches: ["main"]
merge_group:
branches: [ "main" ]
branches: ["main"]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand All @@ -20,36 +20,36 @@ permissions:
jobs:
copilot-chat-package:
strategy:
fail-fast: false
matrix:
include:
- { dotnet: '6.0', configuration: Release, os: ubuntu-latest }
fail-fast: false
matrix:
include:
- { dotnet: "6.0", configuration: Release, os: ubuntu-latest }

runs-on: ${{ matrix.os }}
env:
NUGET_CERT_REVOCATION_MODE: offline
steps:
- uses: actions/checkout@v3
with:
clean: true
- name: Pull container dotnet/sdk:${{ matrix.dotnet }}
run: docker pull mcr.microsoft.com/dotnet/sdk:${{ matrix.dotnet }}

- name: Package Copilot Chat WebAPI
run: |
chmod +x $(pwd)/deploy/package-webapi.sh;
docker run --rm -v $(pwd):/app -w /app -e GITHUB_ACTIONS='true' mcr.microsoft.com/dotnet/sdk:${{ matrix.dotnet }} /bin/sh -c "/app/deploy/package-webapi.sh --no-zip";
- name: Set version tag
id: versiontag
run: |
VERSION_TAG="$(date +'%Y%m%d').${{ github.run_number }}.${{ github.run_attempt }}"
echo $VERSION_TAG
echo "versiontag=$VERSION_TAG" >> $GITHUB_OUTPUT
- name: Upload package to artifacts
uses: actions/upload-artifact@v3
with:
name: copilotchat-webapi-${{ steps.versiontag.outputs.versiontag }}
path: ./deploy/publish
- uses: actions/checkout@v3
with:
clean: true

- name: Pull container dotnet/sdk:${{ matrix.dotnet }}
run: docker pull mcr.microsoft.com/dotnet/sdk:${{ matrix.dotnet }}

- name: Package Copilot Chat WebAPI
run: |
chmod +x $(pwd)/scripts/deploy/package-webapi.sh;
docker run --rm -v $(pwd):/app -w /app -e GITHUB_ACTIONS='true' mcr.microsoft.com/dotnet/sdk:${{ matrix.dotnet }} /bin/sh -c "/app/scripts/deploy/package-webapi.sh --no-zip";
- name: Set version tag
id: versiontag
run: |
VERSION_TAG="$(date +'%Y%m%d').${{ github.run_number }}.${{ github.run_attempt }}"
echo $VERSION_TAG
echo "versiontag=$VERSION_TAG" >> $GITHUB_OUTPUT
- name: Upload package to artifacts
uses: actions/upload-artifact@v3
with:
name: copilotchat-webapi-${{ steps.versiontag.outputs.versiontag }}
path: ./scripts/deploy/publish
2 changes: 1 addition & 1 deletion .github/workflows/copilot-deploy-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ jobs:
- name: Deploy SWA
run: |
deploy/deploy-webapp.sh --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} --resource-group ${{vars.CC_DEPLOYMENT_GROUP_NAME}} --deployment-name ${{inputs.DEPLOYMENT_NAME}} --application-id ${{vars.APPLICATION_CLIENT_ID}} --authority ${{secrets.APPLICATION_AUTHORITY}} --no-redirect
scripts/deploy/deploy-webapp.sh --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} --resource-group ${{vars.CC_DEPLOYMENT_GROUP_NAME}} --deployment-name ${{inputs.DEPLOYMENT_NAME}} --application-id ${{vars.APPLICATION_CLIENT_ID}} --authority ${{secrets.APPLICATION_AUTHORITY}} --no-redirect
2 changes: 1 addition & 1 deletion .github/workflows/copilot-deploy-infra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ jobs:
inlineScript: |
AI_SERVICE_KEY=$(az cognitiveservices account keys list --name ${{vars.AZUREOPENAI__NAME}} --resource-group ${{vars.AZUREOPENAI_DEPLOYMENT_GROUP_NAME}} | jq -r '.key1')
echo "::add-mask::$AI_SERVICE_KEY"
deploy/deploy-azure.sh --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} --web-api-key ${{secrets.WEB_API_KEY}} --resource-group ${{vars.CC_DEPLOYMENT_GROUP_NAME}} --deployment-name ${{steps.deployment-id.outputs.deployment_name}} --region ${{vars.CC_DEPLOYMENT_REGION}} --ai-service AzureOpenAI --ai-endpoint ${{secrets.AZURE_OPENAI_ENDPOINT}} --ai-service-key $AI_SERVICE_KEY --app-service-sku ${{vars.WEBAPP_API_SKU}} --no-deploy-package --debug-deployment
scripts/deploy/deploy-azure.sh --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} --web-api-key ${{secrets.WEB_API_KEY}} --resource-group ${{vars.CC_DEPLOYMENT_GROUP_NAME}} --deployment-name ${{steps.deployment-id.outputs.deployment_name}} --region ${{vars.CC_DEPLOYMENT_REGION}} --ai-service AzureOpenAI --ai-endpoint ${{secrets.AZURE_OPENAI_ENDPOINT}} --ai-service-key $AI_SERVICE_KEY --app-service-sku ${{vars.WEBAPP_API_SKU}} --no-deploy-package --debug-deployment
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -480,4 +480,7 @@ webapp/build/
webapp/node_modules/

# Custom plugin files used in webapp for testing
webapp/public/.well-known*
webapp/public/.well-known*

# Auto-generated solution file from Visual Studio
webapi/CopilotChatWebApi.sln
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "0.2.0",
"configurations": [

{
"name": "Debug CopilotChatWebApi",
"type": "coreclr",
"preLaunchTask": "build (CopilotChatWebApi)",
"request": "launch",
"program": "${workspaceFolder}/webapi/bin/Debug/net6.0/CopilotChatWebApi.dll",
"cwd": "${workspaceFolder}/webapi",
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
}
]
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"type": "process",
"args": [
"build",
"${workspaceFolder}/CopilotChatWebApi.csproj",
"${workspaceFolder}/webapi/CopilotChatWebApi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary",
"/property:DebugType=portable"
Expand Down
4 changes: 2 additions & 2 deletions CopilotChat.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33706.43
Expand All @@ -22,4 +22,4 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {971570D3-60EA-4EE4-980C-0BDA3E66E741}
EndGlobalSection
EndGlobal
EndGlobal
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion deploy/main.bicep → scripts/deploy/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ resource appServiceWebConfig 'Microsoft.Web/sites/config@2022-09-01' = {
value: 'Warning'
}
{
name: 'Logging:LogLevel:SemanticKernel.Service'
name: 'Logging:LogLevel:CopilotChat.WebApi'
value: 'Warning'
}
{
Expand Down
2 changes: 1 addition & 1 deletion deploy/main.json → scripts/deploy/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
"value": "Warning"
},
{
"name": "Logging:LogLevel:SemanticKernel.Service",
"name": "Logging:LogLevel:CopilotChat.WebApi",
"value": "Warning"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (!(Test-Path $publishOutputDirectory)) {
}

Write-Host "Build configuration: $BuildConfiguration"
dotnet publish "$PSScriptRoot/../webapi/CopilotChatWebApi.csproj" --configuration $BuildConfiguration --framework $DotNetFramework --runtime $TargetRuntime --self-contained --output "$publishOutputDirectory"
dotnet publish "$PSScriptRoot/../../webapi/CopilotChatWebApi.csproj" --configuration $BuildConfiguration --framework $DotNetFramework --runtime $TargetRuntime --self-contained --output "$publishOutputDirectory"
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ if [[ ! -d "$PUBLISH_ZIP_DIRECTORY" ]]; then
fi

echo "Build configuration: $CONFIGURATION"
dotnet publish "$SCRIPT_ROOT/../webapi/CopilotChatWebApi.csproj" --configuration $CONFIGURATION --framework $DOTNET --runtime $RUNTIME --self-contained --output "$PUBLISH_OUTPUT_DIRECTORY"
dotnet publish "$SCRIPT_ROOT/../../webapi/CopilotChatWebApi.csproj" --configuration $CONFIGURATION --framework $DOTNET --runtime $RUNTIME --self-contained --output "$PUBLISH_OUTPUT_DIRECTORY"
if [ $? -ne 0 ]; then
exit 1
fi
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 5 additions & 3 deletions importdocument/README.md → tools/importdocument/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ Memories can be generated from conversations as well as imported from external s
Importing documents enables Copilot Chat to have up-to-date knowledge of specific contexts, such as enterprise and personal data.

## Configure your environment

1. A registered App in Azure Portal (https://learn.microsoft.com/azure/active-directory/develop/quickstart-register-app)
- Select Mobile and desktop applications as platform type, and the Redirect URI will be `http://localhost`
- Select **`Accounts in any organizational directory (Any Azure AD directory - Multitenant)
and personal Microsoft accounts (e.g. Skype, Xbox)`** as the supported account
and personal Microsoft accounts (e.g. Skype, Xbox)`** as the supported account
type for this sample.
- Note the **`Application (client) ID`** from your app registration.
2. Make sure the service is running. To start the service, see [here](../webapi/README.md).
2. Make sure the service is running. To start the service, see [here](../../webapi/README.md).

## Running the app

1. Ensure the web api is running at `https://localhost:40443/`.
2. Configure the appsettings.json file under this folder root with the following variables and fill
in with your information, where
Expand All @@ -33,7 +35,7 @@ Importing documents enables Copilot Chat to have up-to-date knowledge of specifi
all users will have access to:

`dotnet run --files .\sample-docs\ms10k.txt`

Or **Run** the following command to import a document to the app under a chat isolated document collection where
only the chat session will have access to:

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion webapi/Auth/ApiKeyAuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;

namespace SemanticKernel.Service.Auth;
namespace CopilotChat.WebApi.Auth;

/// <summary>
/// Class implementing API key authentication.
Expand Down
2 changes: 1 addition & 1 deletion webapi/Auth/ApiKeyAuthenticationSchemeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using Microsoft.AspNetCore.Authentication;

namespace SemanticKernel.Service.Auth;
namespace CopilotChat.WebApi.Auth;

/// <summary>
/// Options for API key authentication.
Expand Down
2 changes: 1 addition & 1 deletion webapi/Auth/PassThroughAuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace SemanticKernel.Service.Auth;
namespace CopilotChat.WebApi.Auth;

/// <summary>
/// Class implementing "authentication" that lets all requests pass through.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Diagnostics;
using Microsoft.SemanticKernel.Memory;
using SemanticKernel.Service.CopilotChat.Extensions;
using SemanticKernel.Service.CopilotChat.Models;
using SemanticKernel.Service.CopilotChat.Options;
using SemanticKernel.Service.CopilotChat.Storage;
using SemanticKernel.Service.Options;
using CopilotChat.WebApi.Extensions;
using CopilotChat.WebApi.Options;
using CopilotChat.WebApi.Storage;
using CopilotChat.WebApi.Models.Storage;
using CopilotChat.WebApi.Models.Response;

namespace SemanticKernel.Service.CopilotChat.Controllers;
namespace CopilotChat.WebApi.Controllers;

[ApiController]
public class BotController : ControllerBase
Expand Down Expand Up @@ -142,7 +142,7 @@ public async Task<ActionResult<ChatSession>> UploadAsync(

return this.CreatedAtAction(
nameof(ChatHistoryController.GetChatSessionByIdAsync),
nameof(ChatHistoryController).Replace("Controller", "", StringComparison.OrdinalIgnoreCase),
nameof(ChatHistoryController).Replace("Controller", string.Empty, StringComparison.OrdinalIgnoreCase),
new { chatId },
newChat);
}
Expand Down Expand Up @@ -208,7 +208,7 @@ private async Task GetMemoryRecordsAndAppendToEmbeddingsAsync(
IKernel kernel,
string collectionName,
List<KeyValuePair<string, List<MemoryQueryResult>>> embeddings,
string newCollectionName = "")
string? newCollectionName = null)
{
List<MemoryQueryResult> collectionMemoryRecords;
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
using Microsoft.SemanticKernel.Skills.MsGraph.Connectors.Client;
using Microsoft.SemanticKernel.Skills.OpenAPI.Authentication;
using Microsoft.SemanticKernel.Skills.OpenAPI.Extensions;
using SemanticKernel.Service.CopilotChat.Hubs;
using SemanticKernel.Service.CopilotChat.Models;
using SemanticKernel.Service.CopilotChat.Skills.ChatSkills;
using SemanticKernel.Service.Diagnostics;
using SemanticKernel.Service.Models;
using CopilotChat.WebApi.Hubs;
using CopilotChat.WebApi.Skills.ChatSkills;
using CopilotChat.WebApi.Models.Response;
using CopilotChat.WebApi.Models.Request;
using CopilotChat.WebApi.Services;

namespace SemanticKernel.Service.CopilotChat.Controllers;
namespace CopilotChat.WebApi.Controllers;

/// <summary>
/// Controller responsible for handling chat messages and responses.
Expand Down Expand Up @@ -116,7 +116,7 @@ public async Task<IActionResult> ChatAsync(
return this.BadRequest(string.Concat(aiException.Message, " - Detail: " + aiException.Detail));
}

return this.BadRequest(result.LastErrorDescription);
return this.BadRequest(result.LastException!.Message);
}

AskResult chatSkillAskResult = new()
Expand Down Expand Up @@ -174,17 +174,17 @@ private async Task RegisterPlannerSkillsAsync(CopilotChatPlanner planner, Dictio
this._logger.LogInformation("Registering Klarna plugin");

// Register the Klarna shopping ChatGPT plugin with the planner's kernel. There is no authentication required for this plugin.
await planner.Kernel.ImportChatGptPluginSkillFromUrlAsync("KlarnaShoppingPlugin", new Uri("https://www.klarna.com/.well-known/ai-plugin.json"), new OpenApiSkillExecutionParameters());
await planner.Kernel.ImportAIPluginAsync("KlarnaShoppingPlugin", new Uri("https://www.klarna.com/.well-known/ai-plugin.json"), new OpenApiSkillExecutionParameters());
}

// GitHub
if (openApiSkillsAuthHeaders.TryGetValue("GITHUB", out string? GithubAuthHeader))
{
this._logger.LogInformation("Enabling GitHub plugin.");
BearerAuthenticationProvider authenticationProvider = new(() => Task.FromResult(GithubAuthHeader));
await planner.Kernel.ImportOpenApiSkillFromFileAsync(
await planner.Kernel.ImportAIPluginAsync(
skillName: "GitHubPlugin",
filePath: Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "CopilotChat", "Skills", "OpenApiPlugins/GitHubPlugin/openapi.json"),
filePath: Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Skills", "OpenApiPlugins/GitHubPlugin/openapi.json"),
new OpenApiSkillExecutionParameters
{
AuthCallback = authenticationProvider.AuthenticateRequestAsync,
Expand All @@ -198,9 +198,9 @@ await planner.Kernel.ImportOpenApiSkillFromFileAsync(
var authenticationProvider = new BasicAuthenticationProvider(() => { return Task.FromResult(JiraAuthHeader); });
var hasServerUrlOverride = variables.TryGetValue("jira-server-url", out string? serverUrlOverride);

await planner.Kernel.ImportOpenApiSkillFromFileAsync(
await planner.Kernel.ImportAIPluginAsync(
skillName: "JiraPlugin",
filePath: Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "CopilotChat", "Skills", "OpenApiPlugins/JiraPlugin/openapi.json"),
filePath: Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Skills", "OpenApiPlugins/JiraPlugin/openapi.json"),
new OpenApiSkillExecutionParameters
{
AuthCallback = authenticationProvider.AuthenticateRequestAsync,
Expand Down Expand Up @@ -241,7 +241,7 @@ await planner.Kernel.ImportOpenApiSkillFromFileAsync(
var requiresAuth = !plugin.AuthType.Equals("none", StringComparison.OrdinalIgnoreCase);
BearerAuthenticationProvider authenticationProvider = new(() => Task.FromResult(PluginAuthValue));

await planner.Kernel.ImportChatGptPluginSkillFromUrlAsync(
await planner.Kernel.ImportAIPluginAsync(
$"{plugin.NameForModel}Plugin",
uriBuilder.Uri,
new OpenApiSkillExecutionParameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.SemanticKernel;
using SemanticKernel.Service.CopilotChat.Hubs;
using SemanticKernel.Service.CopilotChat.Models;
using SemanticKernel.Service.CopilotChat.Options;
using SemanticKernel.Service.CopilotChat.Skills;
using SemanticKernel.Service.CopilotChat.Storage;

namespace SemanticKernel.Service.CopilotChat.Controllers;
using CopilotChat.WebApi.Hubs;
using CopilotChat.WebApi.Options;
using CopilotChat.WebApi.Skills;
using CopilotChat.WebApi.Storage;
using CopilotChat.WebApi.Models.Storage;
using CopilotChat.WebApi.Models.Request;
using CopilotChat.WebApi.Models.Response;

namespace CopilotChat.WebApi.Controllers;

/// <summary>
/// Controller for chat history.
Expand Down
Loading

0 comments on commit 0a9b8d7

Please sign in to comment.