From a8b1d40de2c058875650580bfc2989dfe6bf5f63 Mon Sep 17 00:00:00 2001 From: Harmanpreet Kaur Date: Wed, 1 Jan 2025 12:09:30 +0530 Subject: [PATCH 01/43] edits 1 --- .github/workflows/CI.yml | 165 ++++++++++++++++++++++++++++++ .github/workflows/tests.yml | 122 ++++++++++++++++++++++ Deployment/main.bicep | 1 + Deployment/resourcedeployment.ps1 | 20 +++- 4 files changed, 306 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/CI.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 00000000..513e3386 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,165 @@ +name: Deploy Resources + +on: + push: + branches: + - main # Adjust this to the branch you want to trigger the deployment on + schedule: + - cron: '0 6,18 * * *' # Runs at 6:00 AM and 6:00 PM GMT + + +jobs: + deploy: + runs-on: windows-latest # Use a Windows runner for PowerShell scripts + + steps: + - name: Checkout Code + uses: actions/checkout@v3 # Checks out your repository + # Install Azure CLI + - name: Install Azure CLI + run: curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash + + # Install kubectl + - name: Install kubectl + run: | + sudo apt-get update + sudo apt-get install -y kubectl + + # Install Helm + - name: Install Helm + run: | + curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash + + # Set up Docker + - name: Set up Docker + uses: docker/setup-buildx-action@v2 + + - name: Setup PowerShell + shell: pwsh + run: | + $PSVersionTable.PSVersion + + - name: Run Deployment Script with Input + shell: pwsh + run: | + cd Deployment + $input = @" + ${{ secrets.AZURE_SUBSCRIPTION_ID }} + CanadaCentral + WestUS3 + ${{ secrets.EMAIL }} + yes + "@ + $input | pwsh ./resourcedeployment.ps1 + echo "Resource Group Name is ${{ env.rg_name }}" + echo "Kubernetes resource group are ${{ env.krg_name }}" + env: + AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} + AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} + AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }} + - name: Cleanup Resource Group + if: always() # Ensures this step runs even if the deployment fails + shell: pwsh + run: | + az login --service-principal --username ${{ secrets.AZURE_CLIENT_ID }} --password ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }} + az group delete --name ${{ env.rg_name }} --yes --no-wait + az group delete --name ${{ env.krg_name }} --yes --no-wait + env: + AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} + AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} + AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }} + + - name: Wait for Resource Deletion to Complete + shell: pwsh + run: | + $retries = 0 + $maxRetries = 3 + $sleepIntervals = @(700, 200, 200) + + while ($retries -lt $maxRetries) { + $rgStatus = az group exists --name ${{ env.rg_name }} + $krgStatus = az group exists --name ${{ env.krg_name }} + + + # if (-not $rgStatus -and -not $krgStatus) { + # Write-Host "Both resource groups deleted successfully." + # break + # } + if ($rgStatus -eq "false" -and $krgStatus -eq "false") { + Write-Host "Both resource groups deleted successfully." + break + } + + $retries++ + if ($retries -eq $maxRetries) { + Write-Host "Resource groups deletion not confirmed after $maxRetries attempts. Exiting." + exit 1 + } + + Write-Host "Resource groups still exist. Retrying in $($sleepIntervals[$retries - 1]) seconds..." + Start-Sleep -Seconds $sleepIntervals[$retries - 1] + } + + - name: Purging the Resources + if: success() + shell: pwsh + run: | + # Set variables using GitHub Actions environment values + $solutionPrefix = "${{ env.SOLUTION_PREFIX }}" + $subscriptionId = "${{ secrets.AZURE_SUBSCRIPTION_ID }}" + $resourceGroupName = "${{ env.rg_name }}" + + $openai_name = "openaiservice-$solutionPrefix" + $cognitiveservice_name = "cognitiveservice-$solutionPrefix" + + # Debug: Print resource names + Write-Host "Purging OpenAI resource: $openai_name" + Write-Host "Purging CognitiveService Account: $cognitiveservice_name" + + # Construct resource IDs + $openaiResourceId = "/subscriptions/$subscriptionId/providers/Microsoft.CognitiveServices/locations/westus3/resourceGroups/$resourceGroupName/deletedAccounts/$openai_name" + $cognitiveResourceId = "/subscriptions/$subscriptionId/providers/Microsoft.CognitiveServices/locations/eastus/resourceGroups/$resourceGroupName/deletedAccounts/$cognitiveservice_name" + + # Debug: Print constructed resource IDs + Write-Host "Command to purge OpenAI resource: az resource delete --ids `"$openaiResourceId`" --verbose" + Write-Host "Command to purge CognitiveService Account: az resource delete --ids `"$cognitiveResourceId`" --verbose" + # Purge OpenAI Resource + az resource delete --ids $openaiResourceId --verbose + if (-not $?) { + Write-Host "Failed to purge OpenAI resource: $openaiResourceId" + } + + # Purge CognitiveService Account + + + az resource delete --ids $cognitiveResourceId --verbose + if (-not $?) { + Write-Host "Failed to purge CognitiveService Account." + } + + + # - name: Send Notification on Failure + # if: failure() + # shell: pwsh + # run: | + # # Define the RUN_URL variable + # $RUN_URL = "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" + + # # Construct the email body using a Here-String + # $EMAIL_BODY = @" + # { + # "body": "

Dear Team,

The Document Knowledge Mining Automation process encountered an issue.

Build URL: $RUN_URL

Please investigate promptly.

Best regards,
Your Automation Team

