Skip to content

Commit

Permalink
Merge pull request #846 from anoopt/personal-assistant
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoabernier authored Aug 26, 2023
2 parents 081ba93 + 444821a commit 98e6f1b
Show file tree
Hide file tree
Showing 39 changed files with 69,065 additions and 0 deletions.
352 changes: 352 additions & 0 deletions samples/react-application-personal-assistant/.eslintrc.js

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions samples/react-application-personal-assistant/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Logs
logs
*.log
npm-debug.log*

# Dependency directories
node_modules

# Build generated files
dist
lib
release
solution
temp
*.sppkg
.heft

# Coverage directory used by tools like istanbul
coverage

# OSX
.DS_Store

# Visual Studio files
.ntvs_analysis.dat
.vs
bin
obj

# Resx Generated Code
*.resx.ts

# Styles Generated Code
*.scss.ts
*.scss.d.ts
16 changes: 16 additions & 0 deletions samples/react-application-personal-assistant/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
!dist
config

gulpfile.js

release
src
temp

tsconfig.json
tslint.json

*.log

.yo-rc.json
.vscode
23 changes: 23 additions & 0 deletions samples/react-application-personal-assistant/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Hosted workbench",
"type": "msedge",
"request": "launch",
"url": "https://{tenantDomain}/_layouts/workbench.aspx",
"webRoot": "${workspaceRoot}",
"sourceMaps": true,
"sourceMapPathOverrides": {
"webpack:///.././src/*": "${webRoot}/src/*",
"webpack:///../../../src/*": "${webRoot}/src/*",
"webpack:///../../../../src/*": "${webRoot}/src/*",
"webpack:///../../../../../src/*": "${webRoot}/src/*"
},
"runtimeArgs": [
"--remote-debugging-port=9222",
"-incognito"
]
}
]
}
13 changes: 13 additions & 0 deletions samples/react-application-personal-assistant/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Place your settings in this file to overwrite default and user settings.
{
// Configure glob patterns for excluding files and folders in the file explorer.
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"**/bower_components": true,
"**/coverage": true,
"**/lib-amd": true,
"src/**/*.scss.ts": true
},
"typescript.tsdk": ".\\node_modules\\typescript\\lib"
}
22 changes: 22 additions & 0 deletions samples/react-application-personal-assistant/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"@microsoft/generator-sharepoint": {
"plusBeta": false,
"isCreatingSolution": true,
"nodeVersion": "16.20.0",
"sdksVersions": {
"@microsoft/microsoft-graph-client": "3.0.2",
"@microsoft/teams-js": "2.9.1"
},
"version": "1.17.3",
"libraryName": "personal-assistant",
"libraryId": "e6fe279b-a2f3-4047-8d2c-8702c8274991",
"environment": "spo",
"packageManager": "npm",
"solutionName": "PersonalAssistant",
"solutionShortDescription": "PersonalAssistant description",
"skipFeatureDeployment": true,
"isDomainIsolated": false,
"componentType": "extension",
"extensionType": "ApplicationCustomizer"
}
}
98 changes: 98 additions & 0 deletions samples/react-application-personal-assistant/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Personal Assistant - OpenAI Function Calling with Microsoft Graph

## Summary

