Welcome to the Semantic Kernel Python Tutorial 101! This repository provides a hands-on introduction to using Semantic Kernel with Python, demonstrating integration with various AI services. Semeantic implements a Kernel that supports Python, C#, and Java. The Kernel is an opinionated, configurable set of abstractions that are agentic in various ways. It offers a very interesting Plugins architecture that allows for LLM based and native functions within a plugin namespace for grouping more granular functions and tools - both semantic and discrete - to accomplish a larger task.
- Microsoft Semantic Kernel - github repo
- Compare / contrast LangChain, Semantic Kernel, and AutoGen
- Microsoft Learn - Intro to Semantic Kernel
- Python 3.10+
- pip (Python package manager)
- Ollama - https://www.ollama.com/
- Groq API key - https://console.groq.com/keys
-
Clone this repository:
git clone https://github.com/killerapp/semantic-kernel-python-tutorial.git cd semantic-kernel-python-tutorial
-
Install the required packages:
pip install -r requirements.txt
Before running the examples, you need to set up your environment variables. We provide sample .env
files for different services:
- .env.ollama.example - For Ollama
- .env.groq.example - For Groq
Copy the appropriate .env.*.example
file to .env
and fill in your API keys and other required information.
Run the Ollama example with:
cd sk-ollama
python sk-ollama.py
This script demonstrates how to use Semantic Kernel with an Ollama server. Key features:
execution_settings = OllamaChatPromptExecutionSettings()
kernel = Kernel()
# Alternative using Ollama:
service_id="ollama"
kernel.add_service(
OllamaChatCompletion(
service_id=service_id
)
)
Run the Groq example with:
cd sk-groq
python sk-groq.py
This script shows how to integrate Semantic Kernel with Groq. Notable sections:
# Use Groq:
service_id = "groq"
service = OpenAIChatCompletion(
service_id=service_id,
api_key=os.getenv("GROQ_API_KEY"),
org_id=os.getenv("GROQ_ORG_ID"),
ai_model_id=os.getenv("GROQ_MODEL")
)
service.client.base_url = os.getenv("GROQ_BASE_URL") # this is the important line
kernel.add_service(service=service)
This tutorial includes one sample plugin to demonstrate Semantic Kernel's capabilities:
- FunPlugin: Generates jokes, limericks, and creative excuses.
You can find plugins in the plugins/
directory.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
If you have any questions or feedback, please open an issue in this repository.
Happy coding with Semantic Kernel! 🎉