chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
### Running the OpenAPI syntax example
|
||||
|
||||
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/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).
|
||||
|
||||
3. Start the server by running `python openapi_server.py`.
|
||||
|
||||
4. In another terminal, do steps 1 & 2. Then, run `python openapi_client.py`, which will register a plugin representing the API defined in openapi.yaml
|
||||
@@ -0,0 +1,44 @@
|
||||
openapi: 3.1.0
|
||||
info:
|
||||
title: Test API
|
||||
version: 1.0.0
|
||||
servers:
|
||||
- url: http://localhost:8080
|
||||
paths:
|
||||
/{name}:
|
||||
post:
|
||||
summary: Hello World
|
||||
operationId: helloWorld
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
input:
|
||||
type: string
|
||||
description: The input of the request
|
||||
example: Howdy
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
parameters:
|
||||
- name: name
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
description: Your name
|
||||
- name: Header
|
||||
in: header
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
description: The header
|
||||
- name: q
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
type: string
|
||||
description: The query parameter
|
||||
@@ -0,0 +1,36 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from semantic_kernel import Kernel
|
||||
from semantic_kernel.functions.kernel_arguments import KernelArguments
|
||||
|
||||
|
||||
async def main():
|
||||
"""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)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,26 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
from aiohttp import web
|
||||
|
||||
"""OpenAPI Sample Server"""
|
||||
routes = web.RouteTableDef()
|
||||
|
||||
|
||||
@routes.post("/{name}")
|
||||
async def hello(request):
|
||||
# Get path parameters
|
||||
name = request.match_info.get("name", "")
|
||||
# Get query parameters
|
||||
q = request.rel_url.query.get("q", "")
|
||||
# Get body
|
||||
body = await request.json()
|
||||
# Get headers
|
||||
headers = request.headers
|
||||
return web.Response(text=f"Hello, {name}: q={q}, body={body}, headers={headers}")
|
||||
|
||||
|
||||
app = web.Application()
|
||||
app.add_routes(routes)
|
||||
|
||||
if __name__ == "__main__":
|
||||
web.run_app(app)
|
||||
Reference in New Issue
Block a user