-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## 🎯 Aim The aim is to add a preview feature with SPFx chat participant ## 📷 Result ![chat-intro](https://github.com/pnp/vscode-viva/assets/58668583/e4166cfc-b200-4563-88c9-a53f09add7f1) ## ✅ What was done - [X] Added chat participant ## 🔗 Related issue Related: #239
- Loading branch information
Showing
12 changed files
with
38,738 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import * as vscode from 'vscode'; | ||
import { Commands, promptActionContext, promptCodeContext, promptContext, promptNewContext, promptSetupContext } from '../constants'; | ||
|
||
const MODEL_SELECTOR: vscode.LanguageModelChatSelector = { vendor: 'copilot', family: 'gpt-4' }; | ||
|
||
export class PromptHandlers { | ||
|
||
public static async handle(request: vscode.ChatRequest, context: vscode.ChatContext, stream: vscode.ChatResponseStream, token: vscode.CancellationToken): Promise<any> { | ||
stream.progress(PromptHandlers.getRandomProgressMessage()); | ||
const chatCommand = (request.command && ['setup', 'new', 'code', 'action'].indexOf(request.command) > -1) ? request.command : ''; | ||
|
||
const messages = [vscode.LanguageModelChatMessage.User(promptContext)]; | ||
messages.push(vscode.LanguageModelChatMessage.User(PromptHandlers.getChatCommandPrompt(chatCommand))); | ||
messages.push(vscode.LanguageModelChatMessage.User(request.prompt)); | ||
const [model] = await vscode.lm.selectChatModels(MODEL_SELECTOR); | ||
try { | ||
const chatResponse = await model.sendRequest(messages, {}, token); | ||
for await (const fragment of chatResponse.text) { | ||
stream.markdown(fragment); | ||
} | ||
PromptHandlers.getChatCommandButtons(chatCommand).forEach(button => stream.button(button)); | ||
return { metadata: { command: chatCommand } }; | ||
} catch (err) { | ||
stream.markdown('...It seems that something is not working as expected. Please try again later.'); | ||
return { metadata: { command: '' } }; | ||
} | ||
} | ||
|
||
private static getChatCommandButtons(chatCommand: string) { | ||
switch (chatCommand) { | ||
case 'setup': | ||
return [{ | ||
command: Commands.checkDependencies, | ||
title: vscode.l10n.t('Check if my local workspace is ready'), | ||
}, | ||
{ | ||
command: Commands.installDependencies, | ||
title: vscode.l10n.t('Install required dependencies'), | ||
}]; | ||
case 'new': | ||
return [{ | ||
command: Commands.createProject, | ||
title: vscode.l10n.t('Create a new project'), | ||
}, | ||
{ | ||
command: Commands.samplesGallery, | ||
title: vscode.l10n.t('View samples'), | ||
}]; | ||
case 'code': | ||
return []; | ||
case 'action': | ||
return [{ | ||
command: Commands.upgradeProject, | ||
title: vscode.l10n.t('Get upgrade guidance to latest SPFx version'), | ||
}, | ||
{ | ||
command: Commands.validateProject, | ||
title: vscode.l10n.t('Validate your project'), | ||
}, | ||
{ | ||
command: Commands.renameProject, | ||
title: vscode.l10n.t('Rename your project'), | ||
}, | ||
{ | ||
command: Commands.pipeline, | ||
title: vscode.l10n.t('Create a CI/CD workflow'), | ||
}]; | ||
default: | ||
return []; | ||
} | ||
} | ||
|
||
private static getChatCommandPrompt(chatCommand: string): string { | ||
switch (chatCommand) { | ||
case 'setup': | ||
return promptSetupContext; | ||
case 'new': | ||
return promptNewContext; | ||
case 'code': | ||
return promptCodeContext; | ||
case 'action': | ||
return promptActionContext; | ||
default: | ||
return ''; | ||
} | ||
} | ||
|
||
private static getRandomProgressMessage(): string { | ||
const messages = [ | ||
'Checking...', | ||
'Let me think about it...', | ||
'Reading the docs...', | ||
'Cracking the code...', | ||
'Unleashing the algorithms...', | ||
'Beaming up the data...', | ||
'Feeding the hamsters...', | ||
'Charging the flux capacitor...', | ||
'Warming up the servers...', | ||
'Consulting with the rubber duck...', | ||
'Asking the magic 8-ball...', | ||
'Counting backwards from infinity...', | ||
'Commencing time travel...', | ||
'Converting coffee to code...', | ||
'Adjusting the reality matrix...', | ||
'Waking up the AI...' | ||
]; | ||
return messages[Math.floor(Math.random() * messages.length)]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const EXTENSION_NAME = 'spfx-toolkit'; | ||
export const EXTENSION_NAME = 'spfx-toolkit'; | ||
export const CHAT_PARTICIPANT_NAME = 'spfx-toolkit.pnp'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
export const personality = 'You are a kind and helpful assistant named SPFx Toolkit.'; | ||
|
||
export const aim = 'You aim to provide support in coding and managing SharePoint Framework (SPFx) solutions.'; | ||
|
||
export const msLearnLink = 'learn.microsoft.com'; | ||
export const msSampleGalleryLink = 'https://adoption.microsoft.com/en-us/sample-solution-gallery/'; | ||
export const msLinks = `${msLearnLink}, ${msSampleGalleryLink}`; | ||
|
||
export const spfxOverviewLink = 'https://learn.microsoft.com/en-us/sharepoint/dev/spfx/sharepoint-framework-overview'; | ||
export const spfxSetupLink = 'https://learn.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-development-environment'; | ||
export const spfxWebPartLink = 'https://learn.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/overview-client-side-web-parts'; | ||
export const spfxExtensionLink = 'https://learn.microsoft.com/en-us/sharepoint/dev/spfx/extensions/overview-extensions'; | ||
export const spfxLibraryLink = 'https://learn.microsoft.com/en-us/sharepoint/dev/spfx/library-component-overview'; | ||
export const spfxApiLink = 'https://learn.microsoft.com/en-us/javascript/api/overview/sharepoint?view=sp-typescript-latest'; | ||
export const spfxGuideLink = 'https://learn.microsoft.com/en-us/sharepoint/dev/spfx/enterprise-guidance'; | ||
export const spfxVivaLink = 'https://learn.microsoft.com/en-us/sharepoint/dev/spfx/viva/overview-viva-connections'; | ||
export const spfxLinks = `${spfxOverviewLink}, ${spfxSetupLink}, ${spfxWebPartLink}, ${spfxExtensionLink}, ${spfxLibraryLink}, ${spfxApiLink}, ${spfxGuideLink}, ${spfxVivaLink}`; | ||
|
||
export const pnpCommunityHomePageLink = 'https://pnp.github.io/'; | ||
export const pnpSpfxSamplesLink = 'https://pnp.github.io/sp-dev-fx-webparts/'; | ||
export const pnpCliM365Link = 'https://pnp.github.io/cli-microsoft365/'; | ||
export const pnpPSLink = 'https://pnp.github.io/powershell/'; | ||
export const pnpReactControlsLink = 'https://pnp.github.io/sp-dev-fx-controls-react/'; | ||
export const pnpPropertyPaneControlsLink = 'https://pnp.github.io/sp-dev-fx-property-controls/'; | ||
export const pnpLinks = `${pnpCommunityHomePageLink}, ${pnpSpfxSamplesLink}, ${pnpCliM365Link}, ${pnpPSLink}, ${pnpReactControlsLink}, ${pnpPropertyPaneControlsLink}`; | ||
|
||
export const spfxSnippetsLink = 'https://marketplace.visualstudio.com/items?itemName=eliostruyf.spfx-snippets'; | ||
|
||
export const references = `You will be using the following documentation as references: ${msLinks}, ${spfxLinks}, ${pnpLinks}`; | ||
|
||
export const community = `You will promote the Microsoft 365 & Power Platform community: ${pnpCommunityHomePageLink}.`; | ||
|
||
export const boundary = 'When returning code you will surround it in a MD code block, not HTML.'; | ||
|
||
export const promptContext = `${personality}${aim}${community}${references}${boundary}`; | ||
|
||
export const promptSetupContext = 'You aim to provide support in setting up your development environment for SharePoint Framework (SPFx) development by suggesting the correct version of Node.js and required dependencies.'; | ||
|
||
export const promptNewContext = `You aim to provide support in creating a new SharePoint Framework project by suggesting the scaffolding form in SPFx Toolkit VS Code extension or by suggesting one of the samples from the ${pnpSpfxSamplesLink}.`; | ||
|
||
export const promptCodeContext = `You aim to provide support in writting code for SharePoint Framework (SPFx) solutions by suggesting the correct coding practices or spfx snippets that may be used from ${spfxSnippetsLink}. You will always provide coding sample for a given prompt.`; | ||
|
||
export const promptActionContext = 'You aim to provide support additional help in managing your SharePoint Framework (SPFx) solutions. Providing guidance how to create an upgrade or validate report or how to create a CI/CD pipeline for your project using SPFx Toolkit VS Code features.'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.