Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Building AI Applications with Microsoft Semantic Kernel
Building AI Applications with Microsoft Semantic Kernel

Building AI Applications with Microsoft Semantic Kernel : Easily integrate generative AI capabilities and copilot experiences into your applications

eBook
€17.99 €26.99
Paperback
€22.99 €33.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Building AI Applications with Microsoft Semantic Kernel

Introducing Microsoft Semantic Kernel

The generative artificial intelligence (GenAI) space is evolving quickly, with dozens of new products and services being launched weekly; it is becoming hard for developers to keep up with the ever-changing features and application programming interfaces (APIs) for each of the services. In this book, you will learn about Microsoft Semantic Kernel, an API that will make it a lot easier for you to use GenAI as a developer, making your code shorter, simpler, and more maintainable. Microsoft Semantic Kernel will allow you, as a developer, to use a single interface to connect with several different GenAI providers. Microsoft used Semantic Kernel to develop its copilots, such as Microsoft 365 Copilot.

Billions of people already use GenAI as consumers, and you are probably one of them. We will start this chapter by showing some examples of what you can do with GenAI as a consumer. Then, you will learn how you can start using GenAI as a developer to...

Technical requirements

To complete this chapter, you will need to have a recent, supported version of your preferred Python or C# development environment:

  • For Python, the minimum supported version is Python 3.10, and the recommended version is Python 3.11
  • For C#, the minimum supported version is .NET 8

Important note

The examples are presented in C# and Python, and you can choose to only read the examples of your preferred language. Occasionally, a feature is available in only one of the languages. In such cases, we provide an alternative in the other language for how to achieve the same objectives.

In this chapter, we will call OpenAI services. Given the amount that companies spend on training these large language models (LLMs), it’s no surprise that using these services is not free. You will need an OpenAI API key, obtained either directly through OpenAI or Microsoft, via the Azure OpenAI service.

Important: Using the OpenAI services is not free...

Generative AI and how to use it

Generative AI refers to a subset of artificial intelligence programs that are capable of creating content that is similar to what humans can produce. These systems use training from very large datasets to learn their patterns, styles, and structures. Then, they can generate entirely new content, such as synthesized images, music, and text.

Using GenAI as consumer or end-user is very easy, and as a technical person, you probably have already done it. There are many consumer-facing AI products. The most famous is OpenAI’s ChatGPT, but there are many others that have hundreds of millions of users every day, such as Microsoft Copilot, Google Gemini (formerly Bard), and Midjourney. As of October 2023, Meta, the parent company of Facebook, WhatsApp, and Instagram, is making GenAI services available to all its users, increasing the number of GenAI daily users to billions.

While the concept of GenAI has existed for a while, it gained a lot of users...

Microsoft Semantic Kernel