- This sample is chatbot that provides information to the current logged in user.
- The information can be the user's basic details or user's calendar details or user's tasks. - The information exchanged between the user and the chatbot is in natural language.
- The chatbot uses [OpenAI's function calling feature](https://openai.com/blog/function-calling-and-other-api-updates) to understand whether a function in the code needs to be called based on user's query.
- The chatbot uses Microsoft Graph API to get the user's details or details from calendar or tasks.
- That JSON response is then transformed into a natural language response by OpenAI and sent back to the user.

![Chatbot](./assets/demo.gif)

## Used SharePoint Framework Version

![SPFx 1.17.3](https://img.shields.io/badge/version-1.17.3-green.svg)
16.13.0![Node.js v16 | v14 | v12](https://img.shields.io/badge/Node.js-v16%20%7C%20v14%20%7C%20v12-green.svg)
![Compatible with SharePoint Online](https://img.shields.io/badge/SharePoint%20Online-Compatible-green.svg)
![Does not work with SharePoint 2019](https://img.shields.io/badge/SharePoint%20Server%202019-Incompatible-red.svg "SharePoint Server 2019 requires SPFx 1.4.1 or lower")
![Does not work with SharePoint 2016 (Feature Pack 2)](https://img.shields.io/badge/SharePoint%20Server%202016%20(Feature%20Pack%202)-Incompatible-red.svg "SharePoint Server 2016 Feature Pack 2 requires SPFx 1.1")
![Local Workbench Unsupported](https://img.shields.io/badge/Local%20Workbench-Unsupported-red.svg "Local workbench is no longer available as of SPFx 1.13 and above")
![Hosted Workbench Compatible](https://img.shields.io/badge/Hosted%20Workbench-Compatible-green.svg)

Tested with Node.js v16.13.0

## Applies to

- [SharePoint Framework](https://aka.ms/spfx)
- [Microsoft 365 tenant](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-developer-tenant)

> Get your own free development tenant by subscribing to [Microsoft 365 developer program](http://aka.ms/o365devprogram)
## Prerequisites

> Open AI API key. You can get a key from <https://platform.openai.com/account/api-keys>
## Contributors

* [Anoop Tatti](https://github.com/anoopt)

## Version history

| Version | Date | Comments |
| ------- | ---------------- | --------------- |
| 1.0 | June 23, 2023 | Initial release |

## 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.**

> This sample calls OpenAI API from client side code. This is not recommended. You should call OpenAI API from server side code. This sample is only for demonstration purposes.
---

## Minimal Path to Awesome

- Clone this repository
- Ensure that you are at the solution folder
- In the command-line run:
- **npm install**
- **gulp bundle --ship**
- **gulp package-solution --ship**
- Upload the **personal-assistant.sppkg** from the **sharepoint/solution** folder to your SharePoint tenant's app catalog
- In the API access page approve the following
- `User.Read`, `Calendars.Read` and `Tasks.Read` permission for the Microsoft Graph API
- In the command-line run:
- **gulp serve --nobrowser**
- Open your SharePoint Online site
- Append the following query string parameters to the URL: `?debugManifestsFile=https://localhost:4321/temp/manifests.js&loadSPFX=true&customActions={"a4c9460d-77b2-4864-8fb7-183bf668c222":{"location":"ClientSideExtension.ApplicationCustomizer","properties":{"show":true}}}`
- You should now see the chatbot in the bottom right corner of the page

## Features

- This sample shows how use [OpenAI's function calling feature](https://openai.com/blog/function-calling-and-other-api-updates). A personal assistant chatbot (an SPFx application customiser) is used to show this feature in action.
- The chatbot sends the user's message to [OpenAI API](https://platform.openai.com/docs/api-reference).
- Based on user's message, OpenAI determines whether a function needs to be called.
- If so, based on the response from OpenAI, the chatbot calls the function - which in turn uses [Microsoft Graph API](https://docs.microsoft.com/en-us/graph/overview) to get the user's details or details from calendar or tasks.
- The result of the function is then sent back to OpenAI. OpenAI then uses the result to generate a response to the user.

## References

- [Getting started with SharePoint Framework](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-developer-tenant)
- [Building for Microsoft teams](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/build-for-teams-overview)
- [Use Microsoft Graph in your solution](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/using-microsoft-graph-apis)
- [Publish SharePoint Framework applications to the Marketplace](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/publish-to-marketplace-overview)
- [Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) - Guidance, tooling, samples and open-source controls for your Microsoft 365 development


## Help

We do not support samples, but we 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, [create a new issue](https://github.com/pnp/sp-dev-fx-extensions/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected&template=bug-report.yml&sample=react-application-personal-assistant&authors=@anoopt&title=react-application-personal-assistant%20-%20).

For questions regarding this sample, [create a new question](https://github.com/pnp/sp-dev-fx-extensions/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected&template=question.yml&sample=react-application-personal-assistant&authors=@anoopt&title=react-application-personal-assistant%20-%20).

Finally, if you have an idea for improvement, [make a suggestion](https://github.com/pnp/sp-dev-fx-extensions/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected&template=suggestion.yml&sample=react-application-personal-assistant&authors=@anoopt&title=react-application-personal-assistant%20-%20).

<img src="https://m365-visitor-stats.azurewebsites.net/sp-dev-fx-extensions/samples/react-application-personal-assistant" />
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions samples/react-application-personal-assistant/assets/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
{
"name": "pnp-sp-dev-spfx-extensions-react-application-personal-assistant",
"source": "pnp",
"title": "Personal Assistant - OpenAI Function Calling with Microsoft Graph",
"shortDescription": "This sample is chatbot that provides information to the current logged in user.",
"url": "https://github.com/pnp/sp-dev-fx-extensions/tree/main/samples/react-application-personal-assistant",
"longDescription": [
"This sample is chatbot that provides information to the current logged in user."
],
"creationDateTime": "2023-06-23",
"updateDateTime": "2023-06-23",
"products": [
"SharePoint"
],
"metadata": [
{
"key": "CLIENT-SIDE-DEV",
"value": "React"
},
{
"key": "SPFX-VERSION",
"value": "1.17.3"
}
],
"tags": [],
"categories": [
"SPFX-APPLICATION-EXTENSION"
],
"thumbnails": [
{
"type": "image",
"order": 100,
"url": "https://github.com/pnp/sp-dev-fx-extensions/raw/main/samples/react-application-personal-assistant/assets/demo.gif",
"alt": "Extension preview"
}
],
"authors": [
{
"gitHubAccount": "anoopt",
"pictureUrl": "https://github.com/anoopt.png",
"name": "Anoop Tatti"
}
],
"references": [
{
"name": "Overview of SharePoint Framework Extensions",
"description": "You can use SharePoint Framework (SPFx) Extensions to extend the SharePoint user experience. With SPFx Extensions, you can customize more facets of the SharePoint experience, including notification areas, toolbars, and list data views. SPFx Extensions are available in all Microsoft 365 subscriptions for production usage.",
"url": "https://docs.microsoft.com/sharepoint/dev/spfx/extensions/overview-extensions?WT.mc_id=m365-15741-cxa"
},
{
"name": "Use page placeholders from Application Customizer",
"description": "Application Customizers provide access to well-known locations on SharePoint pages that you can modify based on your business and functional requirements. For example, you can create dynamic header and footer experiences that render across all the pages in SharePoint Online.",
"url": "https://docs.microsoft.com/sharepoint/dev/spfx/extensions/get-started/using-page-placeholder-with-extensions?WT.mc_id=m365-15741-cxa"
}
]
}
]
18 changes: 18 additions & 0 deletions samples/react-application-personal-assistant/config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0",
"bundles": {
"personal-assistant-application-customizer": {
"components": [
{
"entrypoint": "./lib/extensions/personalAssistant/PersonalAssistantApplicationCustomizer.js",
"manifest": "./src/extensions/personalAssistant/PersonalAssistantApplicationCustomizer.manifest.json"
}
]
}
},
"externals": {},
"localizedResources": {
"PersonalAssistantApplicationCustomizerStrings": "lib/extensions/personalAssistant/loc/{locale}.js"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
"workingDir": "./release/assets/",
"account": "<!-- STORAGE ACCOUNT NAME -->",
"container": "personal-assistant",
"accessKey": "<!-- ACCESS KEY -->"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "personal-assistant-application-customizer",
"id": "e6fe279b-a2f3-4047-8d2c-8702c8274991",
"version": "1.0.0.0",
"includeClientSideAssets": true,
"skipFeatureDeployment": true,
"isDomainIsolated": false,
"developer": {
"name": "",
"websiteUrl": "",
"privacyUrl": "",
"termsOfUseUrl": "",
"mpnId": "Undefined-1.17.3"
},
"webApiPermissionRequests": [
{
"resource": "Microsoft Graph",
"scope": "User.Read"
},
{
"resource": "Microsoft Graph",
"scope": "Calendars.Read"
},
{
"resource": "Microsoft Graph",
"scope": "Tasks.Read"
}
],
"metadata": {
"shortDescription": {
"default": "PersonalAssistant description"
},
"longDescription": {
"default": "PersonalAssistant description"
},
"screenshotPaths": [],
"videoUrl": "",
"categories": []
},
"features": [
{
"title": "Application Extension - Deployment of custom action",
"description": "Deploys a custom action with ClientSideComponentId association",
"id": "33b2afe9-2d88-4619-8ece-52a0fb2572c5",
"version": "1.0.0.0",
"assets": {
"elementManifests": [
"elements.xml",
"ClientSideInstance.xml"
]
}
}
]
},
"paths": {
"zippedPackage": "solution/personal-assistant.sppkg"
}
}
3 changes: 3 additions & 0 deletions samples/react-application-personal-assistant/config/sass.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/core-build/sass.schema.json"
}
29 changes: 29 additions & 0 deletions samples/react-application-personal-assistant/config/serve.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/spfx-serve.schema.json",
"port": 4321,
"https": true,
"serveConfigurations": {
"default": {
"pageUrl": "https://{tenantDomain}/SitePages/myPage.aspx",
"customActions": {
"a4c9460d-77b2-4864-8fb7-183bf668c222": {
"location": "ClientSideExtension.ApplicationCustomizer",
"properties": {
"testMessage": "Test message"
}
}
}
},
"personalAssistant": {
"pageUrl": "https://{tenantDomain}/SitePages/myPage.aspx",
"customActions": {
"a4c9460d-77b2-4864-8fb7-183bf668c222": {
"location": "ClientSideExtension.ApplicationCustomizer",
"properties": {
"testMessage": "Test message"
}
}
}
}
}
}
Loading

0 comments on commit 98e6f1b

Please sign in to comment.