OpenAPI is a widely adopted standard for describing RESTful APIs in a way that is both human-readable and machine-friendly. It streamlines API integration by providing automatic documentation, client SDK generation, and reduced manual coding efforts. By leveraging OpenAPI specifications, Semantic Kernel can dynamically load external services as plugins, letting your AI-driven apps discover, invoke, and orchestrate these APIs more effectively.
As developers, we can enrich our applications by integrating various APIs through OpenAPI specifications. In this challenge, you will learn how to import the provided WorkItems API as an OpenAPI plugin in Semantic Kernel and interact with it through AI-driven prompts.
NOTE: You have an existing OpenAPI spec for the WorkItems API. Make sure to locate it and use it when configuring your Semantic Kernel plugin.
This challenge will introduce you to how to import OpenAPI API as Semantic Kernels Plugins in Python, and how to chain plugins using the Auto Function Calling capabilities of Semantic Kernel.
- Launch your AI Chat app, and ask the bot
What are my work items?- Test the prompt "What are my work items?" see how it responds.
- You will be adding a new plugin to your Semantic Kernel using the API provided in the workshop. API can be found in
workitemsfolder insidePythonfolder.-
Start the uvicorn app
- Go to
Python/workitemsfolder - Run
python api.pyon command prompt - Find the OpenAPI spec in following path
http://127.0.0.1:8000/openapi.json - Swagger page can be found in
http://127.0.0.1:8000/docs
- Go to
-
Import the API into Semantic Kernel.
kernel.add_plugin_from_openapi( plugin_name="get_tasks", openapi_document_path="http://127.0.0.1:8000/openapi.json", execution_settings=OpenAPIFunctionExecutionParameters( enable_payload_namespacing=True, ) )
❗ Semantic Kernel SDK for OpenAPI's - your plugin name must be 64 characters or less.
-
Test the prompt "What are my work items?" see how it responds.
-
- (Optional) Do you have another API you would like to integrate with? Try importing it as a plugin.
- Your chat bot should be able to answer the question "What are my work items?" with a list of work items from the API.
- You can ask the bot to filter, sort, group, or change the display format of the work items.
- (Optional) Test other CRUD operations on the WorkItems API and try chaining multiple operations together.