" + # } + # "@ + + # # Send the notification with error handling + # try { + # curl -X POST "${{ secrets.LOGIC_APP_URL }}" ` + # -H "Content-Type: application/json" ` + # -d "$EMAIL_BODY" + # } catch { + # Write-Output "Failed to send notification." + # } + \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..9b51901d --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,122 @@ +name: Unit Tests - DKM + +on: + push: + branches: main + + pull_request: + branches: main + types: + - opened + - ready_for_review + - reopened + - synchronize + +jobs: + backend_api_tests: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + - name: Install Code Coverage Tools + run: | + dotnet tool install --global coverlet.console || echo "Warning: Could not install coverlet." + env: + DOTNET_ROOT: /usr/share/dotnet + + + - name: Restore and run tests for Backend API with coverage + working-directory: ./App/backend-api + run: | + if [ -f "Microsoft.GS.DPS.sln" ]; then + dotnet restore Microsoft.GS.DPS.sln || echo "Warning: Some dependencies are missing. Proceeding." + if dotnet test Microsoft.GS.DPS.sln --list-tests > /dev/null 2>&1; then + dotnet test Microsoft.GS.DPS.Host/BackendApi.Tests/BackendApi.Tests.csproj --collect:"XPlat Code Coverage" --settings coverlet.runsettings --logger trx --results-directory TestResults || echo "Warning: Some tests may have failed." + else + echo "No test cases found in Backend API. Skipping tests." + fi + else + echo "No solution file found in Backend API. Skipping tests." + fi + - name: List test result files + run: ls -R ./App/backend-api/TestResults || echo "TestResults directory not found." + - name: Verify Coverage Report + run: | + if [ -d "./App/backend-api/TestResults/CoverageReport" ]; then + echo "Coverage report exists." + else + echo "Coverage report not generated." + fi + + + + - name: Publish coverage results for Backend API + uses: actions/upload-artifact@v3 + with: + name: backend-api-coverage + path: ./App/backend-api/TestResults/CoverageReport + + kernel_memory_tests: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + + - name: Restore and run tests for Kernel Memory with coverage + working-directory: ./App/kernel-memory + run: | + if [ -f "KernelMemory.sln" ]; then + dotnet restore KernelMemory.sln || echo "Warning: Some dependencies are missing. Proceeding." + if dotnet test KernelMemory.sln --list-tests > /dev/null 2>&1; then + dotnet test KernelMemory.sln --collect:"XPlat Code Coverage" --logger trx --results-directory TestResults || echo "Warning: Some tests may have failed." + else + echo "No test cases found in Kernel Memory. Skipping tests." + fi + else + echo "No solution file found in Kernel Memory. Skipping tests." + fi + + - name: Publish coverage results for Kernel Memory + uses: actions/upload-artifact@v3 + with: + name: kernel-memory-coverage + path: ./App/kernel-memory/TestResults/CoverageReport + + frontend_tests: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: 16 + + - name: Install dependencies + working-directory: ./App/frontend-app + run: | + npm install --legacy-peer-deps || echo "Warning: Dependency installation failed. Proceeding." + + - name: Run tests for Frontend App with coverage + working-directory: ./App/frontend-app + run: | + if find src -type f \( -name "*.test.tsx" -o -name "*.spec.tsx" -o -name "*.test.ts" -o -name "*.spec.ts" \) | grep -q .; then + echo "Test files found. Proceeding with tests." + npx jest --coverage --coverageDirectory=coverage --detectOpenHandles + else + echo "No test files found in Frontend App. Skipping tests." + fi diff --git a/Deployment/main.bicep b/Deployment/main.bicep index afbe4912..29fa5f4a 100644 --- a/Deployment/main.bicep +++ b/Deployment/main.bicep @@ -158,6 +158,7 @@ module gs_appconfig 'bicep/azureappconfigservice.bicep' = { // return all resource names as a output output gs_resourcegroup_name string = 'rg-${resourceprefix_name}${resourceprefix}' +output gs_solution_prefix string = '${resourceprefix_name}${resourceprefix}' output gs_storageaccount_name string = gs_storageaccount.outputs.storageAccountName output gs_azsearch_name string = gs_azsearch.outputs.searchServiceName diff --git a/Deployment/resourcedeployment.ps1 b/Deployment/resourcedeployment.ps1 index 35a5342a..174010f3 100644 --- a/Deployment/resourcedeployment.ps1 +++ b/Deployment/resourcedeployment.ps1 @@ -141,8 +141,19 @@ $modelLocation = $params.modelLocation $email = $params.email function LoginAzure([string]$subscriptionID) { - Write-Host "Log in to Azure.....`r`n" -ForegroundColor Yellow - az login + Write-Host "Log in to Azure.....`r`n" -ForegroundColor Yellow + if ($env:CI -eq "true"){ + + az login --service-principal ` + --username $env:AZURE_CLIENT_ID ` + --password $env:AZURE_CLIENT_SECRET ` + --tenant $env:AZURE_TENANT_ID + write-host "CI deployment mode" + } + else{ + az login + write-host "manual deployment mode" + } az account set --subscription $subscriptionID Write-Host "Switched subscription to '$subscriptionID' `r`n" -ForegroundColor Yellow } @@ -192,6 +203,8 @@ function DeployAzureResources([string]$location, [string]$modelLocation) { function DisplayResult([pscustomobject]$jsonString) { $resourcegroupName = $jsonString.properties.outputs.gs_resourcegroup_name.value + $solutionPrefix = $jsonString.properties.outputs.gs_solution_prefix.value + $storageAccountName = $jsonString.properties.outputs.gs_storageaccount_name.value $azsearchServiceName = $jsonString.properties.outputs.gs_azsearch_name.value $aksName = $jsonString.properties.outputs.gs_aks_name.value @@ -215,6 +228,8 @@ function DisplayResult([pscustomobject]$jsonString) { Write-Host "* Azure Storage Account " -ForegroundColor Yellow -NoNewline; Write-Host "$storageAccountName" -ForegroundColor Green Write-Host "* Azure Cosmos DB " -ForegroundColor Yellow -NoNewline; Write-Host "$azcosmosDBName" -ForegroundColor Green Write-Host "* Azure App Configuration Endpoint " -ForegroundColor Yellow -NoNewline; Write-Host "$azappConfigEndpoint" -ForegroundColor Green + Write-Output "rg_name=$resourcegroupName" >> $Env:GITHUB_ENV + Write-Output "SOLUTION_PREFIX=$solutionPrefix" >> $Env:GITHUB_ENV } # Function to replace placeholders in a template with actual values @@ -716,6 +731,7 @@ try { Write-Host "Upgrading node pool: $nodePool" -ForegroundColor Cyan Write-Host "Node pool $nodePool upgrade initiated." -ForegroundColor Green az aks nodepool upgrade --resource-group $deploymentResult.ResourceGroupName --cluster-name $deploymentResult.AksName --name $nodePool + } } catch { From 9ba9d346945a0bb6d8779d7e539e8d5f9cb90721 Mon Sep 17 00:00:00 2001 From: Harmanpreet Kaur Date: Wed, 1 Jan 2025 12:27:07 +0530 Subject: [PATCH 02/43] edit 2 --- .github/workflows/CI.yml | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 513e3386..051757fa 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -17,22 +17,32 @@ jobs: uses: actions/checkout@v3 # Checks out your repository # Install Azure CLI - name: Install Azure CLI - run: curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash + shell: pwsh + run: | + Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile AzureCLI.msi + Start-Process msiexec.exe -ArgumentList '/I AzureCLI.msi /quiet' -Wait - # Install kubectl + # Install kubectl (Windows method) - name: Install kubectl + shell: pwsh run: | - sudo apt-get update - sudo apt-get install -y kubectl + Invoke-WebRequest -Uri https://dl.k8s.io/release/v1.28.0/bin/windows/amd64/kubectl.exe -OutFile kubectl.exe + Move-Item -Path ./kubectl.exe -Destination "C:\kubectl.exe" + [Environment]::SetEnvironmentVariable('PATH', $env:PATH + ';C:\', [System.EnvironmentVariableTarget]::Machine) - # Install Helm + + # Install Helm (Windows method) - name: Install Helm + shell: pwsh run: | - curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash + Invoke-WebRequest -Uri https://get.helm.sh/helm-v3.13.0-windows-amd64.zip -OutFile helm.zip + Expand-Archive helm.zip -DestinationPath helm + Move-Item -Path ./helm/windows-amd64/helm.exe -Destination "C:\helm.exe" + [Environment]::SetEnvironmentVariable('PATH', $env:PATH + ';C:\', [System.EnvironmentVariableTarget]::Machine) # Set up Docker - name: Set up Docker - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v2 - name: Setup PowerShell shell: pwsh From a009099554e209a22164f7bb36d6912e514e5cb6 Mon Sep 17 00:00:00 2001 From: Harmanpreet Kaur Date: Wed, 1 Jan 2025 12:40:37 +0530 Subject: [PATCH 03/43] edit 3 --- .github/workflows/CI.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 051757fa..33665c97 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -40,6 +40,10 @@ jobs: Move-Item -Path ./helm/windows-amd64/helm.exe -Destination "C:\helm.exe" [Environment]::SetEnvironmentVariable('PATH', $env:PATH + ';C:\', [System.EnvironmentVariableTarget]::Machine) + + - name: Set Docker environment variables + run: echo "DOCKER_BUILDKIT=0" >> $GITHUB_ENV + # Set up Docker - name: Set up Docker uses: docker/setup-buildx-action@v2 From b192b13b5b7e2280384d6f9fad2ef73b2dd4e0b1 Mon Sep 17 00:00:00 2001 From: Harmanpreet Kaur Date: Wed, 1 Jan 2025 14:07:01 +0530 Subject: [PATCH 04/43] edit 3 --- .github/workflows/CI.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 33665c97..af41d95a 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -40,13 +40,15 @@ jobs: Move-Item -Path ./helm/windows-amd64/helm.exe -Destination "C:\helm.exe" [Environment]::SetEnvironmentVariable('PATH', $env:PATH + ';C:\', [System.EnvironmentVariableTarget]::Machine) - + - name: Set Docker environment variables run: echo "DOCKER_BUILDKIT=0" >> $GITHUB_ENV - + # Set up Docker - name: Set up Docker uses: docker/setup-buildx-action@v2 + with: + driver: docker - name: Setup PowerShell shell: pwsh From c2b9180f07a8bf9c25e39c48383df790f1023407 Mon Sep 17 00:00:00 2001 From: Harmanpreet Kaur Date: Wed, 1 Jan 2025 15:29:20 +0530 Subject: [PATCH 05/43] edit 4 --- Deployment/resourcedeployment.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Deployment/resourcedeployment.ps1 b/Deployment/resourcedeployment.ps1 index 174010f3..a56a061f 100644 --- a/Deployment/resourcedeployment.ps1 +++ b/Deployment/resourcedeployment.ps1 @@ -208,6 +208,7 @@ function DisplayResult([pscustomobject]$jsonString) { $storageAccountName = $jsonString.properties.outputs.gs_storageaccount_name.value $azsearchServiceName = $jsonString.properties.outputs.gs_azsearch_name.value $aksName = $jsonString.properties.outputs.gs_aks_name.value + $containerRegistryName = $jsonString.properties.outputs.gs_containerregistry_name.value $azcognitiveserviceName = $jsonString.properties.outputs.gs_azcognitiveservice_name.value $azopenaiServiceName = $jsonString.properties.outputs.gs_openaiservice_name.value @@ -229,6 +230,7 @@ function DisplayResult([pscustomobject]$jsonString) { Write-Host "* Azure Cosmos DB " -ForegroundColor Yellow -NoNewline; Write-Host "$azcosmosDBName" -ForegroundColor Green Write-Host "* Azure App Configuration Endpoint " -ForegroundColor Yellow -NoNewline; Write-Host "$azappConfigEndpoint" -ForegroundColor Green Write-Output "rg_name=$resourcegroupName" >> $Env:GITHUB_ENV + Write-Output "SOLUTION_PREFIX=$solutionPrefix" >> $Env:GITHUB_ENV } @@ -605,6 +607,8 @@ try { Write-Host "Getting the Kubernetes resource group..." -ForegroundColor Cyan $aksResourceGroupName = $(az aks show --resource-group $deploymentResult.ResourceGroupName --name $deploymentResult.AksName --query nodeResourceGroup --output tsv) Write-Host "Kubernetes resource group: $aksResourceGroupName" -ForegroundColor Green + Write-Output "krg_name=$aksResourceGroupName" >> $Env:GITHUB_ENV + } catch { Write-Host "Failed to get the Kubernetes resource group." -ForegroundColor Red From f14a3d0e7c53e0591d6be372400db77542183a5e Mon Sep 17 00:00:00 2001 From: Harmanpreet Kaur Date: Thu, 2 Jan 2025 12:06:59 +0530 Subject: [PATCH 06/43] edit 5 --- .github/workflows/CI.yml | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index af41d95a..a28b9b6e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -156,26 +156,26 @@ jobs: } - # - name: Send Notification on Failure - # if: failure() - # shell: pwsh - # run: | - # # Define the RUN_URL variable - # $RUN_URL = "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" + - name: Send Notification on Failure + if: failure() + shell: pwsh + run: | + # Define the RUN_URL variable + $RUN_URL = "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" - # # Construct the email body using a Here-String - # $EMAIL_BODY = @" - # { - # "body": "

Dear Team,

The Document Knowledge Mining Automation process encountered an issue.

Build URL: $RUN_URL

Please investigate promptly.

Best regards,
Your Automation Team

" - # } - # "@ + # Construct the email body using a Here-String + $EMAIL_BODY = @" + { + "body": "

Dear Team,

The Document Knowledge Mining Automation process encountered an issue.

Build URL: $RUN_URL

Please investigate promptly.

Best regards,
Your Automation Team

