{"id":13561266,"url":"https://github.com/goodtocode/semantickernel-microservice","last_synced_at":"2025-09-21T00:58:52.150Z","repository":{"id":243586527,"uuid":"812824377","full_name":"goodtocode/semantickernel-microservice","owner":"goodtocode","description":"A Clean Architecture microservice based on Microsoft Semantic Kernel. Provides language models from OpenAI, AzureOpenAI, and Hugging Face. Enables developers to store and retrieve memories, add plugins, create dynamic prompts, and combine functions with planners.","archived":false,"fork":false,"pushed_at":"2025-09-17T00:10:19.000Z","size":1621,"stargazers_count":13,"open_issues_count":16,"forks_count":6,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-17T01:32:30.635Z","etag":null,"topics":["clean-architecture","csharp","dotnet","microservices","semantic-kernel"],"latest_commit_sha":null,"homepage":"https://www.goodtocode.com","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goodtocode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-06-10T00:43:29.000Z","updated_at":"2025-09-17T00:10:21.000Z","dependencies_parsed_at":"2024-11-04T13:36:35.558Z","dependency_job_id":"e7444772-369f-4430-a315-391483411758","html_url":"https://github.com/goodtocode/semantickernel-microservice","commit_stats":{"total_commits":27,"total_committers":1,"mean_commits":27.0,"dds":0.0,"last_synced_commit":"7c2a8f1785197f5bd77499505b79a23458a24e7f"},"previous_names":["goodtocode/semantickernel-microservice"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/goodtocode/semantickernel-microservice","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodtocode%2Fsemantickernel-microservice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodtocode%2Fsemantickernel-microservice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodtocode%2Fsemantickernel-microservice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodtocode%2Fsemantickernel-microservice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goodtocode","download_url":"https://codeload.github.com/goodtocode/semantickernel-microservice/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodtocode%2Fsemantickernel-microservice/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276179897,"owners_count":25598571,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-20T02:00:10.207Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clean-architecture","csharp","dotnet","microservices","semantic-kernel"],"created_at":"2024-08-01T13:00:54.293Z","updated_at":"2025-09-21T00:58:52.140Z","avatar_url":"https://github.com/goodtocode.png","language":"C#","readme":"# Semantic Kernel C# Microservice Quick-Start\n**Azure Bicep Infrastucture**\n\n[![.github/workflows/gtc-rg-semkernel-iac.yml](https://github.com/goodtocode/semantickernel-microservice/actions/workflows/gtc-rg-semkernel-iac.yml/badge.svg)](https://github.com/goodtocode/semantickernel-microservice/actions/workflows/gtc-rg-semkernel-iac.yml)\n\n**Clean Architecture C# Microservice**\n\n[![.github/workflows/gtc-rg-semkernel-api-ci-cd.yml](https://github.com/goodtocode/semantickernel-microservice/actions/workflows/gtc-rg-semkernel-api-ci-cd.yml/badge.svg)](https://github.com/goodtocode/semantickernel-microservice/actions/workflows/gtc-rg-semkernel-api-ci-cd.yml)\n\nSemantic Kernel Quick-start is a .NET Web API CRUD Microservice solution with Blazor Copilot-ish Chat client that demonstrates the most basic use cases of the Microsoft Semantic Kernel in a Clean Architecture C# Microservice. This microservice allows you to persist the following Azure Open AI services to SQL Server, so you can replay messages and maintain history of your interaction with AI. \n\n![Semantic Kernel Quick-start Blazor](./docs/SemanticKernel-Quick-start-Blazor-Side-by-Side.png)\n\nSemantic Kernel is an SDK that integrates Large Language Models (LLMs) like OpenAI, Azure OpenAI, and Hugging Face with conventional programming languages like C#, Python, and Java. Semantic Kernel allows developers to define plugins that can be chained together in just a few lines of code.\n\n[Introduction to Semantic Kernel](https://learn.microsoft.com/en-us/semantic-kernel/overview/)\n\n[Getting Started with Semantic Kernel](https://learn.microsoft.com/en-us/semantic-kernel/get-started/quick-start-guide?pivots=programming-language-csharp)\n\nThis microservice supports:\n* Chat Completions: Generate responses based on user input, making it useful for chatbots and virtual assistants.\n* Text to Speech: Convert text into natural-sounding speech, enhancing user experiences.\n* Whisper (Text to Speech): Convert spoken language into text, useful for transcription and voice recognition.\n* Image to Text: Generate descriptions of an image.\n* Text to Image: Create an image based on a description prompt of the desired imagery.\n\nUpcoming relases will support more Semantic Kernel and Azure Open AI functionality such as:\n* Embeddings: Create vector representations of text, which can be used for semantic search and similarity matching.\n* Function Calling: Integrate custom functions into your AI models, allowing the model to call external APIs or perform specific tasks based on the context of the conversation.\n* Content Filtering: Automatically filter out inappropriate or harmful content from generated responses.\n* Fine-Tuning: Train models on your specific data to better align with your use cases and improve performance.\n* Assistants: Create and manage virtual assistants that can handle complex tasks and interactions.\n* Semantic Search: Perform searches based on the meaning of the text rather than just keywords, improving search relevance.\n\n# Getting-Started in 4 Steps\nTo get started, follow the steps below:\n1. Clone this repository\n\t```\n\tgit clone https://github.com/goodtocode/semantickernel-microservice.git\n\t```\n2. Install Prerequisites\n\t```\n\twinget install Microsoft.DotNet.SDK.9 --silent\n\t```\n\t```\n\tdotnet tool install --global dotnet-ef\n\t```\n3. Add your Open AI or Azure Open AI key to configuration (via *dotnet user-secrets set* command)\n\t```\n\tcd src/Presentation.WebAPI\n\tdotnet user-secrets set \"OpenAI:ApiKey\" \"YOUR_API_KEY\"\n\t```\n\t```\n\tcd ../Tests.Specs.Integration\n\tdotnet user-secrets set \"OpenAI:ApiKey\" \"YOUR_API_KEY\"\n\t```\n4. Create your SQL Server database \u0026 schema (via *dotnet ef* command)\n\t```\n\tcd ../../\n\tdotnet ef database update --project .\\src\\Infrastructure.SqlServer\\Infrastructure.SqlServer.csproj --startup-project .\\src\\Presentation.WebApi\\Presentation.WebApi.csproj --context SemanticKernelContext --connection \"Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=SemanticKernelMicroservice;Min Pool Size=3;MultipleActiveResultSets=True;Trusted_Connection=Yes;TrustServerCertificate=True;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30\"\n\t```\n5. Run Tests (Tests.Specs.Integration)\n\t```\n\tcd src/Tests.Specs.Integration\n\tdotnet test\n\t```\n6. Run Blazor Web Chat Client (Presentation.Blazor) and Web API (Presentation.WebApi)\n\t```\n\tcd ../\n\tdotnet run --project Presentation.WebApi/Presentation.WebApi.csproj\n\tdotnet run --project Presentation.Blazor/Presentation.Blazor.csproj\n\t```\n\n# Install Prerequisites\nYou will need the following tools:\n## Visual Studio\n[Visual Studio Workload IDs](https://learn.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-community?view=vs-2022\u0026preserve-view=true)\n```\nwinget install --id Microsoft.VisualStudio.2022.Community --override \"--quiet --add Microsoft.Visualstudio.Workload.Azure --add Microsoft.VisualStudio.Workload.Data --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.Workload.NetWeb\"\n```\n\n## .NET SDK\n```\nwinget install Microsoft.DotNet.SDK.9 --silent\n```\n\n## dotnet ef cli\nInstall\n```\ndotnet tool install --global dotnet-ef\n```\n\n## SQL Server\nVisual Studio installs SQL Express. If you want full-featured SQL Server, install the SQL Server Developer Edition or above.\n\n[SQL Server Developer Edition or above](https://www.microsoft.com/en-us/sql-server/sql-server-downloads)\n\n# Configure API Key and Connection String\nFollow these steps to get your development environment set up:\n\n## ASPNETCORE_ENVIRONMENT set to \"Local\" in launchsettings.json\n1. This project uses the following ASPNETCORE_ENVIRONMENT to set configuration profile\n- Debugging uses Properties/launchSettings.json\n- launchSettings.json is set to Local, which relies on appsettings.Local.json\n2. As a standard practice, set ASPNETCORE_ENVIRONMENT entry in your Enviornment Variables and restart Visual Studio\n\t```\n\tSet-Item -Path Env:ASPNETCORE_ENVIRONMENT -Value \"Development\"\n\tGet-Childitem env:\n\t```\t\n  \n## Setup Azure Open AI or Open AI configuration\n**Important:** Do this for both Presentation.WebAPI and Specs.Infrastructure\n### Azure Open AI\n```\ncd src/Presentation.WebAPI\ndotnet user-secrets set \"AzureOpenAI:ChatDeploymentName\" \"gpt-4\"\ndotnet user-secrets set \"AzureOpenAI:Endpoint\" \"https://YOUR_ENDPOINT.openai.azure.com/\"\ndotnet user-secrets set \"AzureOpenAI:ApiKey\" \"YOUR_API_KEY\"\ncd src/Tests.Specs.Integration\ndotnet user-secrets set \"AzureOpenAI:ChatDeploymentName\" \"gpt-4\"\ndotnet user-secrets set \"AzureOpenAI:Endpoint\" \"https://YOUR_ENDPOINT.openai.azure.com/\"\ndotnet user-secrets set \"AzureOpenAI:ApiKey\" \"YOUR_API_KEY\"\n```\nAlternately you can set in Environment variables\n```\nAzureOpenAI__ChatDeploymentName\nAzureOpenAI__Endpoint\nAzureOpenAI__ApiKey\n```\n\n### Open AI\nSet API Key in both Presention.WebAPI and Tests/Specs.Integration projects\n```\ncd src/Presentation.WebAPI\ndotnet user-secrets set \"OpenAI:ApiKey\" \"YOUR_API_KEY\"\ncd ../Tests.Specs.Integration\ndotnet user-secrets set \"OpenAI:ApiKey\" \"YOUR_API_KEY\"\n```\nAlternately you can set in Environment variables\n```\nOpenAI__ChatModelId\t\nOpenAI__ApiKey\n```\n\n## Setup your SQL Server connection string\n```\ndotnet user-secrets init\ndotnet user-secrets set \"ConnectionStrings:DefaultConnection\" \"YOUR_SQL_CONNECTION_STRING\"\n```\n# Create SQL Server Database\n## dotnet ef migrate steps\n\n1. Open Windows Terminal in Powershell or Cmd mode\n2. cd to root of repository\n3. (Optional) If you have an existing database, scaffold current entities into your project\n\t\n\t```\n\tdotnet ef dbcontext scaffold \"Data Source=localhost;Initial Catalog=semantickernelmicroservice;Min Pool Size=3;MultipleActiveResultSets=True;Trusted_Connection=Yes;TrustServerCertificate=True;\" Microsoft.EntityFrameworkCore.SqlServer -t WeatherForecastView -c WeatherChannelContext -f -o WebApi\n\t```\n\n4. Create an initial migration\n\t```\n\tdotnet ef migrations add InitialCreate --project .\\src\\Infrastructure.SqlServer\\Infrastructure.SqlServer.csproj --startup-project .\\src\\Presentation.WebApi\\Presentation.WebApi.csproj --context SemanticKernelContext\n\t```\n\n5. Develop new entities and configurations\n6. When ready to deploy new entities and configurations\n   \n\t```\t\n\tdotnet ef database update --project .\\src\\Infrastructure.SqlServer\\Infrastructure.SqlServer.csproj --startup-project .\\src\\Presentation.WebApi\\Presentation.WebApi.csproj --context SemanticKernelContext --connection \"Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=SemanticKernelMicroservice;Min Pool Size=3;MultipleActiveResultSets=True;Trusted_Connection=Yes;TrustServerCertificate=True;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30\"\n\t```\n7. When an entity changes, is created or deleted, create a new migration. Suggest doing this each new version.\n\t```\n\tdotnet ef migrations add v1.1.1 --project .\\src\\Infrastructure.SqlServer\\Infrastructure.SqlServer.csproj --startup-project .\\src\\Presentation.WebApi\\Presentation.WebApi.csproj --context SemanticKernelContext\n\t```\n# Running the Application\n## Launch the backend\nRight-click Presentation.WebApi and select Set as Default Project\n```\ndotnet run Presentation.WebApi.csproj\n```\n\n## Open http://localhost:7777/swagger/index.html \nOpen Microsoft Edge or modern browser\nNavigate to: http://localhost:7777/swagger/index.html in your browser to the Swagger API Interface\n\n\n# DevOps Configuration for Azure IaC and CI/CD\n## GitHub Actions (.github folder)\nThe GitHub action will automatically run upon commit to a repo. The triggers are set based on changes (PRs/Merges) to the main branch.\n\n### Azure Federation to GitHub Actions\ngtc-rg-semantickernel-infrastructure.yml will deploy all necessary resources to Azure. To enable this functionality, two service principles are required: App Registration service principle (used for az login command) and a Enterprise Application service principle (allows GitHub to authenticate to Azure).\n#### Git Hub Environment Secret setup and Azure IAM privileges: \nNote: The AZURE_SECRETS method uses: az ad sp create-for-rbac --name \"COMPANY-SUB_OR_PRODUCTLINE-github-001\" --role contributor --scopes /subscriptions/SUBSCRIPTION_ID --json-auth\n\n[New-AzureGitHubFederation.ps1](https://github.com/goodtocode/cloud-admin/blob/main/scripts/cybersecurity/Azure-GitHub-Federation/New-AzureGitHubFederation.ps1)\n```\nInstall-Module Az #-Force #Force will update the module if it is already installed\n\nConnect-AzAccount -SubscriptionId $SubscriptionId -UseDeviceAuthentication\n```\n```\n# Create a new Azure AD App Registration application and service principal\n$existingAppRegistration = Get-AzADApplication -Filter \"displayName eq '$PrincipalName'\"\nif (-not $existingAppRegistration) {\n    New-AzADApplication -DisplayName $PrincipalName\n}\n$clientId = (Get-AzADApplication -DisplayName $PrincipalName).AppId\n\nNew-AzADServicePrincipal -ApplicationId $clientId\n$objectId = (Get-AzADServicePrincipal -DisplayName $PrincipalName).Id\n\nNew-AzRoleAssignment -ObjectId $objectId -RoleDefinitionName Contributor -Scope \"/subscriptions/$SubscriptionId\"\n$clientId = (Get-AzADApplication -DisplayName $PrincipalName).AppId\n$tenantId = (Get-AzContext).Subscription.TenantId\n```\n```\n# Create new App Registration Federated Credentials for the GitHub operations\n$subjectRepo = $subjectRepo = \"repo:\" + $Organization + \"/\" + $Repository + \":environment:\" + $Environment\n\nNew-AzADAppFederatedCredential -ApplicationObjectId $objectId -Audience api://AzureADTokenExchange -Issuer 'https://token.actions.githubusercontent.com' -Name \"$PrincipalName-repo\" -Subject \"$subjectRepo\"\n$subjectRepoMain = \"repo:\" + $Organization + \"/\" + $Repository + \":ref:refs/heads/main\"\n\nNew-AzADAppFederatedCredential -ApplicationObjectId $objectId -Audience api://AzureADTokenExchange -Issuer 'https://token.actions.githubusercontent.com' -Name \"$PrincipalName-main\" -Subject \"$subjectRepoMain\"\n$subjectRepoPR = \"repo:\" + $Organization + \"/\" + $Repository + \":pull_request\"\n\nNew-AzADAppFederatedCredential -ApplicationObjectId $objectId -Audience api://AzureADTokenExchange -Issuer 'https://token.actions.githubusercontent.com' -Name \"$PrincipalName-PR\" -Subject \"$subjectRepoPR\"\n```\nIn GitHub repo environment: Add the az login secrets: \n- AZURE_CLIENT_ID\n- AZURE_TENANT_ID\n- AZURE_SUBSCRIPTION_ID\n\n## Azure DevOps Pipelines (.azure-devops folder)\nAzure DevOps pipelines require an Azure Service Connection to authenticate and deploy resources to Azure.\n\n# Entity Framework vs. Semantic Kernel Memory\nThis example uses Entity Framework (EF) to store messages and responses for Semantic Kernel, and does not rely on SK Memory (SM). EF and SM serve different purposes. If you need natural language querying and efficient indexing, Semantic Kernel Memory is a great fit. If you’re building a standard application with a relational database, Entity Framework is more appropriate.\n\nThe key differences between Entity Framework (EF) and Semantic Kernel memory:\n\n## Purpose and Functionality\n- Entity Framework (EF): EF is an Object-Relational Mapping (ORM) framework for .NET applications. It allows you to map database tables to C# classes and provides an abstraction layer for database operations. EF focuses on CRUD (Create, Read, Update, Delete) operations and data modeling.\n- Semantic Kernel Memory: Semantic Kernel Memory (SM) is part of the Semantic Kernel project. It’s a library for C#, Python, and Java that wraps direct calls to databases and supports vector search. SM is designed for long-term memory and efficient indexing of datasets. It’s particularly useful for natural language querying and retrieval augmented generation (RAG).\n\n## Data Storage and Retrieval\n- EF: EF stores data in relational databases (e.g., SQL Server, MySQL, PostgreSQL). It uses SQL queries to retrieve data.\n- SM: SM can use various storage mechanisms, including vector databases. It supports vector search, which allows efficient similarity-based retrieval. SM is well-suited for handling large volumes of data and complex queries.\n\n## Querying\n- EF: EF queries are typically written in LINQ (Language Integrated Query) or SQL. You express queries in terms of C# objects and properties.\n- SM: SM supports natural language querying. You can search for information using text-based queries, making it more user-friendly for applications like chatbots.\n\n## Integration with Chat Systems\n- EF: EF doesn’t directly integrate with chat systems. It’s primarily used for data persistence.\n- SM: SM integrates seamlessly with chat systems like ChatGPT, Copilot, and Semantic Kernel. It enhances data-driven features in AI applications.\n\n## Scalability and Performance\n- EF: EF is suitable for small to medium-sized applications. It may not perform optimally with very large datasets.\n- SM: SM is designed for scalability. It can handle large volumes of data efficiently, making it suitable for memory-intensive applications.\n\n## Use Cases\n- EF: Use EF for traditional CRUD operations, business logic, and data modeling.\n- SM: Use SM for long-term memory, chatbots, question-answering systems, and information retrieval.\n\n# Contact\n* [GitHub Repo](https://www.github.com/goodtocode/templates)\n* [@goodtocode](https://www.twitter.com/goodtocode)\n* [github.com/goodtocode](https://www.github.com/goodtocode)\n\n# Technologies\n* [ASP.NET .Net](https://docs.microsoft.com/en-us/aspnet/core/introduction-to-aspnet-core)\n* [Entity Framework Core](https://docs.microsoft.com/en-us/ef/core/)\n\n# Semantic Kernel\n* [GitHub](https://github.com/microsoft/semantic-kernel.git)\n* [Getting Started Blog](https://devblogs.microsoft.com/semantic-kernel/how-to-get-started-using-semantic-kernel-net/)\n* [Understanding the Kernel](https://learn.microsoft.com/en-us/semantic-kernel/agents/kernel/?tabs=Csharp)\n* [Creating Plugins](https://devblogs.microsoft.com/semantic-kernel/using-semantic-kernel-to-create-a-time-plugin-with-net/)\n\n## Additional Technologies References\n* AspNetCore.HealthChecks.UI\n* Entity Framework Core\n* Microsoft.AspNetCore.App\n* Microsoft.AspNetCore.Cors\n* Swashbuckle.AspNetCore.SwaggerGen\n* Swashbuckle.AspNetCore.SwaggerUI\n\n# Version History\n\n| Version | Date        | Release Notes                             |\n|---------|-------------|-------------------------------------------|\n| 1.0.0   | 2024-Aug-05 | Initial WebAPI Release                    |\n| 1.0.1   | 2024-Oct-27 | Updated Azure IaC ESA/CAF Standards       |\n| 1.0.2   | 2025-Jan-19 | Updated to .NET 9 and SK 1.33             |\n| 1.0.3   | 2025-Feb-09 | Remove projects from File-New Project     |\n| 1.1.0   | 2025-Jun-04 | Blazor copilot-ish UX, AuthorSession      |\n| 1.1.1   | 2025-Jun-07 | Authors, Sessions \u0026 Messages Plugins      |\n| 1.1.2   | 2025-Aug-16 | Deprecated Specflow,Automapper\t\t\t|\n| 1.1.5   | 2025-Aug-18 | Deprecated FluentValidation/Assertions\t|\n| 1.1.6   | 2025-Aug-19 | Fixed blazor copilot chat runtime error\t|\n| 1.1.7   | 2025-Aug-22 | Deprecated MediatR\t\t\t\t\t\t|\n| 1.1.8   | 2025-Aug-23 | Updated docs. Fixed runtime message post\t|\n\nThis project is licensed with the [MIT license](https://mit-license.org/).","funding_links":[],"categories":["Open Source Projects"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodtocode%2Fsemantickernel-microservice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoodtocode%2Fsemantickernel-microservice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodtocode%2Fsemantickernel-microservice/lists"}