Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor webapi directory structure #100

Merged
merged 15 commits into from
Aug 8, 2023
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
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
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'
glahaye marked this conversation as resolved.
Show resolved Hide resolved
name: 'Logging:LogLevel:CopilotChat.WebApi'
value: 'Warning'
}
dehoward marked this conversation as resolved.
Show resolved Hide resolved
{
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
teresaqhoang marked this conversation as resolved.
Show resolved Hide resolved
exit 1
fi
Expand Down
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.
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
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
using Microsoft.Extensions.Options;
using Microsoft.SemanticKernel.Diagnostics;
using Microsoft.SemanticKernel.Memory;
using SemanticKernel.Service.CopilotChat.Options;
using SemanticKernel.Service.CopilotChat.Skills.ChatSkills;
using SemanticKernel.Service.CopilotChat.Storage;
using CopilotChat.WebApi.Options;
using CopilotChat.WebApi.Skills.ChatSkills;
using CopilotChat.WebApi.Storage;

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

/// <summary>
/// Controller for retrieving semantic memory data of chat sessions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
using SemanticKernel.Service.CopilotChat.Hubs;
using SemanticKernel.Service.CopilotChat.Models;
using SemanticKernel.Service.CopilotChat.Storage;
using CopilotChat.WebApi.Hubs;
using CopilotChat.WebApi.Storage;
using CopilotChat.WebApi.Models.Storage;

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

/// <summary>
/// Controller for managing invitations and participants in a chat session.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
using Microsoft.Extensions.Options;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Text;
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;
using SemanticKernel.Service.Services;
using CopilotChat.WebApi.Hubs;
using CopilotChat.WebApi.Options;
using CopilotChat.WebApi.Skills;
using CopilotChat.WebApi.Storage;
using CopilotChat.WebApi.Services;
using UglyToad.PdfPig;
using UglyToad.PdfPig.DocumentLayoutAnalysis.TextExtractor;
using static SemanticKernel.Service.CopilotChat.Models.MemorySource;
using CopilotChat.WebApi.Models.Request;
using CopilotChat.WebApi.Models.Storage;
using CopilotChat.WebApi.Models.Response;

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

/// <summary>
/// Controller for importing documents.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using CopilotChat.WebApi.Models.Response;
using CopilotChat.WebApi.Options;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using SemanticKernel.Service.CopilotChat.Models;
using SemanticKernel.Service.Options;
using static SemanticKernel.Service.CopilotChat.Models.ServiceOptionsResponse;

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

/// <summary>
/// Controller responsible for returning the service options to the client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using SemanticKernel.Service.CopilotChat.Models;
using SemanticKernel.Service.CopilotChat.Options;
using CopilotChat.WebApi.Options;
using CopilotChat.WebApi.Models.Response;

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

[Authorize]
[ApiController]
Expand Down
Loading