liveBook · Manning

Chapter 5: Building a ChatGPT clone with Aspire, Ollama, and Semantic Kernel

What you will learn in chapter 5 of Building Distributed Applications that Work

The introduction motivates a product-specific chat assistant and identifies Semantic Kernel and Ollama as tools for adding a self-hosted LLM to an Aspire application.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction motivates a product-specific chat assistant and identifies Semantic Kernel and Ollama as tools for adding a self-hosted LLM to an Aspire application.

Key terms: LLM, domain-specific ChatGPT clone, virtual store assistant, Semantic Kernel, .NET libraries, LLMs, custom code, Ollama, self-host, Aspire integration library

5.1 Hosting an LLM anywhere with Ollama

This section explains why to run an LLM with Ollama and how to host a model in Aspire for a ChatGPT-like application.

Key terms: Ollama, local execution, LLM, CommunityToolkit.Aspire.Hosting.Ollama, persistent lifetime, WithDataVolume(), WithOpenWebUI(), AddModel(), phi35, phi3.5

5.2 Adding Semantic Kernel

This section identifies where Semantic Kernel belongs in the Aspire chat application and which Ollama connector package to install.

Key terms: Semantic Kernel, adapter libraries, LLM client, chat-completion functionality, OnlineShop.Web, Microsoft .SemanticKernel.Connectors.Ollama, NuGet package, preview, prerelease versions

5.2.1 Building the chatbot backend

Shows how to connect a Semantic Kernel backend to an Aspire-hosted Ollama model by obtaining its endpoint through a service-discovered connection string.

Key terms: service discovery, Ollama community toolkit, OllamaSharp, connection string, endpoint URI, Aspire host, phi35, ConnectionStrings, Semantic Kernel registration

5.2.2 Adding Semantic Kernel backend logic

This section adds session-specific chat history and a streaming SignalR hub to the Semantic Kernel chatbot backend.

Key terms: chat completion, chat history, connection ID, AddUserMessage(), GetChatHistory(), RemoveHistory(), singleton, Program.cs, user sessions, SignalR hub

5.3 Finalizing the user interface

The section introduces the browser-based SignalR client and tells the reader where to add its CDN-hosted library.

Key terms: SignalR, content delivery network (CDN), App.razor

5.3.1 Adding a SignalR JavaScript client

This section builds a browser-side SignalR client that connects the chat page to its hub and handles streamed responses and chat controls.

Key terms: chat.js, SignalR client, connection status, SignalR hub, hub-connection object, chat path, form-submission event, stream of characters, Stop, Clear

5.3.2 Building the chat page

This section creates the chat page’s Razor component and HTML while noting that the page cannot function until it is connected to the server.

Key terms: Chat.razor, Razor component, JavaScript interop, interactive mode, input field, output field, buttons, SignalR client

5.3.3 Adding the SignalR client to the page

This section explains why the chat page loads its SignalR JavaScript client through Blazor interop, then adds navigation so users can reach the page.

Key terms: SignalR JavaScript client, chat.js, App.razor, JavaScript interop, NavMenu .razor, chat page, chat interface

5.4 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 4: Adding order-tracking functionality with SignalR Chapter 6: Integration testing and monitoring →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.