-
It's been fun playing with the OpenAPI Plugin code. Here is a situation I am not sure is covered yet. OverviewStraightforward caseSay that I am using Semantic Kernel on top of OpenAI to orchestrate various HTTP function calls for a client company, 'C'. 'C' has an endpoint at the URL
The response is a simple JSON object, for example So far, this is no issue to handle with the OpenAPI plugin. I can define a YAML file as below: openapi: 3.1.0
info:
title: Employee API
version: v0.1
servers:
- url: http://client-company.com
paths:
"/remaining-vacation-days":
post:
operationId: FindRemainingVacationDays
description: Returns number of vacation days an employee has left
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
authCode:
type: string
empno:
type: string
responses:
"200":
description: {OK response description}
content:
application/json:
schema:
type: object
properties:
result:
type: integer I can use OpenAPI plugin code as below to generate a Kernel Plugin.... employee_plugin = KernelPlugin.from_openapi(
plugin_name="Employee",
openapi_document_path="./path/to/employee.yaml"
) And ultimately Semantic Kernel communicates this plugin's function to OpenAI as follows...
such that if an end user asks "How many vacation days do I have left?", the Kernel will prompt the user to input their authorization code and employee number in order to make the HTTP request. Problem caseSay that for the purposes of the product it wants me to build, 'C' wants me to use the same FIXED_AUTH_CODE = ... # Provided by 'C'
@kernel_function(
name="find_remaining_vacation_days",
description="Returns number of vacation days an employee has left",
)
def find_emp_vcatn_cnt(self, empno: Annotated[str, "some description"):
BASE_PAYLOAD = { "authCode": FIXED_AUTH_CODE }
request = request.post("http://client-company.com/remaining-vacation-days",
json=BASE_PAYLOAD | { "empno": empno })
# omit post process and return Crucially,
In the scope of this thread, I will refer to payload values like Solutions?Unfortunately, I haven't found a way yet to use
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @w4-jake, thanks for the detailed question/post/discussion. This is wonderful. After an initial read, one should be able to adapt this similar to the following OpenAPI Azure Key Vault sample/yaml:
You can see in the following code that the kernel arguments contain some default values to create a secret: async def add_secret_to_key_vault(kernel: Kernel, plugin: KernelPlugin):
"""Adds a secret to the Azure Key Vault."""
arguments = KernelArguments()
arguments["secret_name"] = "Foo" # nosec
arguments["api_version"] = "7.0"
arguments["value"] = "Bar"
arguments["enabled"] = True
result = await kernel.invoke(
function=plugin["SetSecret"],
arguments=arguments,
) which corresponds to this portion of the OpenAPI spec: put:
summary: Create or update secret value
description: "Sets a secret in a specified key vault. This operation adds a secret to the Azure Key Vault. If the named secret already exists, Azure Key Vault creates a new version of that secret. This operation requires the secrets/set permission. For details, see: https://learn.microsoft.com/en-us/rest/api/keyvault/secrets/set-secret/set-secret."
operationId: SetSecret
parameters:
- name: secret-name
in: path
required: true
schema:
type: string
- name: api-version
in: query
required: true
schema:
type: string
default: "7.0"
x-ms-visibility: internal
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
attributes:
type: object
properties:
enabled:
type: boolean
description: Determines whether the object is enabled.
value:
type: string
description: The value of the secret.
required:
- value The AKV spec structure allows one to set up the request body to include the enabled bool and the value string. This would be similar to your Could you have a look at this, please, and see if we're on track to help with your use-case? Otherwise, I can keep digging. Thanks! |
Beta Was this translation helpful? Give feedback.
Hi @w4-jake, thanks for the detailed question/post/discussion. This is wonderful.
After an initial read, one should be able to adapt this similar to the following OpenAPI Azure Key Vault sample/yaml:
You can see in the following code that the kernel arguments contain some default values to create a secret:
https://github.com/microsoft/semantic-kernel/blob/821968a2631e4c3ce41fb953bbad1e52ac8a9eed/python/samples/conce…