Skip to content

Python: Fix OpenAPI concept sample #12418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/samples/concepts/plugins/openapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

For more generic setup instructions, including how to install the `uv` tool, see the [main README](../../../../DEV_SETUP.md).

1. In a terminal, navigate to `semantic_kernel/python/samples/kernel-syntax-examples/openapi_example`.
1. In a terminal, navigate to `semantic_kernel/python/samples/concepts/plugins/openapi`.

2. Run `uv sync` followed by `source .venv/bin/activate` to enter the virtual environment (depending on the os, the activate script may be in a different location).

Expand Down
2 changes: 1 addition & 1 deletion python/samples/concepts/plugins/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ paths:
description: Your name
- name: Header
in: header
required: false
required: true
schema:
type: string
description: The header
Expand Down
38 changes: 22 additions & 16 deletions python/samples/concepts/plugins/openapi/openapi_client.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
# Copyright (c) Microsoft. All rights reserved.

import asyncio
import os

import semantic_kernel as sk
from semantic_kernel import Kernel
from semantic_kernel.functions.kernel_arguments import KernelArguments


async def main():
"""Client"""
kernel = sk.Kernel()

openapi_plugin = kernel.add_plugin_from_openapi(plugin_name="openApiPlugin", openapi_document_path="./openapi.yaml")

arguments = {
"request_body": '{"input": "hello world"}',
"path_params": '{"name": "mark"}',
"query_params": '{"q": "0.7"}',
"headers": '{"Content-Type": "application/json", "Header": "example"}',
}

kernel_arguments = KernelArguments(**arguments)

result = await kernel.invoke(openapi_plugin["helloWorld"], arguments=kernel_arguments)
"""OpenAPI Sample Client"""
kernel = Kernel()

spec_path = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))),
"plugins",
"openapi",
"openapi.yaml",
)

openapi_plugin = kernel.add_plugin_from_openapi(plugin_name="openApiPlugin", openapi_document_path=spec_path)

arguments = KernelArguments(
input="hello world",
name="John",
q=0.7,
Header="example-header",
)

result = await kernel.invoke(openapi_plugin["helloWorld"], arguments=arguments)

print(result)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from aiohttp import web

"""Server"""
"""OpenAPI Sample Server"""
routes = web.RouteTableDef()


Expand Down
Loading