|
| 1 | +# Semantic Kernel Python Azure Functions Starter |
| 2 | + |
| 3 | +The `sk-python-azure-functions` application demonstrates how to execute a semantic function within an Azure Function. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- [Python](https://www.python.org/downloads/) >=3.8 and <3.11 |
| 8 | +- [Azure Functions](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions) |
| 9 | +- [Azurite](https://marketplace.visualstudio.com/items?itemName=Azurite.azurite). Run the services from the VS Code status bar. |
| 10 | +- [Semantic Kernel Tools](https://marketplace.visualstudio.com/items?itemName=ms-semantic-kernel.semantic-kernel) |
| 11 | + |
| 12 | +## Configuring the starter |
| 13 | + |
| 14 | +The starter can be configured with a `.env` file in the project which holds api keys and other secrets and configurations. |
| 15 | + |
| 16 | +Make sure you have an |
| 17 | +[Open AI API Key](https://openai.com/api/) or |
| 18 | +[Azure Open AI service key](https://learn.microsoft.com/azure/cognitive-services/openai/quickstart?pivots=rest-api) |
| 19 | + |
| 20 | +Copy the `.env.example` file to a new file named `.env`. Then, copy those keys into the `.env` file: |
| 21 | + |
| 22 | +``` |
| 23 | +OPENAI_API_KEY="" |
| 24 | +OPENAI_ORG_ID="" |
| 25 | +AZURE_OPENAI_DEPLOYMENT_NAME="" |
| 26 | +AZURE_OPENAI_ENDPOINT="" |
| 27 | +AZURE_OPENAI_API_KEY="" |
| 28 | +``` |
| 29 | + |
| 30 | +## Running the starter |
| 31 | + |
| 32 | +To run the console application within Visual Studio Code, run Azurite from the status bar or command pallette, then just hit `F5`. |
| 33 | +As configured in `launch.json` and `tasks.json`, Visual Studio Code will create a virtual environment at `.venv` and run `pip install requirements.txt`. |
| 34 | + |
| 35 | +To run from command line, run the following: |
| 36 | + |
| 37 | +``` |
| 38 | +python -m venv .venv |
| 39 | +.venv\Scripts\python -m pip install -r requirements.txt # Location of python within venv depends on OS |
| 40 | +.venv\Scripts\activate |
| 41 | +func host start |
| 42 | +``` |
| 43 | + |
| 44 | +## Using the starter |
| 45 | + |
| 46 | +In your browser, visit `http://localhost:7071/api/skills/{skill_name/functions/{function_name}` to execute a skill. |
| 47 | +For example, `http://localhost:7071/api/skills/FunSkill/functions/Joke` will execute the example Joke function in the FunSkill skill. |
| 48 | + |
| 49 | +To provide input, send a POST request with a JSON body, e.g. provide this as input to the Joke function: |
| 50 | +`{"input": "time traveling to dinosaur age", "style": "deadpan"}` |
0 commit comments