Skip to content

Commit

Permalink
Merge pull request #87 from raffertyuy/main
Browse files Browse the repository at this point in the history
New sk-python-azure-functions-chatgpt-plugin and other minor updates
  • Loading branch information
markwallace-microsoft authored Dec 1, 2023
2 parents 0f9ff1d + e82aa67 commit 7ce99cc
Show file tree
Hide file tree
Showing 27 changed files with 698 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ Alternatively, you can use the [Semantic Kernel Tools](https://marketplace.visua
- [C# Hello World](sk-csharp-hello-world): The Hello World C# console application starter for the Semantic Kernel.
- [C# Console Chat](sk-csharp-console-chat): A console application based chat starter for the Semantic Kernel.
- [C# Azure Functions](sk-csharp-azure-functions): The Hello World C# Azure Functions starter for the Semantic Kernel.
- [C# Azure ChatGPT Plugin](sk-csharp-chatgpt-plugin): The Joke ChatGPT Plugin starter using C# Azure Functions for the Semantic Kernel.
- [Python Hello World](sk-python-hello-world): The Hello World Python console application starter for the Semantic Kernel.
- [Python Azure Functions](sk-python-azure-functions): The Hello World Python Azure Functions starter for the Semantic Kernel.
- [Python Azure Functions ChatGPT Plugin](sk-python-azure-functions-chatgpt-plugin): The Joke ChatGPT Plugin starter using Python Azure Functions for the Semantic Kernel.
- [Python Flask ChatGPT Plugin](sk-python-flask-chatgpt-plugin): The Joke ChatGPT Plugin starter using Python Flask for the Semantic Kernel.
- [Typescript Console Chat](sk-typescript-console-chat): A console application based chat starter for the Semantic Kernel.

## Contributing
Expand Down
19 changes: 19 additions & 0 deletions sk-csharp-chatgpt-plugin/azure-function/Logo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;

public class Logo
{
[Function("GetLogo")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "logo.png")] HttpRequestData req)
{
// Return logo.png that's in the root of the project
var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "image/png");

var logo = System.IO.File.ReadAllBytes("logo.png");
response.Body.Write(logo);

return response;
}
}
Binary file added sk-csharp-chatgpt-plugin/azure-function/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.12.0" OutputItemType="Analyzer" />
Expand Down Expand Up @@ -53,6 +54,12 @@
</AdditionalFiles>
</ItemGroup>

<ItemGroup>
<Content Include="logo.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
</ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions sk-python-azure-functions-chatgpt-plugin/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
OPENAI_API_KEY=""
OPENAI_ORG_ID=""
AZURE_OPENAI_DEPLOYMENT_NAME=""
AZURE_OPENAI_ENDPOINT=""
AZURE_OPENAI_API_KEY=""
8 changes: 8 additions & 0 deletions sk-python-azure-functions-chatgpt-plugin/.funcignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.git*
.vscode
__azurite_db*__.json
__blobstorage__
__queuestorage__
local.settings.json
test
.venv
134 changes: 134 additions & 0 deletions sk-python-azure-functions-chatgpt-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don’t work, or not
# install all needed dependencies.
#Pipfile.lock

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Azure Functions artifacts
bin
obj
appsettings.json

# Azurite artifacts
__blobstorage__
__queuestorage__
__azurite_db*__.json
.python_packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"ms-azuretools.vscode-azurefunctions",
"ms-python.python",
"azurite.azurite",
"ms-semantic-kernel.semantic-kernel",
]
}
12 changes: 12 additions & 0 deletions sk-python-azure-functions-chatgpt-plugin/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Python Functions",
"type": "python",
"request": "attach",
"port": 9091,
"preLaunchTask": "func: host start"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"azureFunctions.deploySubpath": ".",
"azureFunctions.scmDoBuildDuringDeployment": true,
"azureFunctions.pythonVenv": ".venv",
"azureFunctions.projectLanguage": "Python",
"azureFunctions.projectRuntime": "~4",
"debug.internalConsoleOptions": "neverOpen",
"azureFunctions.projectLanguageModel": 2
}
37 changes: 37 additions & 0 deletions sk-python-azure-functions-chatgpt-plugin/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "func",
"label": "func: host start",
"command": "host start",
"problemMatcher": "$func-python-watch",
"isBackground": true,
"dependsOn": "pip install (functions)"
},
{
"label": "create venv",
"type": "shell",
"command": "python -m venv .venv || echo 0",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "pip install (functions)",
"type": "shell",
"osx": {
"command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
},
"windows": {
"command": "${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt"
},
"linux": {
"command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
},
"problemMatcher": [],
"dependsOn": "create venv"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"schema_version": "v1",
"name_for_human": "Fun Plugin",
"name_for_model": "FunPlugin",
"description_for_human": "Execute fun skills such as jokes, excuses and limericks.",
"description_for_model": "A plugin for using semantic kernel fun skills.",
"auth": {
"type": "none"
},
"api": {
"type": "openapi",
"url": "http://localhost:7071/openapi.yaml"
},
"logo_url": "http://localhost:7071/logo.png",
"contact_email": "legal@example.com",
"legal_info_url": "http://example.com/legal"
}
50 changes: 50 additions & 0 deletions sk-python-azure-functions-chatgpt-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Semantic Kernel Python Azure Functions Starter

The `sk-python-azure-functions` application demonstrates how to execute a semantic function within an Azure Function.

## Prerequisites

- [Python](https://www.python.org/downloads/) >=3.8 and <3.11
- [Azure Functions](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions)
- [Azurite](https://marketplace.visualstudio.com/items?itemName=Azurite.azurite). Run the services from the VS Code status bar.
- [Semantic Kernel Tools](https://marketplace.visualstudio.com/items?itemName=ms-semantic-kernel.semantic-kernel)

## Configuring the starter

The starter can be configured with a `.env` file in the project which holds api keys and other secrets and configurations.

Make sure you have an
[Open AI API Key](https://openai.com/api/) or
[Azure Open AI service key](https://learn.microsoft.com/azure/cognitive-services/openai/quickstart?pivots=rest-api)

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=""
```

## Running the starter

To run the console application within Visual Studio Code, run Azurite from the status bar or command pallette, then just hit `F5`.
As configured in `launch.json` and `tasks.json`, Visual Studio Code will create a virtual environment at `.venv` and run `pip install requirements.txt`.

To run from command line, run the following:

```
python -m venv .venv
.venv\Scripts\python -m pip install -r requirements.txt # Location of python within venv depends on OS
.venv\Scripts\activate
func host start
```

## Using the starter

In your browser, visit `http://localhost:7071/api/skills/{skill_name/functions/{function_name}` to execute a skill.
For example, `http://localhost:7071/api/skills/FunSkill/functions/Joke` will execute the example Joke function in the FunSkill skill.

To provide input, send a POST request with a JSON body, e.g. provide this as input to the Joke function:
`{"input": "time traveling to dinosaur age", "style": "deadpan"}`
Loading

0 comments on commit 7ce99cc

Please sign in to comment.