robvet / semantic-kernel-sleeping-bag

Fork Jordan Bean's Effort on SK Planners

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

semantic-kernel-sleeping-bag

architecture

This demo app demostrates how to use C# & Semantic Kernel to orchestrate AI calls. In this example, we are building a chatbot for an outdoor sports equipment company. This chatbot needs to be able to answer common questions that customer support gets.

For example, a customer might ask "Will my sleeping bag work for my trip to Patagonia next month?". The chatbot needs to be able to understand the question and then answer it. The answer might be "Yes, your sleeping bag will work for your trip to Patagonia next month. The lowest average temperature in Patagonia in November is 20 degrees Fahrenheiht. Your sleeping bag is rated for 5 degrees Fahrenheit.".

In order to do this, the code needs to be able to call several different data sources to answer the question.

  1. OrderHistory - This is an API that returns the customer's order history (including the product IDs of the items they ordered).
  2. ProductCatalog - This is an API that returns the product details for a given product ID.
  3. LocationLookup - This ia an API that returns the GPS coordindates of a given location.
  4. HistoricalWeather - This is an API that returns the average temperature for a given GPS location and date.

We need the RecommendationAPI to be able to call all of these APIs and then combine the results into a single answer. Semantic Kernel enables us to orchestrate these API calls via the StepwisePlanner. This planner will make multiple calls to the OpenAI service, make up its own plan to answer the question based upon the data & native plugins it has access to, then execute the plan.

Here is a series of blog posts that go through this demo in detail.

Disclaimer

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Prerequisites

Local development

Deployment

Deploy to Azure

  1. Run the following command to deploy all services to Azure (building Docker containers, deploying Azure infrastructure & deploying web apps takes about 30 minutes).

    azd up
  2. Navigate to the URL specified in the command window (or go to the Web app container app in the Azure portal) and click the Submit button.

homepage

Note

Since this is using generative AI, there is no guarantee that the plan generated will exactly match the screenshots. You may have to run the demo several times to get it to output the desired result.

Run locally

  1. Set the following application settings to initialize the RecommendationApi (this assumes you already have the required Azure services such as OpenAI & Application Insights deployed)..

    cd src/RecommendationApi
    
    dotnet user-secrets init
    
    dotnet user-secrets set "OpenAI:Endpoint" "https://..."
    
    dotnet user-secrets set "OpenAI:ChatModelName" "chat"
    
    dotnet user-secrets set "OpenAI:EmbeddingModelName" "embedding"
    
    dotnet user-secrets set "ApplicationInsights:ConnectionString" ""
    
    dotnet user-secrets set "EntraID:TenantId" ""
    
    dotnet user-secrets set "Cors:AllowedOrigins" "http://localhost:3000"
  2. Run the following command to start the application.

    tye run
  3. Navigate to the following URLs to test the application.

Links

About

Fork Jordan Bean's Effort on SK Planners

License:MIT License


Languages

Language:Bicep 73.0%Language:C# 15.2%Language:TypeScript 5.7%Language:Dockerfile 3.7%Language:Shell 0.8%Language:JavaScript 0.6%Language:CSS 0.5%Language:HTML 0.4%