Microsoft Semantic Kernel (https://github.com/microsoft/semantic-kernel) is a thin, open source software development toolkit (SDK) that makes it easier for applications developed in C# and Python to interact with AI services such as the ones made available through OpenAI, Azure OpenAI, and Hugging Face. Semantic Kernel can receive requests from your application and route them to different AI services. Furthermore, if you extend the functionality of Semantic Kernel by adding your own functions, which we will explore in Chapter 3, Semantic Kernel can automatically discover which functions need to be used, and in which order, to fulfill a request. The request can come directly from the user and be passed through directly from your application, or your application can modify and enrich the user request before sending it to Semantic Kernel.

It was originally designed to power different versions of Microsoft Copilot, such as Microsoft 365 Copilot and the Bing...

Using Semantic Kernel to connect to AI services

To complete this section, you must have an API key. The process to obtain an API key was described at the beginning of this chapter.

In the upcoming subsections, we are only going to connect to the OpenAI text models GPT-3.5 and GPT-4. If you have access to the OpenAI models through Azure, you will need to make minor modifications to your code.

Although it would be simpler to connect to a single model, we are already going to show a simple but powerful Microsoft Semantic Kernel feature: we’re going to connect to two different models and run a simple prompt using the simpler but less expensive model, GPT-3.5, and a more complex prompt on the more advanced but also more expensive model, GPT-4.

This process of sending simpler requests to simpler models and more complex requests to more complex models is something that you will frequently do when creating your own applications. This approach is called LLM cascade, and it was...

Running a simple prompt

This section assumes you completed the prior sections and builds upon the same code. By now, you should have instantiated Semantic Kernel and loaded both the GPT-3.5 and the GPT-4 services into it in that order. When you submit a prompt, it will default to the first service, and will run the prompt on GPT-3.5.

When we send the prompt to the service, we will also send a parameter called temperature. The temperature parameter goes from 0.0 to 1.0, and it controls how random the responses are. We’re going to explain the temperature parameter in more detail in later chapters. A temperature parameter of 0.8 generates a more creative response, while a temperature parameter of 0.2 generates a more precise response.

To send the prompt to the service, we will use a method called create_semantic_function. For now, don’t worry about what a semantic function is. We’re going to explain it in the Using generative AI to solve simple problems section...

Using generative AI to solve simple problems

Microsoft Semantic Kernel distinguishes between two types of functions that can be loaded into it: semantic functions and native functions.

Semantic functions are functions that connect to AI services, usually LLMs, to perform a task. The service is not part of your codebase. Native functions are regular functions written in the language of your application.

The reason to differentiate a native function from any other regular function in your code is that the native function will have additional attributes that will tell the kernel what it does. When you load a native function into the kernel, you can use it in chains that combine native and semantic functions. In addition, Semantic Kernel planner can use the function when creating a plan to achieve a user goal.

Creating semantic functions

We have already created a semantic function (knock) in the previous section. Now, we’re going to add a parameter to it. The default...

Plugins

One of the greatest strengths of Microsoft Semantic Kernel is that you can create semantic plugins that are language agnostic. Semantic plugins are collections of semantic functions that can be imported into the kernel. Creating semantic plugins allows you to separate your code from the AI function, which makes your application easier to maintain. It also allows other people to work on the prompts, making it easier to implement prompt engineering, which will be explored in Chapter 2.

Each function is defined by a directory containing two text files: config.json, which contains the configuration for the semantic function, and skprompt.txt, which contains its prompt.

The configuration of the semantic function includes the preferred engine to use, the temperature parameter, and a description of what the semantic function does and its inputs.

The text file contains the prompt that will be sent to the AI service to generate the response.

In this section, we are going...

Using a planner to run a multistep task

Instead of calling functions yourself, you can let Microsoft Semantic Kernel choose the functions for you. This can make your code a lot simpler and can give your users the ability to combine your code in ways that you haven’t considered.

Right now, this will not seem very useful because we only have a few functions and plugins. However, in a large application, such as Microsoft Office, you may have hundreds or even thousands of plugins, and your users may want to combine them in ways that you can’t yet imagine. For example, you may be creating a copilot that helps a user be more efficient when learning about a subject, so you write a function that downloads the latest news about that subject from the web. You may also have independently created a function that explains a piece of text to the user so that the user can paste content to learn more about it. The user may decide to combine them both with “download the news...

Summary

In this chapter, you learned about Generative AI and the main components of Microsoft Semantic Kernel. You learned how to create a prompt and submit it to a service and how to embed that prompt into a semantic function. You also learned how to execute multistep requests by using a planner.

In the next chapter, we are going to learn how to make our prompts better through a topic called prompt engineering. This will help you create prompts that get your users the correct result faster and use fewer tokens, therefore reducing costs.

References

[1] A. Vaswani et al., “Attention Is All You Need,” Jun. 2017.

[2] OpenAI, “GPT-4 Technical Report.” arXiv, Mar. 27, 2023. doi: 10.48550/arXiv.2303.08774.

[3] L. Chen, M. Zaharia, and J. Zou, “FrugalGPT: How to Use Large Language Models While Reducing Cost and Improving Performance.” arXiv, May 09, 2023. doi: 10.48550/arXiv.2305.05176.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Link your C# and Python applications with the latest AI models from OpenAI
  • Combine and orchestrate different AI services such as text and image generators
  • Create your own AI apps with real-world use case examples that show you how to use basic generative AI, create images, process documents, use a vector database
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

In the fast-paced world of AI, developers are constantly seeking efficient ways to integrate AI capabilities into their apps. Microsoft Semantic Kernel simplifies this process by using the GenAI features from Microsoft and OpenAI. Written by Lucas A. Meyer, a Principal Research Scientist in Microsoft’s AI for Good Lab, this book helps you get hands on with Semantic Kernel. It begins by introducing you to different generative AI services such as GPT-3.5 and GPT-4, demonstrating their integration with Semantic Kernel. You’ll then learn to craft prompt templates for reuse across various AI services and variables. Next, you’ll learn how to add functionality to Semantic Kernel by creating your own plugins. The second part of the book shows you how to combine multiple plugins to execute complex actions, and how to let Semantic Kernel use its own AI to solve complex problems by calling plugins, including the ones made by you. The book concludes by teaching you how to use vector databases to expand the memory of your AI services and how to help AI remember the context of earlier requests. You’ll also be guided through several real-world examples of applications, such as RAG and custom GPT agents. By the end of this book, you'll have gained the knowledge you need to start using Semantic Kernel to add AI capabilities to your applications.

Who is this book for?

This book is for beginner-level to experienced .NET or Python software developers who want to quickly incorporate the latest AI technologies into their applications, without having to learn the details of every new AI service. Product managers with some development experience will find this book helpful while creating proof-of-concept applications. This book requires working knowledge of programming basics.

What you will learn

  • Write reusable AI prompts and connect to different AI providers
  • Create new plugins that extend the capabilities of AI services
  • Understand how to combine multiple plugins to execute complex actions
  • Orchestrate multiple AI services to accomplish a task
  • Leverage the powerful planner to automatically create appropriate AI calls
  • Use vector databases as additional memory for your AI tasks
  • Deploy your application to ChatGPT, making it available to hundreds of millions of users

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 21, 2024
Length: 252 pages
Edition : 1st
Language : English
ISBN-13 : 9781835469590
Category :
Concepts :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jun 21, 2024
Length: 252 pages
Edition : 1st
Language : English
ISBN-13 : 9781835469590
Category :
Concepts :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 77.97 113.97 36.00 saved
Web API Development with ASP.NET Core 8
€28.99 €41.99
Building AI Applications with Microsoft Semantic Kernel
€22.99 €33.99
Building LLM Powered  Applications
€25.99 €37.99
Total 77.97 113.97 36.00 saved Stars icon
Banner background image

Table of Contents

13 Chapters
Part 1:Introduction to Generative AI and Microsoft Semantic Kernel Chevron down icon Chevron up icon
Chapter 1: Introducing Microsoft Semantic Kernel Chevron down icon Chevron up icon
Chapter 2: Creating Better Prompts Chevron down icon Chevron up icon
Part 2: Creating AI Applications with Semantic Kernel Chevron down icon Chevron up icon
Chapter 3: Extending Semantic Kernel Chevron down icon Chevron up icon
Chapter 4: Performing Complex Actions by Chaining Functions Chevron down icon Chevron up icon
Chapter 5: Programming with Planners Chevron down icon Chevron up icon
Chapter 6: Adding Memories to Your AI Application Chevron down icon Chevron up icon
Part 3: Real-World Use Cases Chevron down icon Chevron up icon
Chapter 7: Real-World Use Case – Retrieval-Augmented Generation Chevron down icon Chevron up icon
Chapter 8: Real-World Use Case – Making Your Application Available on ChatGPT Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(8 Ratings)
5 star 62.5%
4 star 25%
3 star 0%
2 star 0%
1 star 12.5%
Filter icon Filter
Top Reviews

Filter reviews by




Om S Jul 26, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is a fantastic resource for anyone looking to integrate AI into their applications. Lucas A. Meyer breaks down complex concepts into easy-to-understand steps, making it accessible even for beginners. The book covers how to link C# and Python applications with OpenAI models and use various AI services, such as text and image generators.What I loved most were the real-world examples. They provide practical insights on using generative AI, creating images, processing documents, and using a vector database. The inclusion of these examples helps you see the potential applications in a tangible way.The book is well-structured, starting from basic introductions to more advanced topics like creating and combining plugins. It also explains how to use vector databases for memory expansion, which is crucial for more complex AI tasks. Great addition to my tech library!!
Amazon Verified review Amazon
Lucas Puskaric Jun 26, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I did the technical review on this book, but it's truly a banger. Highly recommend
Amazon Verified review Amazon
Mojeed Abisiga Sep 09, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
If you are a professional in the Gen AI space looking to up your game, this Lucas's book is a must have! It offers a great deep dive into prompt engineering and building robust AI applications with Microsoft's Semantic Kernel SDK.What makes it stand out?Novel Code Design: A fresh approach to managing AI functionalities, similar to the leap classes brought to object-oriented programming.Seamless AI Integration: Streamlines the use of LLMs and other AI models for more efficient and powerful development.Flexible & Familiar: Innovates while allowing for the use of traditional Python functions - which makes the transition smooth for developers.This book is highly recommended for professionals eager to enhance their Gen AI skills.
Amazon Verified review Amazon
Chandra Jul 28, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is a great resource for Generative AI professionals seeking to build applications that require prompt engineering to construct RAGs and custom OpenAI apps. Lucas provides a high-level overview of Microsoft's Semantic Kernel SDK. This SDK integrates OpenAI, Azure OpenAI, and Hugging Face with Java, C#, and Python. Consequently, it's a valuable tool for software engineers to leverage their programming language expertise for developing Gen AI applications. Lucas offers lucid explanations of various topics including prompt engineering, image generation, document processing, and RAGs. Highly recommended for professionals eager to enhance their Gen AI skills.
Amazon Verified review Amazon
Alexander Ashish Sep 09, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I recently read this book which is an amazing guide for Gen AI professionals seeking to build applications that require prompt engineering to construct RAGs and custom OpenAI apps.I am sharing some key points from this book here 👩🏻‍💻📗 This book provides a proper details about the Semantic Kernel’s design which supports independent development and testing of components, perfect for building scalable and maintainable large-scale applications.📘 The kernel can dynamically combine functions which enables the creation of new workflows without additional coding which is ideal for complex applications like MS Office.📙 The book talk about the supports for both Core Plugins and custom semantic plugins which allows developers to create amazing workflows using AI services like OpenAI, without impacting the overall system.📔 The book offers practical guidance on CoT prompt templating and RAG application development within the Semantic Kernel framework.Well this book is around 250 pages only which makes it easier to explain the GEN AI usages and copilot experience in our applications .
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.