Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure OpenAI Service Chat Sample initial commit #46

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions samples/azure-openai-service-chat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Azure OpenAI Service Chat

## Summary

This solution combines the interface of ChatGPT, The [Azure OpenAI service custom connector](https://github.com/microsoft/PowerPlatformConnectors/tree/dev/custom-connectors/AzureOpenAIService) to process the prompt, and the [Prompt Library](https://adoption.microsoft.com/en-us/sample-solution-gallery/sample/pnp-powerplatform-samples-prompt-library/) solution where prompts can be saved. This way the data stays within the organization, super users can save good working prompts, and all other employees can use these valuable prompts directly from within the app.

![picture of the sample](assets/AzureOpenAISeriveChat.png)

## Applies to

![Power Apps](https://img.shields.io/badge/Power%20Apps-Yes-green "Yes")
![Power Automate](https://img.shields.io/badge/Power%20Automate-Yes-green "Yes")
![Power BI](https://img.shields.io/badge/Power%20BI-No-red "No")
![Power Pages](https://img.shields.io/badge/Power%20Pages-No-red "No")
![Power Virtual Agents](https://img.shields.io/badge/Power%20Virtual%20Agents-No-red "No")
![Dataverse](https://img.shields.io/badge/Dataverse-Yes-green "Yes")
![AI Builder](https://img.shields.io/badge/AI%20Builder-No-red "No")
![Custom Connectors](https://img.shields.io/badge/Custom%20Connectors-Yes-green "Yes")
![Power Fx](https://img.shields.io/badge/Power%20Fx-No-red "No")

## Compatibility

![Premium License](https://img.shields.io/badge/Premium%20License-Required-green.svg "Premium license required")
![Experimental Features](https://img.shields.io/badge/Experimental%20Features-No-red.svg "Does not rely on experimental features")

## Contributors

* [Miguel Verweij](https://github.com/miguelverweij)

## Version history

| Version | Date | Comments |
| ------- | ---------------- | --------------- |
| 1.0 | October 15, 2023 | Initial release |

## Prerequisites

Below you can find a summary of the steps that are required to make this solution work. For a full step-by-step guide you can check out [Challenge 019](https://www.powerplatformchallenge.com/post/challenge-019) of the **Power Platform Challenge**.

1. Deploy Azure OpenAI Service to a resource group
2. Deploy the gpt-35-turbo model
3. Install [Creator Kit](https://learn.microsoft.com/en-us/power-platform/guidance/creator-kit/setup)
4. Install the [Prompt Library](https://github.com/pnp/powerplatform-samples/tree/main/samples/prompt-library) solution

## Minimal path to awesome

![Default prompt](assets/DefaultPrompt.png)

This solution is based on a custom connector. In order to import the solution, you will need a connection for the custom connector. We cannot do that at once yet. That's why you should import the custom connector solution first, create a connection, and import the rest of the solution.

1. Import the **AzureOpenAIServiceCustomConnector_1_0_0_1_managed** solution.
> The custom connector is in a seperate solution because you will need to create a connection on this connector before you can import the next solution.
2. Create a [connection](https://github.com/microsoft/PowerPlatformConnectors/tree/master/custom-connectors/AzureOpenAIService) for the custom connector.
3. Import the **ChatGPT_1_0_0_3_managed** solution. Create a connection for Dataverse, if you don't have one already.
4. Add a Default prompt to the Prompt Manager app (see image above). This prompt will act just like ChatGPT will, which makes it a good default option. It is good to know that the Notes field will be shown as hint text in the Azure OpenAI Sercive Chat app.
5. Add more custom prompts. You can find some very helpful prompts browsing the [Power Platform Prompt Library](https://pnp.github.io/powerplatform-prompts/?filters=azure%20open%20ai).
6. Open the Azure OpenAI Sercive Chat app and create a new chat. In the top-right corner you can see a bot icon. all the available prompts will be listed when clicking on that icon. Select the prompt that you want to use. You can only do this at the start of the conversation.

<!--
UPDATE DE SOLUTION PATH
-->

### Using the solution zip

* Download both [AzureOpenAIServiceCustomConnector_1_0_0_1_managed](./solution/AzureOpenAIServiceCustomConnector_1_0_0_1_managed.zip) and [ChatGPT_1_0_0_3_managed](./solution/ChatGPT_1_0_0_3_managed.zip) `.zip` files from the `solution` folder.
* Within **Power Apps Studio**, import the solution `.zip` files using **Solutions** > **Import Solution** and select the `.zip` file. Start with the custom connector `.zip` file first.

### Using the source code

You can also use the [Power Apps CLI](https://docs.microsoft.com/powerapps/developer/data-platform/powerapps-cli) to pack the source code by following these steps:

* Clone the repository to a local drive
* Pack the source files back into a solution `.zip` file:

```bash
pac solution pack --zipfile pathtodestinationfile --folder pathtosourcefolder --processCanvasApps
```

Making sure to replace `pathtosourcefolder` to point to the path to this sample's `sourcecode/solution` folder, and `pathtodestinationfile` to point to the path of this solution's `.zip` file (located under the `solution` folder)
* Within **Power Apps Studio**, import the solution `.zip` file using **Solutions** > **Import Solution** and select the `.zip` file you just packed.

## Features

* Enterprise safe ChatGPT
* Quickly use saved prompts
* consumption-based licensing

<!--
RESERVED FOR REPO MAINTAINERS

We'll add the video from the community call recording here

## Video

[![YouTube video title](./assets/video-thumbnail.jpg)](https://www.youtube.com/watch?v=XXXXX "YouTube video title")
-->

## Help

<!--
You can just search and replace this page with the following values:

Search for:
YOUR-SOLUTION-NAME

Replace with your sample folder name. E.g.: my-cool-sample

Search for:
@YOURGITHUBUSERNAME

Replace with your GitHub username, prefixed with an "@". If you have more than one author, use %20 to separate them, making sure to prefix everyone's username individually with an "@".

Example:
@hugoabernier

Or:
@hugoabernier%20@VesaJuvonen%20@PopWarner
-->

> Note: don't worry about this section, we'll update the links.

We do not support samples, but this community is always willing to help, and we want to improve these samples. We use GitHub to track issues, which makes it easy for community members to volunteer their time and help resolve issues.

If you encounter any issues while using this sample, you can [create a new issue](https://github.com/pnp/powerapps-samples/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected&template=bug-report.yml&sample=YOURSAMPLENAME&authors=@YOURGITHUBUSERNAME&title=YOURSAMPLENAME%20-%20).

For questions regarding this sample, [create a new question](https://github.com/pnp/powerapps-samples/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected&template=question.yml&sample=YOURSAMPLENAME&authors=@YOURGITHUBUSERNAME&title=YOURSAMPLENAME%20-%20).

Finally, if you have an idea for improvement, [make a suggestion](https://github.com/pnp/powerapps-samples/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected&template=suggestion.yml&sample=YOURSAMPLENAME&authors=@YOURGITHUBUSERNAME&title=YOURSAMPLENAME%20-%20).

## Disclaimer

**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**

<img src="https://m365-visitor-stats.azurewebsites.net/powerplatform-samples/samples/azure-openai-service-chat" />
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# msbuild output directories
/bin
/obj

# MSBuild Binary and Structured Log
*.binlog
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PowerAppsTargetsPath>$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\PowerApps</PowerAppsTargetsPath>
</PropertyGroup>

<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<Import Project="$(PowerAppsTargetsPath)\Microsoft.PowerApps.VisualStudio.Solution.props" Condition="Exists('$(PowerAppsTargetsPath)\Microsoft.PowerApps.VisualStudio.Solution.props')" />

<PropertyGroup>
<ProjectGuid>c5eadf16-96dd-43d3-af4f-7e62e928d629</ProjectGuid>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<!--Remove TargetFramework when this is available in 16.1-->
<TargetFramework>net462</TargetFramework>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<SolutionRootPath>src</SolutionRootPath>
</PropertyGroup>

<!--
Solution Packager overrides, un-comment to use: SolutionPackagerType (Managed, Unmanaged, Both)
Solution Localization Control, if you want to enabled localization of your solution, un-comment SolutionPackageEnableLocalization and set the value to true. - Requires use of -loc flag on Solution Clone or Sync
-->
<!--
<PropertyGroup>
<SolutionPackageType>Managed</SolutionPackageType>
<SolutionPackageEnableLocalization>false</SolutionPackageEnableLocalization>
</PropertyGroup>
-->

<ItemGroup>
<PackageReference Include="Microsoft.PowerApps.MSBuild.Solution" Version="1.*" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<ExcludeDirectories Include="$(MSBuildThisFileDirectory)\.gitignore" />
<ExcludeDirectories Include="$(MSBuildThisFileDirectory)\bin\**" />
<ExcludeDirectories Include="$(MSBuildThisFileDirectory)\obj\**" />
<ExcludeDirectories Include="$(MSBuildThisFileDirectory)\*.cdsproj" />
<ExcludeDirectories Include="$(MSBuildThisFileDirectory)\*.cdsproj.user" />
<ExcludeDirectories Include="$(MSBuildThisFileDirectory)\*.sln" />
</ItemGroup>

<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)\**" Exclude="@(ExcludeDirectories)" />
<Content Include="$(SolutionPackageZipFilePath)">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" />
<Import Project="$(PowerAppsTargetsPath)\Microsoft.PowerApps.VisualStudio.Solution.targets" Condition="Exists('$(PowerAppsTargetsPath)\Microsoft.PowerApps.VisualStudio.Solution.targets')" />

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Connector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<connectorid>76b87ad4-2b1d-44cf-965c-df67c01b8666</connectorid>
<description>Azure OpenAI Service provides access to OpenAI's powerful language models including the GPT-3, Codex and Embeddings model series. These models can be easily adapted to your specific task including but not limited to content generation, summarization, semantic search, and natural language to code translation.</description>
<displayname>AzureOpenAIService</displayname>
<iconbrandcolor>#007ee5</iconbrandcolor>
<name>ppchal_azureopenaiservice</name>
<connectortype>1</connectortype>
<scriptoperations>["ChatCompletion","CreateCompletion"]</scriptoperations>
<openapidefinition>/Connector/ppchal_azureopenaiservice_openapidefinition.json</openapidefinition>
<connectionparameters>/Connector/ppchal_azureopenaiservice_connectionparameters.json</connectionparameters>
<policytemplateinstances>/Connector/ppchal_azureopenaiservice_policytemplateinstances.json</policytemplateinstances>
<customcodeblobcontent>/Connector/ppchal_azureopenaiservice_customcodeblobcontent.csx</customcodeblobcontent>
<iconblob>/Connector/ppchal_azureopenaiservice_iconblob.Png</iconblob>
</Connector>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"azureOpenAIServiceName":{"type":"string","uiDefinition":{"constraints":{"required":"true"},"description":"Specify the name of your instance (for instance: microsoft when the endpoint is https://microsoft.openai.azure.com/)","displayName":"Instance name","tooltip":"Specify the name of your instance (for instance: microsoft when the endpoint is https://microsoft.openai.azure.com/)"}},"api_key":{"type":"securestring","uiDefinition":{"displayName":"API Key","description":"The API Key for this api","tooltip":"Provide your API Key","constraints":{"tabIndex":2,"clearText":false,"required":"true"}}}}
Loading