mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
### Motivation and Context In an effort to move all samples to their respective language folder, I've moved all of the notebooks to the correct language folder. ### Contribution Checklist - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄
12 KiB
12 KiB
In [ ]:
!python -m pip install semantic-kernel -UIn [ ]:
import semantic_kernel as sk
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion, AzureChatCompletion
kernel = sk.Kernel()
useAzureOpenAI = True
# Configure AI backend used by the kernel
if useAzureOpenAI:
deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()
kernel.add_chat_service("gpt-3.5", AzureChatCompletion("gpt-35-turbo", endpoint, api_key))
else:
api_key, org_id = sk.openai_settings_from_dot_env()
kernel.add_chat_service("gpt-3.5", OpenAIChatCompletion("gpt-3.5-turbo", api_key, org_id))In [ ]:
ask = """
Tomorrow is Valentine's day. I need to come up with a few date ideas. She speaks French so write it in French.
Convert the text to uppercase"""In [ ]:
from semantic_kernel.core_skills.text_skill import TextSkill
skills_directory = "../../samples/skills/"
summarize_skill = kernel.import_semantic_skill_from_directory(skills_directory, "SummarizeSkill")
writer_skill = kernel.import_semantic_skill_from_directory(skills_directory, "WriterSkill")
text_skill = kernel.import_skill(TextSkill(), "TextSkill")In [ ]:
from semantic_kernel.planning.basic_planner import BasicPlanner
planner = BasicPlanner()In [ ]:
basic_plan = await planner.create_plan_async(ask, kernel)In [ ]:
print(basic_plan.generated_plan)In [ ]:
sk_prompt = """
{{$input}}
Rewrite the above in the style of Shakespeare.
"""
shakespeareFunction = kernel.create_semantic_function(sk_prompt, "shakespeare", "ShakespeareSkill",
max_tokens=2000, temperature=0.8)In [ ]:
ask = """
Tomorrow is Valentine's day. I need to come up with a few date ideas.
She likes Shakespeare so write using his style. She speaks French so write it in French.
Convert the text to uppercase."""
new_plan = await planner.create_plan_async(ask, kernel)In [ ]:
print(new_plan.generated_plan)In [ ]:
results = await planner.execute_plan_async(new_plan, kernel)In [ ]:
print(results)In [ ]:
from semantic_kernel.planning import SequentialPlanner
planner = SequentialPlanner(kernel)In [ ]:
sequential_plan = await planner.create_plan_async(goal=ask)In [ ]:
for step in sequential_plan._steps:
print(step.description, ":", step._state.__dict__)In [ ]:
result = await sequential_plan.invoke_async()In [ ]:
print(result)In [ ]:
from semantic_kernel.planning import ActionPlanner
planner = ActionPlanner(kernel)In [ ]:
from semantic_kernel.core_skills import FileIOSkill, MathSkill, TextSkill, TimeSkill
kernel.import_skill(MathSkill(), "math")
kernel.import_skill(FileIOSkill(), "fileIO")
kernel.import_skill(TimeSkill(), "time")
kernel.import_skill(TextSkill(), "text")In [ ]:
ask = "What is the sum of 110 and 990?"In [ ]:
plan = await planner.create_plan_async(goal=ask)In [ ]:
result = await plan.invoke_async()In [ ]:
print(result)