" + } + "@ - # # Send the notification with error handling - # try { - # curl -X POST "${{ secrets.LOGIC_APP_URL }}" ` - # -H "Content-Type: application/json" ` - # -d "$EMAIL_BODY" - # } catch { - # Write-Output "Failed to send notification." - # } + # Send the notification with error handling + try { + curl -X POST "${{ secrets.LOGIC_APP_URL }}" ` + -H "Content-Type: application/json" ` + -d "$EMAIL_BODY" + } catch { + Write-Output "Failed to send notification." + } \ No newline at end of file From b32526957f2e330441f53ffec31df5dbde30bd3c Mon Sep 17 00:00:00 2001 From: Harmanpreet Kaur Date: Thu, 2 Jan 2025 12:58:08 +0530 Subject: [PATCH 07/43] updated test file --- .github/workflows/tests.yml | 86 +++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 32 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9b51901d..12aa0ff3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,44 +24,66 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: '8.0.x' - - name: Install Code Coverage Tools - run: | - dotnet tool install --global coverlet.console || echo "Warning: Could not install coverlet." - env: - DOTNET_ROOT: /usr/share/dotnet - - - - name: Restore and run tests for Backend API with coverage - working-directory: ./App/backend-api + - name: Install dependencies + run: dotnet restore App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj + + - name: Check for test files + id: check-tests run: | - if [ -f "Microsoft.GS.DPS.sln" ]; then - dotnet restore Microsoft.GS.DPS.sln || echo "Warning: Some dependencies are missing. Proceeding." - if dotnet test Microsoft.GS.DPS.sln --list-tests > /dev/null 2>&1; then - dotnet test Microsoft.GS.DPS.Host/BackendApi.Tests/BackendApi.Tests.csproj --collect:"XPlat Code Coverage" --settings coverlet.runsettings --logger trx --results-directory TestResults || echo "Warning: Some tests may have failed." + if [ ! -d "App/backend-api/Microsoft.GS.DPS.Tests" ] || [ -z "$(find App/backend-api/Microsoft.GS.DPS.Tests -name '*Test*.cs')" ]; then + echo "No test files found." + echo "tests-found=false" >> $GITHUB_ENV else - echo "No test cases found in Backend API. Skipping tests." + echo "Test files found." + echo "tests-found=true" >> $GITHUB_ENV fi - else - echo "No solution file found in Backend API. Skipping tests." - fi - - name: List test result files - run: ls -R ./App/backend-api/TestResults || echo "TestResults directory not found." - - name: Verify Coverage Report + + - name: Run tests with coverage + if: env.tests-found == 'true' run: | - if [ -d "./App/backend-api/TestResults/CoverageReport" ]; then - echo "Coverage report exists." - else - echo "Coverage report not generated." - fi - - - - - name: Publish coverage results for Backend API + dotnet test App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj \ + --collect:"XPlat Code Coverage" \ + --no-build \ + --verbosity normal + env: + DOTNET_CLI_TELEMETRY_OPTOUT: 1 + + - name: Report coverage + if: env.tests-found == 'true' uses: actions/upload-artifact@v3 with: - name: backend-api-coverage - path: ./App/backend-api/TestResults/CoverageReport - + name: code-coverage-report + path: '**/TestResults/**/*.coverage' + + - name: Convert coverage to lcov + if: env.tests-found == 'true' + run: | + dotnet tool install -g coverlet.console || echo "Coverlet already installed" + export PATH="$PATH:$HOME/.dotnet/tools" + coverlet App/backend-api/Microsoft.GS.DPS.Tests/bin/Debug/net6.0/Microsoft.GS.DPS.Tests.dll \ + --target "dotnet" \ + --targetargs "test App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj --no-build --nologo --blame" \ + --output "coverage.json" --format json --threshold 80 + env: + DOTNET_CLI_TELEMETRY_OPTOUT: 1 + + - name: Upload lcov report + if: env.tests-found == 'true' + uses: actions/upload-artifact@v3 + with: + name: lcov-report + path: coverage.json + + - name: Comment on PR with coverage + if: env.tests-found == 'true' && github.event_name == 'pull_request' + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: Coverage Report + message: | + A new test coverage report is available for this PR: + ``` + $(cat coverage.json | jq '.') + ``` kernel_memory_tests: runs-on: ubuntu-latest From 75dccba42e6f2f1a702303c5111d8905790976e8 Mon Sep 17 00:00:00 2001 From: Harmanpreet Kaur Date: Thu, 2 Jan 2025 13:07:19 +0530 Subject: [PATCH 08/43] edit 1 --- .github/workflows/tests.yml | 110 +++++++++++++----------------------- 1 file changed, 39 insertions(+), 71 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 12aa0ff3..b28c3a2e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,77 +13,45 @@ on: - synchronize jobs: - backend_api_tests: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: '8.0.x' - - name: Install dependencies - run: dotnet restore App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj - - - name: Check for test files - id: check-tests - run: | - if [ ! -d "App/backend-api/Microsoft.GS.DPS.Tests" ] || [ -z "$(find App/backend-api/Microsoft.GS.DPS.Tests -name '*Test*.cs')" ]; then - echo "No test files found." - echo "tests-found=false" >> $GITHUB_ENV - else - echo "Test files found." - echo "tests-found=true" >> $GITHUB_ENV - fi - - - name: Run tests with coverage - if: env.tests-found == 'true' - run: | - dotnet test App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj \ - --collect:"XPlat Code Coverage" \ - --no-build \ - --verbosity normal - env: - DOTNET_CLI_TELEMETRY_OPTOUT: 1 - - - name: Report coverage - if: env.tests-found == 'true' - uses: actions/upload-artifact@v3 - with: - name: code-coverage-report - path: '**/TestResults/**/*.coverage' - - - name: Convert coverage to lcov - if: env.tests-found == 'true' - run: | - dotnet tool install -g coverlet.console || echo "Coverlet already installed" - export PATH="$PATH:$HOME/.dotnet/tools" - coverlet App/backend-api/Microsoft.GS.DPS.Tests/bin/Debug/net6.0/Microsoft.GS.DPS.Tests.dll \ - --target "dotnet" \ - --targetargs "test App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj --no-build --nologo --blame" \ - --output "coverage.json" --format json --threshold 80 - env: - DOTNET_CLI_TELEMETRY_OPTOUT: 1 - - - name: Upload lcov report - if: env.tests-found == 'true' - uses: actions/upload-artifact@v3 - with: - name: lcov-report - path: coverage.json - - - name: Comment on PR with coverage - if: env.tests-found == 'true' && github.event_name == 'pull_request' - uses: marocchino/sticky-pull-request-comment@v2 - with: - header: Coverage Report - message: | - A new test coverage report is available for this PR: - ``` - $(cat coverage.json | jq '.') - ``` + backend_api_tests: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + + - name: Install dependencies + run: dotnet restore App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj + + - name: Build Test Project + run: dotnet build App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj --no-restore + + - name: Check for test files + id: check-tests + run: | + if [ ! -d "App/backend-api/Microsoft.GS.DPS.Tests" ] || [ -z "$(find App/backend-api/Microsoft.GS.DPS.Tests -name '*Test*.cs')" ]; then + echo "No test files found." + echo "tests-found=false" >> $GITHUB_ENV + else + echo "Test files found." + echo "tests-found=true" >> $GITHUB_ENV + fi + + - name: Run tests with coverage + if: env.tests-found == 'true' + run: | + dotnet test App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj \ + --collect:"XPlat Code Coverage" \ + --logger "trx;LogFileName=test_results.trx" \ + --results-directory "./TestResults" \ + --no-build \ + --verbosity normal + env: + DOTNET_CLI_TELEMETRY_OPTOUT: 1 kernel_memory_tests: runs-on: ubuntu-latest From 83e35d1c8b2dff3ebc7aced96feb326acfc3e891 Mon Sep 17 00:00:00 2001 From: Harmanpreet Kaur Date: Thu, 2 Jan 2025 13:43:35 +0530 Subject: [PATCH 09/43] edit 2 --- .github/workflows/tests.yml | 88 ++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b28c3a2e..604a9145 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,10 +2,11 @@ name: Unit Tests - DKM on: push: - branches: main - + branches: + - main pull_request: - branches: main + branches: + - main types: - opened - ready_for_review @@ -13,48 +14,48 @@ on: - synchronize jobs: - backend_api_tests: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: '8.0.x' - - - name: Install dependencies - run: dotnet restore App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj - - - name: Build Test Project - run: dotnet build App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj --no-restore - - - name: Check for test files - id: check-tests - run: | - if [ ! -d "App/backend-api/Microsoft.GS.DPS.Tests" ] || [ -z "$(find App/backend-api/Microsoft.GS.DPS.Tests -name '*Test*.cs')" ]; then - echo "No test files found." - echo "tests-found=false" >> $GITHUB_ENV - else - echo "Test files found." - echo "tests-found=true" >> $GITHUB_ENV - fi - - - name: Run tests with coverage - if: env.tests-found == 'true' - run: | - dotnet test App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj \ - --collect:"XPlat Code Coverage" \ - --logger "trx;LogFileName=test_results.trx" \ - --results-directory "./TestResults" \ - --no-build \ - --verbosity normal - env: - DOTNET_CLI_TELEMETRY_OPTOUT: 1 - kernel_memory_tests: + backend_api_tests: runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + + - name: Install dependencies + run: dotnet restore App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj + - name: Build Test Project + run: dotnet build App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj --no-restore + + - name: Check for test files + id: check-tests + run: | + if [ ! -d "App/backend-api/Microsoft.GS.DPS.Tests" ] || [ -z "$(find App/backend-api/Microsoft.GS.DPS.Tests -name '*Test*.cs')" ]; then + echo "No test files found." + echo "tests-found=false" >> $GITHUB_ENV + else + echo "Test files found." + echo "tests-found=true" >> $GITHUB_ENV + fi + + - name: Run tests with coverage + if: env.tests-found == 'true' + run: | + dotnet test App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj \ + --collect:"XPlat Code Coverage" \ + --logger "trx;LogFileName=test_results.trx" \ + --results-directory "./TestResults" \ + --no-build \ + --verbosity normal + env: + DOTNET_CLI_TELEMETRY_OPTOUT: 1 + + kernel_memory_tests: + runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 @@ -86,7 +87,6 @@ jobs: frontend_tests: runs-on: ubuntu-latest - steps: - name: Checkout code uses: actions/checkout@v3 From 4e2af1575f91e1ee6ffa64535b68f925bcaf61c5 Mon Sep 17 00:00:00 2001 From: Harmanpreet Kaur Date: Thu, 2 Jan 2025 14:07:20 +0530 Subject: [PATCH 10/43] edit 3 --- .github/workflows/tests.yml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 604a9145..1b3f8cac 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -31,28 +31,28 @@ jobs: - name: Build Test Project run: dotnet build App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj --no-restore - - name: Check for test files - id: check-tests - run: | - if [ ! -d "App/backend-api/Microsoft.GS.DPS.Tests" ] || [ -z "$(find App/backend-api/Microsoft.GS.DPS.Tests -name '*Test*.cs')" ]; then - echo "No test files found." - echo "tests-found=false" >> $GITHUB_ENV - else - echo "Test files found." - echo "tests-found=true" >> $GITHUB_ENV - fi - - name: Run tests with coverage - if: env.tests-found == 'true' run: | dotnet test App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj \ --collect:"XPlat Code Coverage" \ --logger "trx;LogFileName=test_results.trx" \ --results-directory "./TestResults" \ - --no-build \ - --verbosity normal - env: - DOTNET_CLI_TELEMETRY_OPTOUT: 1 + /p:CollectCoverage=true \ + /p:CoverletOutputFormat=json \ + /p:CoverletOutput=./coverage/ + + - name: Install Report Generator + run: dotnet tool install -g dotnet-reportgenerator-globaltool + + - name: Generate Coverage Report + run: | + reportgenerator \ + -reports:./coverage/coverage.json \ + -targetdir:./coverage-report \ + -reporttypes:TextSummary + + - name: Display Coverage + run: cat ./coverage-report/Summary.txt kernel_memory_tests: runs-on: ubuntu-latest From d56bcaee6d31d6ec95047f09806b133e8ffe556f Mon Sep 17 00:00:00 2001 From: Harmanpreet Kaur Date: Thu, 2 Jan 2025 15:10:31 +0530 Subject: [PATCH 11/43] edit 4 --- .github/workflows/tests.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1b3f8cac..63a4793b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -38,8 +38,8 @@ jobs: --logger "trx;LogFileName=test_results.trx" \ --results-directory "./TestResults" \ /p:CollectCoverage=true \ - /p:CoverletOutputFormat=json \ - /p:CoverletOutput=./coverage/ + /p:CoverletOutputFormat=cobertura \ + /p:CoverletOutput=./TestResults/coverage.cobertura.xml - name: Install Report Generator run: dotnet tool install -g dotnet-reportgenerator-globaltool @@ -47,12 +47,20 @@ jobs: - name: Generate Coverage Report run: | reportgenerator \ - -reports:./coverage/coverage.json \ + -reports:./TestResults/coverage.cobertura.xml \ -targetdir:./coverage-report \ -reporttypes:TextSummary - name: Display Coverage - run: cat ./coverage-report/Summary.txt + run: | + echo "Code Coverage Summary:" + cat ./coverage-report/Summary.txt + + - name: Upload Coverage Report + uses: actions/upload-artifact@v3 + with: + name: backend-api-coverage + path: ./coverage-report kernel_memory_tests: runs-on: ubuntu-latest From 13963a9b6bd2d69f21b0d9008c0267c4b849132b Mon Sep 17 00:00:00 2001 From: Harmanpreet Kaur Date: Thu, 2 Jan 2025 15:13:33 +0530 Subject: [PATCH 12/43] edit 5 --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 63a4793b..880cda9f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -47,7 +47,7 @@ jobs: - name: Generate Coverage Report run: | reportgenerator \ - -reports:./TestResults/coverage.cobertura.xml \ + -reports:./TestResults/**/coverage.cobertura.xml \ -targetdir:./coverage-report \ -reporttypes:TextSummary From 254e0f5ad64c31c0e49cdc1651c964af8ff56043 Mon Sep 17 00:00:00 2001 From: Harmanpreet Kaur Date: Thu, 2 Jan 2025 15:20:27 +0530 Subject: [PATCH 13/43] edit 6 --- .github/workflows/tests.yml | 113 +++++++++++++++++++++++++++--------- 1 file changed, 84 insertions(+), 29 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 880cda9f..3383d40f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -26,35 +26,54 @@ jobs: dotnet-version: '8.0.x' - name: Install dependencies - run: dotnet restore App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj + run: | + if [ -f "App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj" ]; then + dotnet restore App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj + else + echo "No test project found for Backend API. Skipping tests." + exit 0 + fi - name: Build Test Project - run: dotnet build App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj --no-restore + run: | + if [ -f "App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj" ]; then + dotnet build App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj --no-restore + fi - name: Run tests with coverage run: | - dotnet test App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj \ - --collect:"XPlat Code Coverage" \ - --logger "trx;LogFileName=test_results.trx" \ - --results-directory "./TestResults" \ - /p:CollectCoverage=true \ - /p:CoverletOutputFormat=cobertura \ - /p:CoverletOutput=./TestResults/coverage.cobertura.xml + if [ -f "App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj" ]; then + dotnet test App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj \ + --collect:"XPlat Code Coverage" \ + --logger "trx;LogFileName=test_results.trx" \ + --results-directory "./TestResults" \ + /p:CollectCoverage=true \ + /p:CoverletOutputFormat=cobertura \ + /p:CoverletOutput=./TestResults/coverage.cobertura.xml + fi - name: Install Report Generator run: dotnet tool install -g dotnet-reportgenerator-globaltool - name: Generate Coverage Report run: | - reportgenerator \ - -reports:./TestResults/**/coverage.cobertura.xml \ - -targetdir:./coverage-report \ - -reporttypes:TextSummary + if [ -f "./TestResults/**/coverage.cobertura.xml" ]; then + reportgenerator \ + -reports:./TestResults/**/coverage.cobertura.xml \ + -targetdir:./coverage-report \ + -reporttypes:TextSummary + else + echo "No coverage report generated. Skipping report generation." + fi - name: Display Coverage run: | - echo "Code Coverage Summary:" - cat ./coverage-report/Summary.txt + if [ -f "./coverage-report/Summary.txt" ]; then + echo "Code Coverage Summary:" + cat ./coverage-report/Summary.txt + else + echo "No coverage summary available." + fi - name: Upload Coverage Report uses: actions/upload-artifact@v3 @@ -62,7 +81,7 @@ jobs: name: backend-api-coverage path: ./coverage-report - kernel_memory_tests: + semantic_kernel_tests: runs-on: ubuntu-latest steps: - name: Checkout code @@ -73,25 +92,61 @@ jobs: with: dotnet-version: '8.0.x' - - name: Restore and run tests for Kernel Memory with coverage - working-directory: ./App/kernel-memory + - name: Install dependencies + run: | + if [ -f "App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj" ]; then + dotnet restore App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj + else + echo "No test project found for Semantic Kernel. Skipping tests." + exit 0 + fi + + - name: Build Test Project + run: | + if [ -f "App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj" ]; then + dotnet build App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj --no-restore + fi + + - name: Run tests with coverage run: | - if [ -f "KernelMemory.sln" ]; then - dotnet restore KernelMemory.sln || echo "Warning: Some dependencies are missing. Proceeding." - if dotnet test KernelMemory.sln --list-tests > /dev/null 2>&1; then - dotnet test KernelMemory.sln --collect:"XPlat Code Coverage" --logger trx --results-directory TestResults || echo "Warning: Some tests may have failed." - else - echo "No test cases found in Kernel Memory. Skipping tests." - fi + if [ -f "App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj" ]; then + dotnet test App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj \ + --collect:"XPlat Code Coverage" \ + --logger "trx;LogFileName=test_results.trx" \ + --results-directory "./TestResults" \ + /p:CollectCoverage=true \ + /p:CoverletOutputFormat=cobertura \ + /p:CoverletOutput=./TestResults/coverage.cobertura.xml + fi + + - name: Install Report Generator + run: dotnet tool install -g dotnet-reportgenerator-globaltool + + - name: Generate Coverage Report + run: | + if [ -f "./TestResults/**/coverage.cobertura.xml" ]; then + reportgenerator \ + -reports:./TestResults/**/coverage.cobertura.xml \ + -targetdir:./coverage-report \ + -reporttypes:TextSummary + else + echo "No coverage report generated. Skipping report generation." + fi + + - name: Display Coverage + run: | + if [ -f "./coverage-report/Summary.txt" ]; then + echo "Code Coverage Summary:" + cat ./coverage-report/Summary.txt else - echo "No solution file found in Kernel Memory. Skipping tests." + echo "No coverage summary available." fi - - name: Publish coverage results for Kernel Memory + - name: Upload Coverage Report uses: actions/upload-artifact@v3 with: - name: kernel-memory-coverage - path: ./App/kernel-memory/TestResults/CoverageReport + name: semantic-kernel-coverage + path: ./coverage-report frontend_tests: runs-on: ubuntu-latest From 2641ced821b645b12970f8153be3813f6164a7ee Mon Sep 17 00:00:00 2001 From: Harmanpreet Kaur Date: Thu, 2 Jan 2025 15:46:21 +0530 Subject: [PATCH 14/43] edit 7 --- .github/workflows/tests.yml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3383d40f..d70014dc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -51,20 +51,19 @@ jobs: /p:CoverletOutputFormat=cobertura \ /p:CoverletOutput=./TestResults/coverage.cobertura.xml fi + - name: Find Coverage File + id: coverage_path + run: echo "coverage_file=$(find ./TestResults -name 'coverage.cobertura.xml')" >> $GITHUB_ENV - name: Install Report Generator run: dotnet tool install -g dotnet-reportgenerator-globaltool - name: Generate Coverage Report run: | - if [ -f "./TestResults/**/coverage.cobertura.xml" ]; then - reportgenerator \ - -reports:./TestResults/**/coverage.cobertura.xml \ - -targetdir:./coverage-report \ - -reporttypes:TextSummary - else - echo "No coverage report generated. Skipping report generation." - fi + reportgenerator \ + -reports:${{ env.coverage_file }} \ + -targetdir:./coverage-report \ + -reporttypes:TextSummary - name: Display Coverage run: | From 05d7e3aaa02f79b8375fa88437c8c00f4f673000 Mon Sep 17 00:00:00 2001 From: Harmanpreet Kaur Date: Thu, 2 Jan 2025 16:28:40 +0530 Subject: [PATCH 15/43] edit 8 --- .github/workflows/tests.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d70014dc..b512909b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -60,10 +60,12 @@ jobs: - name: Generate Coverage Report run: | - reportgenerator \ - -reports:${{ env.coverage_file }} \ - -targetdir:./coverage-report \ - -reporttypes:TextSummary + if [ -f "App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj" ]; then + reportgenerator \ + -reports:${{ env.coverage_file }} \ + -targetdir:./coverage-report \ + -reporttypes:TextSummary + fi - name: Display Coverage run: | From 436f9f674acd1c1d9e5eff566774eedd7ad3a1cc Mon Sep 17 00:00:00 2001 From: Harmanpreet Kaur Date: Thu, 2 Jan 2025 16:52:45 +0530 Subject: [PATCH 16/43] edit 9 --- .github/workflows/tests.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b512909b..effc734b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -51,18 +51,13 @@ jobs: /p:CoverletOutputFormat=cobertura \ /p:CoverletOutput=./TestResults/coverage.cobertura.xml fi - - name: Find Coverage File - id: coverage_path - run: echo "coverage_file=$(find ./TestResults -name 'coverage.cobertura.xml')" >> $GITHUB_ENV - - name: Install Report Generator - run: dotnet tool install -g dotnet-reportgenerator-globaltool - name: Generate Coverage Report run: | if [ -f "App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj" ]; then reportgenerator \ - -reports:${{ env.coverage_file }} \ + -reports:./TestResults/**/coverage.cobertura.xml \ \ -targetdir:./coverage-report \ -reporttypes:TextSummary fi From 173a0c38564c2f89ff5b823de6436d8103b93c69 Mon Sep 17 00:00:00 2001 From: Harmanpreet Kaur Date: Thu, 2 Jan 2025 16:54:43 +0530 Subject: [PATCH 17/43] edit 10 --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index effc734b..97ccb386 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -57,7 +57,7 @@ jobs: run: | if [ -f "App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj" ]; then reportgenerator \ - -reports:./TestResults/**/coverage.cobertura.xml \ \ + -reports:./TestResults/**/coverage.cobertura.xml \ -targetdir:./coverage-report \ -reporttypes:TextSummary fi From 98e3d00e0afba436d78bac1d11f99b895717e922 Mon Sep 17 00:00:00 2001 From: Harmanpreet Kaur Date: Thu, 2 Jan 2025 16:57:34 +0530 Subject: [PATCH 18/43] edit 11 --- .github/workflows/tests.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 97ccb386..186b2d33 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -53,8 +53,10 @@ jobs: fi + - name: Generate Coverage Report run: | + dotnet tool install -g dotnet-reportgenerator-globaltool if [ -f "App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj" ]; then reportgenerator \ -reports:./TestResults/**/coverage.cobertura.xml \ From 01a85f561a235ffc9b0769293829bb903df98575 Mon Sep 17 00:00:00 2001 From: Harmanpreet Kaur Date: Thu, 2 Jan 2025 17:40:40 +0530 Subject: [PATCH 19/43] edit 12 --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 186b2d33..7ae3ef35 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -122,7 +122,7 @@ jobs: - name: Generate Coverage Report run: | - if [ -f "./TestResults/**/coverage.cobertura.xml" ]; then + if [ -f "App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj" ]; then reportgenerator \ -reports:./TestResults/**/coverage.cobertura.xml \ -targetdir:./coverage-report \ From baa14614cf417d60a588a5180c8ce01807aea550 Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 20:41:05 +0530 Subject: [PATCH 20/43] Delete .github/workflows/tests.yml --- .github/workflows/tests.yml | 173 ------------------------------------ 1 file changed, 173 deletions(-) delete mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index 7ae3ef35..00000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,173 +0,0 @@ -name: Unit Tests - DKM - -on: - push: - branches: - - main - pull_request: - branches: - - main - types: - - opened - - ready_for_review - - reopened - - synchronize - -jobs: - backend_api_tests: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: '8.0.x' - - - name: Install dependencies - run: | - if [ -f "App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj" ]; then - dotnet restore App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj - else - echo "No test project found for Backend API. Skipping tests." - exit 0 - fi - - - name: Build Test Project - run: | - if [ -f "App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj" ]; then - dotnet build App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj --no-restore - fi - - - name: Run tests with coverage - run: | - if [ -f "App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj" ]; then - dotnet test App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj \ - --collect:"XPlat Code Coverage" \ - --logger "trx;LogFileName=test_results.trx" \ - --results-directory "./TestResults" \ - /p:CollectCoverage=true \ - /p:CoverletOutputFormat=cobertura \ - /p:CoverletOutput=./TestResults/coverage.cobertura.xml - fi - - - - - name: Generate Coverage Report - run: | - dotnet tool install -g dotnet-reportgenerator-globaltool - if [ -f "App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj" ]; then - reportgenerator \ - -reports:./TestResults/**/coverage.cobertura.xml \ - -targetdir:./coverage-report \ - -reporttypes:TextSummary - fi - - - name: Display Coverage - run: | - if [ -f "./coverage-report/Summary.txt" ]; then - echo "Code Coverage Summary:" - cat ./coverage-report/Summary.txt - else - echo "No coverage summary available." - fi - - - name: Upload Coverage Report - uses: actions/upload-artifact@v3 - with: - name: backend-api-coverage - path: ./coverage-report - - semantic_kernel_tests: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: '8.0.x' - - - name: Install dependencies - run: | - if [ -f "App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj" ]; then - dotnet restore App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj - else - echo "No test project found for Semantic Kernel. Skipping tests." - exit 0 - fi - - - name: Build Test Project - run: | - if [ -f "App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj" ]; then - dotnet build App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj --no-restore - fi - - - name: Run tests with coverage - run: | - if [ -f "App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj" ]; then - dotnet test App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj \ - --collect:"XPlat Code Coverage" \ - --logger "trx;LogFileName=test_results.trx" \ - --results-directory "./TestResults" \ - /p:CollectCoverage=true \ - /p:CoverletOutputFormat=cobertura \ - /p:CoverletOutput=./TestResults/coverage.cobertura.xml - fi - - - name: Install Report Generator - run: dotnet tool install -g dotnet-reportgenerator-globaltool - - - name: Generate Coverage Report - run: | - if [ -f "App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj" ]; then - reportgenerator \ - -reports:./TestResults/**/coverage.cobertura.xml \ - -targetdir:./coverage-report \ - -reporttypes:TextSummary - else - echo "No coverage report generated. Skipping report generation." - fi - - - name: Display Coverage - run: | - if [ -f "./coverage-report/Summary.txt" ]; then - echo "Code Coverage Summary:" - cat ./coverage-report/Summary.txt - else - echo "No coverage summary available." - fi - - - name: Upload Coverage Report - uses: actions/upload-artifact@v3 - with: - name: semantic-kernel-coverage - path: ./coverage-report - - frontend_tests: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: 16 - - - name: Install dependencies - working-directory: ./App/frontend-app - run: | - npm install --legacy-peer-deps || echo "Warning: Dependency installation failed. Proceeding." - - - name: Run tests for Frontend App with coverage - working-directory: ./App/frontend-app - run: | - if find src -type f \( -name "*.test.tsx" -o -name "*.spec.tsx" -o -name "*.test.ts" -o -name "*.spec.ts" \) | grep -q .; then - echo "Test files found. Proceeding with tests." - npx jest --coverage --coverageDirectory=coverage --detectOpenHandles - else - echo "No test files found in Frontend App. Skipping tests." - fi From 94642befd839ac97ca200abf27ae5030bd5145b1 Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 20:54:40 +0530 Subject: [PATCH 21/43] Delete .github/CODEOWNERS --- .github/CODEOWNERS | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS deleted file mode 100644 index fded4435..00000000 --- a/.github/CODEOWNERS +++ /dev/null @@ -1,5 +0,0 @@ -# Lines starting with '#' are comments. -# Each line is a file pattern followed by one or more owners. - -# These owners will be the default owners for everything in the repo. -* @Avijit-Microsoft @Roopan-Microsoft @Prajwal-Microsoft @dongbumlee \ No newline at end of file From 4d4cc990f86fe319765643ef81d9c7b039ab1fe5 Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 20:57:31 +0530 Subject: [PATCH 22/43] Delete .github/ISSUE_TEMPLATE/bug_report.md --- .github/ISSUE_TEMPLATE/bug_report.md | 45 ---------------------------- 1 file changed, 45 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/bug_report.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 882ebd79..00000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,45 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve -title: '' -labels: bug -assignees: '' - ---- - -# Describe the bug -A clear and concise description of what the bug is. - -# Expected behavior -A clear and concise description of what you expected to happen. - -# How does this bug make you feel? -_Share a gif from [giphy](https://giphy.com/) to tells us how you'd feel_ - ---- - -# Debugging information - -## Steps to reproduce -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error - -## Screenshots -If applicable, add screenshots to help explain your problem. - -## Logs - -If applicable, add logs to help the engineer debug the problem. - ---- - -# Tasks - -_To be filled in by the engineer picking up the issue_ - -- [ ] Task 1 -- [ ] Task 2 -- [ ] ... From 8fca4e5909c69de0d60a28a062c58864cd75b27f Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 20:58:04 +0530 Subject: [PATCH 23/43] Delete .github/ISSUE_TEMPLATE/feature_request.md --- .github/ISSUE_TEMPLATE/feature_request.md | 32 ----------------------- 1 file changed, 32 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index 3496fc82..00000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project -title: '' -labels: enhancement -assignees: '' - ---- - -# Motivation - -A clear and concise description of why this feature would be useful and the value it would bring. -Explain any alternatives considered and why they are not sufficient. - -# How would you feel if this feature request was implemented? - -_Share a gif from [giphy](https://giphy.com/) to tells us how you'd feel. Format: ![alt_text](https://media.giphy.com/media/xxx/giphy.gif)_ - -# Requirements - -A list of requirements to consider this feature delivered -- Requirement 1 -- Requirement 2 -- ... - -# Tasks - -_To be filled in by the engineer picking up the issue_ - -- [ ] Task 1 -- [ ] Task 2 -- [ ] ... From 913f0d702b9ebc98f26055f10838ce1c01b344ae Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 20:58:19 +0530 Subject: [PATCH 24/43] Delete .github/ISSUE_TEMPLATE/subtask.md --- .github/ISSUE_TEMPLATE/subtask.md | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/subtask.md diff --git a/.github/ISSUE_TEMPLATE/subtask.md b/.github/ISSUE_TEMPLATE/subtask.md deleted file mode 100644 index 9f86c843..00000000 --- a/.github/ISSUE_TEMPLATE/subtask.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -name: Sub task -about: A sub task -title: '' -labels: subtask -assignees: '' - ---- - -Required by - -# Description - -A clear and concise description of what this subtask is. - -# Tasks - -_To be filled in by the engineer picking up the subtask - -- [ ] Task 1 -- [ ] Task 2 -- [ ] ... From 1806a51b2b3785fbda96c05715ad42b166ce32a4 Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 20:58:34 +0530 Subject: [PATCH 25/43] Delete .github/PULL_REQUEST_TEMPLATE.md --- .github/PULL_REQUEST_TEMPLATE.md | 37 -------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 22b04b72..00000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,37 +0,0 @@ -## Purpose - -* ... - -## Does this introduce a breaking change? - - -- [ ] Yes -- [ ] No - - - -## Golden Path Validation -- [ ] I have tested the primary workflows (the "golden path") to ensure they function correctly without errors. - -## Deployment Validation -- [ ] I have validated the deployment process successfully and all services are running as expected with this change. - -## What to Check -Verify that the following are valid -* ... - -## Other Information - \ No newline at end of file From 990487a578dd5cf35f776a916f7a126e455691c5 Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 20:59:00 +0530 Subject: [PATCH 26/43] Delete .github/workflows/pr-title-checker.yml --- .github/workflows/pr-title-checker.yml | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 .github/workflows/pr-title-checker.yml diff --git a/.github/workflows/pr-title-checker.yml b/.github/workflows/pr-title-checker.yml deleted file mode 100644 index 5cbbae1a..00000000 --- a/.github/workflows/pr-title-checker.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: "pr-title-checker" - -on: - pull_request_target: - types: - - opened - - edited - - synchronize - merge_group: - -permissions: - pull-requests: read - -jobs: - main: - name: Validate PR title - runs-on: ubuntu-latest - if: ${{ github.event_name != 'merge_group' }} - steps: - - uses: amannn/action-semantic-pull-request@v5 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From f753f6a7ae0144e1bbf18284ee80f283ae8697e0 Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 20:59:17 +0530 Subject: [PATCH 27/43] Delete .github/workflows/stale-bot.yml --- .github/workflows/stale-bot.yml | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 .github/workflows/stale-bot.yml diff --git a/.github/workflows/stale-bot.yml b/.github/workflows/stale-bot.yml deleted file mode 100644 index e31059ab..00000000 --- a/.github/workflows/stale-bot.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: 'Close stale issues and PRs' -on: - schedule: - - cron: '30 1 * * *' - -permissions: - contents: write - issues: write - pull-requests: write - -jobs: - stale: - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v9 - with: - stale-issue-message: 'This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days.' - days-before-stale: 180 - days-before-close: 30 From cc3a4ec5ec23ade10e8b8f34e90eb0b5ff081e8e Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 20:59:53 +0530 Subject: [PATCH 28/43] Delete App/kernel-memory/service/Abstractions/Constants.cs --- .../service/Abstractions/Constants.cs | 167 ------------------ 1 file changed, 167 deletions(-) delete mode 100644 App/kernel-memory/service/Abstractions/Constants.cs diff --git a/App/kernel-memory/service/Abstractions/Constants.cs b/App/kernel-memory/service/Abstractions/Constants.cs deleted file mode 100644 index d2e516f7..00000000 --- a/App/kernel-memory/service/Abstractions/Constants.cs +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -namespace Microsoft.KernelMemory; - -public static class Constants -{ - public static class WebService - { - // Form field/Query param containing the Index Name - public const string IndexField = "index"; - - // Form field/Query param containing the Document ID - public const string DocumentIdField = "documentId"; - - // Form field/Query param containing the Filename - public const string FilenameField = "filename"; - - // Form field containing the list of tags - public const string TagsField = "tags"; - - // Form field containing the list of pipeline steps - public const string StepsField = "steps"; - - // Form field containing the optional arguments JSON string - public const string ArgsField = "args"; - } - - public static class CustomContext - { - public static class Partitioning - { - // Used to override MaxTokensPerParagraph config - public const string MaxTokensPerParagraph = "custom_partitioning_max_tokens_per_paragraph_int"; - - // Used to override OverlappingTokens config - public const string OverlappingTokens = "custom_partitioning_overlapping_tokens_int"; - - // Used to prepend header to each partition - public const string ChunkHeader = "custom_partitioning_chunk_header_str"; - } - - public static class EmbeddingGeneration - { - // Used to override MaxBatchSize embedding generators config - public const string BatchSize = "custom_embedding_generation_batch_size_int"; - } - - public static class Rag - - { - // Used to override No Answer config - public const string EmptyAnswer = "custom_rag_empty_answer_str"; - - // Used to override the RAG prompt - public const string Prompt = "custom_rag_prompt_str"; - - // Used to override how facts are injected into RAG prompt - public const string FactTemplate = "custom_rag_fact_template_str"; - - // Used to override the max tokens to generate when using the RAG prompt - public const string MaxTokens = "custom_rag_max_tokens_int"; - - // Used to override the temperature (default 0) used with the RAG prompt - public const string Temperature = "custom_rag_temperature_float"; - - // Used to override the nucleus sampling probability (default 0) used with the RAG prompt - public const string NucleusSampling = "custom_rag_nucleus_sampling_float"; - } - - public static class Summary - { - // Used to override the summarization prompt - public const string Prompt = "custom_summary_prompt_str"; - - // Used to override the size of the summary - public const string TargetTokenSize = "custom_summary_target_token_size_int"; - - // Used to override the number of overlapping tokens - public const string OverlappingTokens = "custom_summary_overlapping_tokens_int"; - } - } - - // // Default User ID owning documents uploaded without specifying a user - // public const string DefaultDocumentOwnerUserId = "defaultUser"; - - // Internal file used to track progress of asynchronous pipelines - public const string PipelineStatusFilename = "__pipeline_status.json"; - - // Tags settings - public const char ReservedEqualsChar = ':'; - public const string ReservedTagsPrefix = "__"; - - // Tags reserved for internal logic - public const string ReservedDocumentIdTag = $"{ReservedTagsPrefix}document_id"; - public const string ReservedFileIdTag = $"{ReservedTagsPrefix}file_id"; - public const string ReservedFilePartitionTag = $"{ReservedTagsPrefix}file_part"; - public const string ReservedFilePartitionNumberTag = $"{ReservedTagsPrefix}part_n"; - public const string ReservedFileSectionNumberTag = $"{ReservedTagsPrefix}sect_n"; - public const string ReservedFileTypeTag = $"{ReservedTagsPrefix}file_type"; - public const string ReservedSyntheticTypeTag = $"{ReservedTagsPrefix}synth"; - - // Known tags - public const string TagsSyntheticSummary = "summary"; - - // Properties stored inside the payload - public const string ReservedPayloadSchemaVersionField = "schema"; - public const string ReservedPayloadTextField = "text"; - public const string ReservedPayloadFileNameField = "file"; - public const string ReservedPayloadUrlField = "url"; - public const string ReservedPayloadLastUpdateField = "last_update"; - public const string ReservedPayloadVectorProviderField = "vector_provider"; - public const string ReservedPayloadVectorGeneratorField = "vector_generator"; - - // Endpoints - public const string HttpAskEndpoint = "/ask"; - public const string HttpSearchEndpoint = "/search"; - public const string HttpDownloadEndpoint = "/download"; - public const string HttpUploadEndpoint = "/upload"; - public const string HttpUploadStatusEndpoint = "/upload-status"; - public const string HttpDocumentsEndpoint = "/documents"; - public const string HttpIndexesEndpoint = "/indexes"; - public const string HttpDeleteDocumentEndpointWithParams = $"{HttpDocumentsEndpoint}?{WebService.IndexField}={HttpIndexPlaceholder}&{WebService.DocumentIdField}={HttpDocumentIdPlaceholder}"; - public const string HttpDeleteIndexEndpointWithParams = $"{HttpIndexesEndpoint}?{WebService.IndexField}={HttpIndexPlaceholder}"; - public const string HttpUploadStatusEndpointWithParams = $"{HttpUploadStatusEndpoint}?{WebService.IndexField}={HttpIndexPlaceholder}&{WebService.DocumentIdField}={HttpDocumentIdPlaceholder}"; - public const string HttpDownloadEndpointWithParams = $"{HttpDownloadEndpoint}?{WebService.IndexField}={HttpIndexPlaceholder}&{WebService.DocumentIdField}={HttpDocumentIdPlaceholder}&{WebService.FilenameField}={HttpFilenamePlaceholder}"; - public const string HttpIndexPlaceholder = "{index}"; - public const string HttpDocumentIdPlaceholder = "{documentId}"; - public const string HttpFilenamePlaceholder = "{filename}"; - - // Pipeline Handlers, Step names - public const string PipelineStepsExtract = "extract"; - public const string PipelineStepsPartition = "partition"; - public const string PipelineStepsGenEmbeddings = "gen_embeddings"; - public const string PipelineStepsSaveRecords = "save_records"; - public const string PipelineStepsSummarize = "summarize"; - public const string PipelineStepsDeleteGeneratedFiles = "delete_generated_files"; - public const string PipelineStepsDeleteDocument = "private_delete_document"; - public const string PipelineStepsDeleteIndex = "private_delete_index"; - public const string PipelineStepsKeywordExtraction = "keyword_extraction"; - - // Pipeline steps - public static readonly string[] DefaultPipeline = - { - PipelineStepsExtract, PipelineStepsPartition, PipelineStepsGenEmbeddings, PipelineStepsSaveRecords - }; - - public static readonly string[] PipelineWithoutSummary = - { - PipelineStepsExtract, PipelineStepsPartition, PipelineStepsGenEmbeddings, PipelineStepsSaveRecords - }; - - public static readonly string[] PipelineWithSummary = - { - PipelineStepsExtract, PipelineStepsPartition, PipelineStepsGenEmbeddings, PipelineStepsSaveRecords, - PipelineStepsSummarize, PipelineStepsGenEmbeddings, PipelineStepsSaveRecords - }; - - public static readonly string[] PipelineOnlySummary = - { - PipelineStepsExtract, PipelineStepsSummarize, PipelineStepsGenEmbeddings, PipelineStepsSaveRecords - }; - - // Standard prompt names - public const string PromptNamesSummarize = "summarize"; - public const string PromptNamesAnswerWithFacts = "answer-with-facts"; - public const string PromptNamesExtractKeywords = "extract-keywords"; -} From e60dfd26dbf89364f17ca10fbcb652255b3ea0c1 Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 21:00:08 +0530 Subject: [PATCH 29/43] Delete App/kernel-memory/service/Core/Core.csproj --- App/kernel-memory/service/Core/Core.csproj | 66 ---------------------- 1 file changed, 66 deletions(-) delete mode 100644 App/kernel-memory/service/Core/Core.csproj diff --git a/App/kernel-memory/service/Core/Core.csproj b/App/kernel-memory/service/Core/Core.csproj deleted file mode 100644 index c3ab4dd3..00000000 --- a/App/kernel-memory/service/Core/Core.csproj +++ /dev/null @@ -1,66 +0,0 @@ - - - - net8.0 - LatestMajor - Microsoft.KernelMemory.Core - Microsoft.KernelMemory - $(NoWarn);KMEXP00;KMEXP01;KMEXP02;KMEXP03;KMEXP04;SKEXP0001;SKEXP0011;CA2208;CA1308;CA1724; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - Microsoft.KernelMemory.Core - Kernel Memory library, including extensions and Serverless and Web client - The package contains all the core logic and extensions of Kernel Memory, to index and query any data and documents, using LLM and natural language, tracking sources and showing citations. - Copilot, Plugin, Memory, RAG, Kernel Memory, Semantic Memory, Episodic Memory, Declarative Memory, AI, Artificial Intelligence, Embeddings, Vector DB, Vector Search, Memory DB, ETL - bin/$(Configuration)/$(TargetFramework)/$(AssemblyName).xml - - - - - - - From 42722aa2813bc08dca5c4f8ec05f5bb10cf0bdd2 Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 21:00:26 +0530 Subject: [PATCH 30/43] Delete App/kernel-memory/service/Core/Handlers/KeywordExtractingHandler.cs --- .../Core/Handlers/KeywordExtractingHandler.cs | 138 ------------------ 1 file changed, 138 deletions(-) delete mode 100644 App/kernel-memory/service/Core/Handlers/KeywordExtractingHandler.cs diff --git a/App/kernel-memory/service/Core/Handlers/KeywordExtractingHandler.cs b/App/kernel-memory/service/Core/Handlers/KeywordExtractingHandler.cs deleted file mode 100644 index df66dedf..00000000 --- a/App/kernel-memory/service/Core/Handlers/KeywordExtractingHandler.cs +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System; -using System.Collections.Generic; -using System.Text.Json; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Extensions.Logging; -using Microsoft.KernelMemory.Diagnostics; -using Microsoft.KernelMemory.Pipeline; -using Microsoft.SemanticKernel; -using Microsoft.SemanticKernel.ChatCompletion; -using static Microsoft.KernelMemory.Pipeline.DataPipeline; -using Microsoft.KernelMemory.Prompts; - -namespace Microsoft.KernelMemory.Handlers; - -public sealed class KeywordExtractingHandler : IPipelineStepHandler -{ - public string StepName { get; } - private readonly ILogger _log; - private readonly IPipelineOrchestrator _orchestrator; - private readonly Kernel _kernel; - private readonly KernelMemoryConfig? _config = null; - private readonly string _extractKeywordPrompt; - - public KeywordExtractingHandler( - string stepName, - IPipelineOrchestrator orchestrator, - KernelMemoryConfig config = null, - IPromptProvider? promptProvider = null, - ILoggerFactory? loggerFactory = null - ) - { - this.StepName = stepName; - this._log = (loggerFactory ?? DefaultLogger.Factory).CreateLogger(); - this._orchestrator = orchestrator; - this._config = config; - - promptProvider ??= new EmbeddedPromptProvider(); - - this._extractKeywordPrompt = promptProvider.ReadPrompt(Constants.PromptNamesExtractKeywords); - - //init Semantic Kernel - this._kernel = Kernel.CreateBuilder() - .AddAzureOpenAIChatCompletion(deploymentName: (string)this._config.Services["AzureOpenAIText"]["Deployment"], - endpoint: (string)this._config.Services["AzureOpenAIText"]["Endpoint"], - apiKey: (string)this._config.Services["AzureOpenAIText"]["APIKey"]) - .Build(); - } - - public async Task<(bool success, DataPipeline updatedPipeline)> InvokeAsync(DataPipeline pipeline, CancellationToken cancellationToken = default) - { - this._log.LogDebug("Extracting Keywords from the content", pipeline.Index, pipeline.DocumentId); - - foreach (FileDetails uploadedFile in pipeline.Files) - { - Dictionary extractedTagsFile = new(); - - foreach (KeyValuePair generatedFile in uploadedFile.GeneratedFiles) - { - var file = generatedFile.Value; - - if (file.AlreadyProcessedBy(this)) - { - this._log.LogDebug("File {FileName} has already been processed by {HandlerName}", file.Name, this.StepName); - continue; - } - - // Extract keywords from the file - if (file.ArtifactType == DataPipeline.ArtifactTypes.ExtractedText) - { - this._log.LogDebug("Extracting Tags from the file {FileName}", file.Name); - - var sourceFile = uploadedFile.Name; - string extactedFileContent = string.Empty; - - BinaryData fileContent = await this._orchestrator.ReadFileAsync(pipeline, file.Name, cancellationToken).ConfigureAwait(false); - - //set file content to extactedFileContent - extactedFileContent = fileContent.ToString(); - - //extract tags as a Json file - var destFile = $"{uploadedFile.Name}.tags.json"; - - var chat = this._kernel.GetRequiredService(); - var chatHistory = new ChatHistory(); - - chatHistory.AddSystemMessage(this._extractKeywordPrompt); - chatHistory.AddUserMessage($"Extract tags from this content : {extactedFileContent} \n The format should be Json but Markdown expression."); - - var executionParam = new PromptExecutionSettings() - { - ExtensionData = new Dictionary - { - { "Temperature", 0 } - } - }; - - ChatMessageContent response = null; - - try - { - response = await chat.GetChatMessageContentAsync(chatHistory: chatHistory, executionSettings: executionParam, cancellationToken: cancellationToken).ConfigureAwait(true); - - //Make BinaryData from response - BinaryData responseBinaryData = new(response.ToString()); - await this._orchestrator.WriteFileAsync(pipeline, destFile, responseBinaryData, cancellationToken).ConfigureAwait(false); - - //Add Tags from Extracted Keywords - List>> tags = JsonSerializer.Deserialize>>>(response.ToString()); - - Dictionary> keyValueCollection = new Dictionary>(); - - foreach (var category in tags) - { - foreach (var kvp in category) - { - pipeline.Tags.Add(kvp.Key, kvp.Value); - } - } - } - catch (Exception ex) - { - this._log.LogError(ex, "Error while extracting tags from the file {FileName}", file.Name); - await this._orchestrator.WriteFileAsync(pipeline, destFile, new BinaryData("[]"), cancellationToken).ConfigureAwait(false); - continue; - } - } - } - uploadedFile.MarkProcessedBy(this); - } - - return (true, pipeline); - } - -} - From 60fc9c87fbcfb455b38750d81e47ff196ca30c6b Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 21:00:42 +0530 Subject: [PATCH 31/43] Delete App/kernel-memory/service/Core/Prompts/extract-keywords.txt --- .../service/Core/Prompts/extract-keywords.txt | 25 ------------------- 1 file changed, 25 deletions(-) delete mode 100644 App/kernel-memory/service/Core/Prompts/extract-keywords.txt diff --git a/App/kernel-memory/service/Core/Prompts/extract-keywords.txt b/App/kernel-memory/service/Core/Prompts/extract-keywords.txt deleted file mode 100644 index 9dd6485c..00000000 --- a/App/kernel-memory/service/Core/Prompts/extract-keywords.txt +++ /dev/null @@ -1,25 +0,0 @@ -You are an assistant to analyze Content and Extract Tags by Content. -[EXTRACT TAGS RULES] -IT SHOULD BE A LIST OF DICTIONARIES WITH CATEGORY AND TAGS -TAGS SHOULD BE CATEGORY SPECIFIC -TAGS SHOULD BE A LIST OF STRINGS -TAGS COUNT CAN BE UP TO 10 UNDER A CATEGORY -CATEGORY COUNT CAN BE UP TO 10 -DON'T ADD ANY MARKDOWN EXPRESSION IN YOUR RESPONSE -[END RULES] -[EXAMPLE] -[ - { - "category1": ["tag1", "tag2", "tag3"] - }, - { - "category2": ["tag1", "tag2", "tag3"] - } -] -[END EXAMPLE] - -Extract Tags from this : -{{$input}} - - - From f335f7e0399ddcb4c6e3ce90f3109104f2dd1459 Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 21:05:48 +0530 Subject: [PATCH 32/43] Create Constants.cs --- .../service/Abstractions/Constants.cs | 166 ++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 App/kernel-memory/service/Abstractions/Constants.cs diff --git a/App/kernel-memory/service/Abstractions/Constants.cs b/App/kernel-memory/service/Abstractions/Constants.cs new file mode 100644 index 00000000..772786bd --- /dev/null +++ b/App/kernel-memory/service/Abstractions/Constants.cs @@ -0,0 +1,166 @@ +// Copyright (c) Microsoft. All rights reserved. + +namespace Microsoft.KernelMemory; + +public static class Constants +{ + public static class WebService + { + // Form field/Query param containing the Index Name + public const string IndexField = "index"; + + // Form field/Query param containing the Document ID + public const string DocumentIdField = "documentId"; + + // Form field/Query param containing the Filename + public const string FilenameField = "filename"; + + // Form field containing the list of tags + public const string TagsField = "tags"; + + // Form field containing the list of pipeline steps + public const string StepsField = "steps"; + + // Form field containing the optional arguments JSON string + public const string ArgsField = "args"; + } + + public static class CustomContext + { + public static class Partitioning + { + // Used to override MaxTokensPerParagraph config + public const string MaxTokensPerParagraph = "custom_partitioning_max_tokens_per_paragraph_int"; + + // Used to override OverlappingTokens config + public const string OverlappingTokens = "custom_partitioning_overlapping_tokens_int"; + + // Used to prepend header to each partition + public const string ChunkHeader = "custom_partitioning_chunk_header_str"; + } + + public static class EmbeddingGeneration + { + // Used to override MaxBatchSize embedding generators config + public const string BatchSize = "custom_embedding_generation_batch_size_int"; + } + + public static class Rag + + { + // Used to override No Answer config + public const string EmptyAnswer = "custom_rag_empty_answer_str"; + + // Used to override the RAG prompt + public const string Prompt = "custom_rag_prompt_str"; + + // Used to override how facts are injected into RAG prompt + public const string FactTemplate = "custom_rag_fact_template_str"; + + // Used to override the max tokens to generate when using the RAG prompt + public const string MaxTokens = "custom_rag_max_tokens_int"; + + // Used to override the temperature (default 0) used with the RAG prompt + public const string Temperature = "custom_rag_temperature_float"; + + // Used to override the nucleus sampling probability (default 0) used with the RAG prompt + public const string NucleusSampling = "custom_rag_nucleus_sampling_float"; + } + + public static class Summary + { + // Used to override the summarization prompt + public const string Prompt = "custom_summary_prompt_str"; + + // Used to override the size of the summary + public const string TargetTokenSize = "custom_summary_target_token_size_int"; + + // Used to override the number of overlapping tokens + public const string OverlappingTokens = "custom_summary_overlapping_tokens_int"; + } + } + + // // Default User ID owning documents uploaded without specifying a user + // public const string DefaultDocumentOwnerUserId = "defaultUser"; + + // Internal file used to track progress of asynchronous pipelines + public const string PipelineStatusFilename = "__pipeline_status.json"; + + // Tags settings + public const char ReservedEqualsChar = ':'; + public const string ReservedTagsPrefix = "__"; + + // Tags reserved for internal logic + public const string ReservedDocumentIdTag = $"{ReservedTagsPrefix}document_id"; + public const string ReservedFileIdTag = $"{ReservedTagsPrefix}file_id"; + public const string ReservedFilePartitionTag = $"{ReservedTagsPrefix}file_part"; + public const string ReservedFilePartitionNumberTag = $"{ReservedTagsPrefix}part_n"; + public const string ReservedFileSectionNumberTag = $"{ReservedTagsPrefix}sect_n"; + public const string ReservedFileTypeTag = $"{ReservedTagsPrefix}file_type"; + public const string ReservedSyntheticTypeTag = $"{ReservedTagsPrefix}synth"; + + // Known tags + public const string TagsSyntheticSummary = "summary"; + + // Properties stored inside the payload + public const string ReservedPayloadSchemaVersionField = "schema"; + public const string ReservedPayloadTextField = "text"; + public const string ReservedPayloadFileNameField = "file"; + public const string ReservedPayloadUrlField = "url"; + public const string ReservedPayloadLastUpdateField = "last_update"; + public const string ReservedPayloadVectorProviderField = "vector_provider"; + public const string ReservedPayloadVectorGeneratorField = "vector_generator"; + + // Endpoints + public const string HttpAskEndpoint = "/ask"; + public const string HttpSearchEndpoint = "/search"; + public const string HttpDownloadEndpoint = "/download"; + public const string HttpUploadEndpoint = "/upload"; + public const string HttpUploadStatusEndpoint = "/upload-status"; + public const string HttpDocumentsEndpoint = "/documents"; + public const string HttpIndexesEndpoint = "/indexes"; + public const string HttpDeleteDocumentEndpointWithParams = $"{HttpDocumentsEndpoint}?{WebService.IndexField}={HttpIndexPlaceholder}&{WebService.DocumentIdField}={HttpDocumentIdPlaceholder}"; + public const string HttpDeleteIndexEndpointWithParams = $"{HttpIndexesEndpoint}?{WebService.IndexField}={HttpIndexPlaceholder}"; + public const string HttpUploadStatusEndpointWithParams = $"{HttpUploadStatusEndpoint}?{WebService.IndexField}={HttpIndexPlaceholder}&{WebService.DocumentIdField}={HttpDocumentIdPlaceholder}"; + public const string HttpDownloadEndpointWithParams = $"{HttpDownloadEndpoint}?{WebService.IndexField}={HttpIndexPlaceholder}&{WebService.DocumentIdField}={HttpDocumentIdPlaceholder}&{WebService.FilenameField}={HttpFilenamePlaceholder}"; + public const string HttpIndexPlaceholder = "{index}"; + public const string HttpDocumentIdPlaceholder = "{documentId}"; + public const string HttpFilenamePlaceholder = "{filename}"; + + // Pipeline Handlers, Step names + public const string PipelineStepsExtract = "extract"; + public const string PipelineStepsPartition = "partition"; + public const string PipelineStepsGenEmbeddings = "gen_embeddings"; + public const string PipelineStepsSaveRecords = "save_records"; + public const string PipelineStepsSummarize = "summarize"; + public const string PipelineStepsDeleteGeneratedFiles = "delete_generated_files"; + public const string PipelineStepsDeleteDocument = "private_delete_document"; + public const string PipelineStepsDeleteIndex = "private_delete_index"; + public const string PipelineStepsKeywordExtraction = "keyword_extraction"; + + // Pipeline steps + public static readonly string[] DefaultPipeline = + { + PipelineStepsExtract, PipelineStepsPartition, PipelineStepsGenEmbeddings, PipelineStepsSaveRecords + }; + + public static readonly string[] PipelineWithoutSummary = + { + PipelineStepsExtract, PipelineStepsPartition, PipelineStepsGenEmbeddings, PipelineStepsSaveRecords + }; + + public static readonly string[] PipelineWithSummary = + { + PipelineStepsExtract, PipelineStepsPartition, PipelineStepsGenEmbeddings, PipelineStepsSaveRecords, + PipelineStepsSummarize, PipelineStepsGenEmbeddings, PipelineStepsSaveRecords + }; + + public static readonly string[] PipelineOnlySummary = + { + PipelineStepsExtract, PipelineStepsSummarize, PipelineStepsGenEmbeddings, PipelineStepsSaveRecords + }; + + // Standard prompt names + public const string PromptNamesSummarize = "summarize"; + public const string PromptNamesAnswerWithFacts = "answer-with-facts"; +} From 5906ef27965b08252066584f7036033ac60dc49b Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 21:07:16 +0530 Subject: [PATCH 33/43] Update Constants.cs --- App/kernel-memory/service/Abstractions/Constants.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/App/kernel-memory/service/Abstractions/Constants.cs b/App/kernel-memory/service/Abstractions/Constants.cs index 772786bd..53d5535e 100644 --- a/App/kernel-memory/service/Abstractions/Constants.cs +++ b/App/kernel-memory/service/Abstractions/Constants.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft. All rights reserved. +// Copyright (c) Microsoft. All rights reserved. namespace Microsoft.KernelMemory; From a25adacad3c63b40def102ac449d2189dbb12949 Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 21:09:58 +0530 Subject: [PATCH 34/43] Create Core.csproj --- App/kernel-memory/service/Core/Core.csproj | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 App/kernel-memory/service/Core/Core.csproj diff --git a/App/kernel-memory/service/Core/Core.csproj b/App/kernel-memory/service/Core/Core.csproj new file mode 100644 index 00000000..71cec67b --- /dev/null +++ b/App/kernel-memory/service/Core/Core.csproj @@ -0,0 +1,65 @@ + + + + net8.0 + LatestMajor + Microsoft.KernelMemory.Core + Microsoft.KernelMemory + $(NoWarn);KMEXP00;KMEXP01;KMEXP02;KMEXP03;KMEXP04;SKEXP0001;SKEXP0011;CA2208;CA1308;CA1724; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + Microsoft.KernelMemory.Core + Kernel Memory library, including extensions and Serverless and Web client + The package contains all the core logic and extensions of Kernel Memory, to index and query any data and documents, using LLM and natural language, tracking sources and showing citations. + Copilot, Plugin, Memory, RAG, Kernel Memory, Semantic Memory, Episodic Memory, Declarative Memory, AI, Artificial Intelligence, Embeddings, Vector DB, Vector Search, Memory DB, ETL + bin/$(Configuration)/$(TargetFramework)/$(AssemblyName).xml + + + + + + + From 7b717aa8e99145cc671a80e88bbc301943c491e6 Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 21:11:35 +0530 Subject: [PATCH 35/43] Create KeywordExtractingHandler.cs --- .../service/Core/KeywordExtractingHandler.cs | 153 ++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 App/kernel-memory/service/Core/KeywordExtractingHandler.cs diff --git a/App/kernel-memory/service/Core/KeywordExtractingHandler.cs b/App/kernel-memory/service/Core/KeywordExtractingHandler.cs new file mode 100644 index 00000000..92fbeb09 --- /dev/null +++ b/App/kernel-memory/service/Core/KeywordExtractingHandler.cs @@ -0,0 +1,153 @@ +// Copyright (c) Microsoft. All rights reserved. + +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Microsoft.KernelMemory.Diagnostics; +using Microsoft.KernelMemory.Pipeline; +using Microsoft.SemanticKernel; +using Microsoft.SemanticKernel.ChatCompletion; +using static Microsoft.KernelMemory.Pipeline.DataPipeline; + +namespace Microsoft.KernelMemory.Handlers; + +public sealed class KeywordExtractingHandler : IPipelineStepHandler +{ + public string StepName { get; } + private readonly ILogger _log; + private readonly IPipelineOrchestrator _orchestrator; + private readonly Kernel _kernel; + private readonly KernelMemoryConfig? _config = null; + + public KeywordExtractingHandler( + string stepName, + IPipelineOrchestrator orchestrator, + KernelMemoryConfig config = null, + ILoggerFactory? loggerFactory = null + ) + { + this.StepName = stepName; + this._log = (loggerFactory ?? DefaultLogger.Factory).CreateLogger(); + this._orchestrator = orchestrator; + this._config = config; + + //init Semantic Kernel + this._kernel = Kernel.CreateBuilder() + .AddAzureOpenAIChatCompletion(deploymentName: (string)this._config.Services["AzureOpenAIText"]["Deployment"], + endpoint: (string)this._config.Services["AzureOpenAIText"]["Endpoint"], + apiKey: (string)this._config.Services["AzureOpenAIText"]["APIKey"]) + .Build(); + } + + public async Task<(bool success, DataPipeline updatedPipeline)> InvokeAsync(DataPipeline pipeline, CancellationToken cancellationToken = default) + { + this._log.LogDebug("Extracting Keywords from the content", pipeline.Index, pipeline.DocumentId); + + foreach (FileDetails uploadedFile in pipeline.Files) + { + Dictionary extractedTagsFile = new(); + + foreach (KeyValuePair generatedFile in uploadedFile.GeneratedFiles) + { + var file = generatedFile.Value; + + if (file.AlreadyProcessedBy(this)) + { + this._log.LogDebug("File {FileName} has already been processed by {HandlerName}", file.Name, this.StepName); + continue; + } + + // Extract keywords from the file + if (file.ArtifactType == DataPipeline.ArtifactTypes.ExtractedText) + { + this._log.LogDebug("Extracting Tags from the file {FileName}", file.Name); + + var sourceFile = uploadedFile.Name; + string extactedFileContent = string.Empty; + + BinaryData fileContent = await this._orchestrator.ReadFileAsync(pipeline, file.Name, cancellationToken).ConfigureAwait(false); + + //set file content to extactedFileContent + extactedFileContent = fileContent.ToString(); + + //extract tags as a Json file + var destFile = $"{uploadedFile.Name}.tags.json"; + + var chat = this._kernel.GetRequiredService(); + var chatHistory = new ChatHistory(); + + var systemMessage = """ + You are an assistant to analyze Content and Extract Tags by Content. + [EXTRACT TAGS RULES] + IT SHOULD BE A LIST OF DICTIONARIES WITH CATEGORY AND TAGS + TAGS SHOULD BE CATEGORY SPECIFIC + TAGS SHOULD BE A LIST OF STRINGS + TAGS COUNT CAN BE UP TO 10 UNDER A CATEGORY + CATEGORY COUNT CAN BE UP TO 10 + DON'T ADD ANY MARKDOWN EXPRESSION IN YOUR RESPONSE + [END RULES] + + [EXAMPLE] + [ + { + [category1": ["tag1", "tag2", "tag3"] + }, + { + "category2": ["tag1", "tag2", "tag3"] + } + ] + [END EXAMPLE] + """; + + chatHistory.AddSystemMessage(systemMessage); + chatHistory.AddUserMessage($"Extract tags from this content : {extactedFileContent} \n The format should be Json but Markdown expression."); + + var executionParam = new PromptExecutionSettings() + { + ExtensionData = new Dictionary + { + { "Temperature", 0 } + } + }; + + ChatMessageContent response = null; + + try + { + response = await chat.GetChatMessageContentAsync(chatHistory: chatHistory, executionSettings: executionParam, cancellationToken: cancellationToken).ConfigureAwait(true); + + //Make BinaryData from response + BinaryData responseBinaryData = new(response.ToString()); + await this._orchestrator.WriteFileAsync(pipeline, destFile, responseBinaryData, cancellationToken).ConfigureAwait(false); + + //Add Tags from Extracted Keywords + List>> tags = JsonSerializer.Deserialize>>>(response.ToString()); + + Dictionary> keyValueCollection = new Dictionary>(); + + foreach (var category in tags) + { + foreach (var kvp in category) + { + pipeline.Tags.Add(kvp.Key, kvp.Value); + } + } + } + catch (Exception ex) + { + this._log.LogError(ex, "Error while extracting tags from the file {FileName}", file.Name); + await this._orchestrator.WriteFileAsync(pipeline, destFile, new BinaryData("[]"), cancellationToken).ConfigureAwait(false); + continue; + } + } + } + uploadedFile.MarkProcessedBy(this); + } + + return (true, pipeline); + } + +} From e2e7a6e66201969898da652544430365bfa0721d Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 21:14:51 +0530 Subject: [PATCH 36/43] Rename App/kernel-memory/service/Core/KeywordExtractingHandler.cs to App/kernel-memory/service/Core/Handlers/KeywordExtractingHandler.cs --- .../service/Core/{ => Handlers}/KeywordExtractingHandler.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename App/kernel-memory/service/Core/{ => Handlers}/KeywordExtractingHandler.cs (100%) diff --git a/App/kernel-memory/service/Core/KeywordExtractingHandler.cs b/App/kernel-memory/service/Core/Handlers/KeywordExtractingHandler.cs similarity index 100% rename from App/kernel-memory/service/Core/KeywordExtractingHandler.cs rename to App/kernel-memory/service/Core/Handlers/KeywordExtractingHandler.cs From 75893385423bea15c25104b51da0c693a8216a67 Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 21:17:04 +0530 Subject: [PATCH 37/43] Update KeywordExtractingHandler.cs From 8444b794a4539ad1b4736bdb23a3d77a4269162c Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 21:17:54 +0530 Subject: [PATCH 38/43] Update KeywordExtractingHandler.cs --- .../service/Core/Handlers/KeywordExtractingHandler.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/App/kernel-memory/service/Core/Handlers/KeywordExtractingHandler.cs b/App/kernel-memory/service/Core/Handlers/KeywordExtractingHandler.cs index 92fbeb09..b5f95c9b 100644 --- a/App/kernel-memory/service/Core/Handlers/KeywordExtractingHandler.cs +++ b/App/kernel-memory/service/Core/Handlers/KeywordExtractingHandler.cs @@ -151,3 +151,4 @@ [END EXAMPLE] } } + From b9b2d2d1f708e3285aedd9b771e6586f4a138430 Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 21:19:20 +0530 Subject: [PATCH 39/43] Create extract-keywords.txt --- .../service/Core/Prompts/extract-keywords.txt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 App/kernel-memory/service/Core/Prompts/extract-keywords.txt diff --git a/App/kernel-memory/service/Core/Prompts/extract-keywords.txt b/App/kernel-memory/service/Core/Prompts/extract-keywords.txt new file mode 100644 index 00000000..72a3e9b8 --- /dev/null +++ b/App/kernel-memory/service/Core/Prompts/extract-keywords.txt @@ -0,0 +1,21 @@ +[EXTRACT KEYWORDS RULES] +IT SHOULD BE A LIST OF DICTIONARIES WITH CATEGORY AND KEYWORDS +KEYWORDS SHOULD BE CATEGORY SPECIFIC +KEYWORDS SHOULD BE A LIST OF STRINGS +KEYWORDS COUNT CAN BE UP TO 50 +CATEGORY COUNT CAN BE UP TO 10 +[END RULES] + +[EXAMPLE] +[ + { + "category1": ["keyword1", "keyword2", "keyword3"] + }, + { + "category2": ["keyword1", "keyword2", "keyword3"] + } +] +[END EXAMPLE] + +Extract Keywords from this : +{{$input}} From 8ef238bbc95d1c4bd9aa1c09bdb8f183d2c66fc6 Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 21:20:53 +0530 Subject: [PATCH 40/43] Update extract-keywords.txt --- App/kernel-memory/service/Core/Prompts/extract-keywords.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/App/kernel-memory/service/Core/Prompts/extract-keywords.txt b/App/kernel-memory/service/Core/Prompts/extract-keywords.txt index 72a3e9b8..52366785 100644 --- a/App/kernel-memory/service/Core/Prompts/extract-keywords.txt +++ b/App/kernel-memory/service/Core/Prompts/extract-keywords.txt @@ -1,4 +1,4 @@ -[EXTRACT KEYWORDS RULES] +[EXTRACT KEYWORDS RULES] IT SHOULD BE A LIST OF DICTIONARIES WITH CATEGORY AND KEYWORDS KEYWORDS SHOULD BE CATEGORY SPECIFIC KEYWORDS SHOULD BE A LIST OF STRINGS From a3f6cf0f4fcf3319e03ed6aaff312e6d5953a044 Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 21:23:14 +0530 Subject: [PATCH 41/43] Update extract-keywords.txt --- App/kernel-memory/service/Core/Prompts/extract-keywords.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/App/kernel-memory/service/Core/Prompts/extract-keywords.txt b/App/kernel-memory/service/Core/Prompts/extract-keywords.txt index 52366785..72a3e9b8 100644 --- a/App/kernel-memory/service/Core/Prompts/extract-keywords.txt +++ b/App/kernel-memory/service/Core/Prompts/extract-keywords.txt @@ -1,4 +1,4 @@ -[EXTRACT KEYWORDS RULES] +[EXTRACT KEYWORDS RULES] IT SHOULD BE A LIST OF DICTIONARIES WITH CATEGORY AND KEYWORDS KEYWORDS SHOULD BE CATEGORY SPECIFIC KEYWORDS SHOULD BE A LIST OF STRINGS From 541a526c7737c55881048908421aad028bdd9983 Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 21:24:03 +0530 Subject: [PATCH 42/43] Update extract-keywords.txt From 7098856de551b32b54e2665ff74839c2b621d4bd Mon Sep 17 00:00:00 2001 From: Harmanpreet-Microsoft Date: Thu, 2 Jan 2025 21:25:35 +0530 Subject: [PATCH 43/43] Update extract-keywords.txt