Files
semantic-kernel/python/samples/kernel-syntax-examples/sequential_planner.py
T
Julio Carlos MenendezandEvan Mattson d97f9536c4 Python: Removes the _async suffix where is not needed (#4735)
### Motivation and Context
Delete all *_async where *_sync doesn't exist to make the library more
Pythonic.

Fixes #4629 

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] 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
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄

---------

Co-authored-by: Evan Mattson <[email protected]>
2024-01-26 17:15:35 +00:00

51 lines
1.4 KiB
Python

# Copyright (c) Microsoft. All rights reserved.
import semantic_kernel as sk
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
from semantic_kernel.core_plugins import (
FileIOPlugin,
MathPlugin,
TextPlugin,
TimePlugin,
)
from semantic_kernel.planning import SequentialPlanner
async def main():
kernel = sk.Kernel()
api_key, org_id = sk.openai_settings_from_dot_env()
kernel.add_chat_service("gpt-3.5", OpenAIChatCompletion("gpt-3.5-turbo", api_key=api_key, org_id=org_id))
kernel.import_plugin(MathPlugin(), "math")
kernel.import_plugin(FileIOPlugin(), "fileIO")
kernel.import_plugin(TimePlugin(), "time")
kernel.import_plugin(TextPlugin(), "text")
# create an instance of sequential planner.
planner = SequentialPlanner(kernel)
# the ask for which the sequential planner is going to find a relevant function.
ask = "What day of the week is today, all uppercase?"
# ask the sequential planner to identify a suitable function from the list of functions available.
plan = await planner.create_plan(goal=ask)
# ask the sequential planner to execute the identified function.
result = await plan.invoke_async()
for step in plan._steps:
print(step.description, ":", step._state.__dict__)
print("Expected Answer:")
print(result)
"""
Output:
SUNDAY
"""
if __name__ == "__main__":
import asyncio
asyncio.run(main())