Files
semantic-kernel/samples/python/kernel_http_server
Adarsh AcharyaandDmytro Struk ff6b4fb39b Python: Fix type error in kernel server.py (#3185)
### Description

This PR fixes #3123.
The problem was in line 147 of kernel_server.py :
[Line147](https://github.com/microsoft/semantic-kernel/blob/bdc517d0f80e0f0896a8f1fc01d4327848c74937/samples/python/kernel_http_server/utils/kernel_server.py#L147C9-L147C14)

The plan object here is plan.Plan, which is incorrect. I believe it
should be basic_planner.Plan, here :
[plan](https://github.com/microsoft/semantic-kernel/blob/bdc517d0f80e0f0896a8f1fc01d4327848c74937/python/semantic_kernel/planning/basic_planner.py#L12C7-L12C11)

### Contribution Checklist

- [ ] 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
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄

---------

Co-authored-by: Dmytro Struk <[email protected]>
2023-10-16 17:54:37 +00:00
..
2023-07-19 23:30:18 +00:00
2023-07-19 23:30:18 +00:00

Semantic Kernel Service API (For Learning Samples)

Important

This sample will be removed in a future release. If you are looking for samples that demonstrate how to use Semantic Kernel, please refer to the sample folders in the root python and dotnet folders.

Watch the Service API Quick Start Video.

This service API is written in Python against Azure Function Runtime v4 and exposes some Semantic Kernel APIs that you can call via HTTP POST requests for the learning samples.

azure-function-diagram

!IMPORTANT

This service API is for educational purposes only and should not be used in any production use case. It is intended to highlight concepts of Semantic Kernel and not any architectural security design practices to be used.

Prerequisites

Azure Functions Core Tools installation is required for this service API to run locally.

Configuring the host

This starter can be configured in two ways:

  • A .env file in the project which holds api keys and other secrets and configurations
  • Or with HTTP Headers on each request

Make sure you have an OpenAI API Key or Azure OpenAI service key

Configure with a .env file

Copy the .env.example file to a new file named .env. Then, copy those keys into the .env file:

OPENAI_API_KEY=""
OPENAI_ORG_ID=""
AZURE_OPENAI_DEPLOYMENT_NAME=""
AZURE_OPENAI_ENDPOINT=""
AZURE_OPENAI_API_KEY=""

Configure with HTTP Headers

On each HTTP request, use these headers:

"x-ms-sk-completion-model" # e.g. text-davinci-003
"x-ms-sk-completion-endpoint" # e.g. https://my-endpoint.openai.azure.com
"x-ms-sk-completion-backend" # AZURE_OPENAI or OPENAI
"x-ms-sk-completion-key" # Your API key

Running the service API locally

Run python -m venv .venv && .\.venv\Scripts\python -m pip install -r requirements.txt && .venv\Scripts\activate to create and activate a virtual environment Run func start from the command line. This will run the service API locally at http://localhost:7071.

Four endpoints will be exposed by the service API:

  • InvokeFunction: [POST] http://localhost:7071/api/skills/{skillName}/invoke/{functionName}
  • Ping: [GET] http://localhost:7071/api/ping
  • CreatePlan: [POST] http://localhost:7071/api/planner/createplan
  • ExecutePlan: [POST] http://localhost:7071/api/planner/executeplan/{maxSteps}

They accept input in the JSON body of the request:

{
  "value": "", // the "input" of the prompt
  // a list of extra key-value parameters for ContextVariables or Plan State
  "inputs": [{ "key": "", "value": "" }],
  "skills": [] // list of skills to use (for the planner)
}

For planning, first create a plan with your prompt in the "value" parameter. Take the JSON "state" response, rename "state" to "inputs", and use it for the input to ExecutePlan.

Next steps

Now that your service API is running locally, let's try it out in a sample app so you can learn core Semantic Kernel concepts!
The service API will need to be run or running for each sample app you want to try.

Sample app learning examples:

  • Book creator – learn how Planner and chaining of semantic functions can be used in your app