Demystifying Semantic Kernel
Let's start with basic question, what exactly is Semantic Kernel?
1. SDK for AI Integration:
2. Orchestration with Intelligence:
3. Simplifying AI Adoption:
Unveiling Complex Concepts: A Simplified Analogy for Easy Understanding
Imagine Semantic Kernel as a wise team leader, and the plugins as their team members with different skills.
In essence, Semantic Kernel acts as the intelligent bridge between GPT-3's general suggestions and the specific actions of its plugins. It does this by:
Remember: GPT-3 offers creative ideas, but Semantic Kernel is the one who understands those ideas and turns them into specific actions within its own system.
Enough of analogy; let's delve into basic Python examples to understand its role more from an engineer's perspective:
import semantic_kernel as sk
# Create a kernel instance
kernel = sk.Kernel()
# Register plugins (here, we're using fictional plugins for illustration)
kernel.register_plugin(WeatherPlugin())
kernel.register_plugin(EmailPlugin())
kernel.register_plugin(TranslationPlugin())
# Set a planner (a simple rule-based planner for this example)
kernel.planner = SimpleRuleBasedPlanner()
# Example user goal
user_goal = "Tell me the weather in Paris, and then email a summary to my friend in Spanish."
# Execute the plan
result = kernel.execute(user_goal)
# Print the result (assuming it contains the weather information and email content)
print(result)
Explanation:
Key Points:
Till here we understood that Semantic kernal has plugins and it takes goal as input creates the plan to use different plugins, to achieve the desired goal, like in above example.
领英推荐
Let's explore another Python code example, this time integrating it with OpenAI. We'll break it down line by line to gain a clearer understanding of its end-to-end application
import semantic_kernel as sk
from openai import ChatGPT
kernel = sk.Kernel()
class GPT3Plugin:
def __init__(self, api_key):
self.gpt = ChatGPT(api_key)
def generate_text(self, prompt):
return self.gpt.submit(prompt)
kernel.register_plugin(GPT3Plugin("<your_openai_api_key>"))
kernel.register_plugin(WeatherPlugin())
kernel.register_plugin(EmailPlugin())
class OpenAIPlanner(sk.SimpleRuleBasedPlanner):
def plan(self, user_goal):
refined_goal = self.gpt3.generate_text(f"How can I best fulfill the request: {user_goal}")
return super().plan(refined_goal)
kernel.planner = OpenAIPlanner()
user_goal = "Write a creative poem about a rainy day in London."
result = kernel.execute(user_goal)
print(result)
So, in the above example, GPT once again proves to be an intelligent creator, generating creative results to fulfill the user's goal. Semantic Kernel comprehends the GPT response and devises a plan to use the defined plugins, ensuring a proper sequence of calling plugins — that is, the plan.
This is what I have learned so far about Semantic Kernel, and I wanted to share it with all of you as I believe it serves as a good starting point.