-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PowerPage][Copilot] Nl2Site and Nl2Page Service Integration for Site…
… Create (#1053) * Refactor PowerPagesChatParticipantConstants and add NL2PAGE and NL2SITE constants * Refactor PowerPagesChatParticipantConstants and add new page types * Update constants and move telemetry to different file * Refactor and add getCommonHeaders function --------- Co-authored-by: amitjoshi <[email protected]>
- Loading branch information
1 parent
7246c08
commit ff6059d
Showing
5 changed files
with
181 additions
and
19 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
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
22 changes: 22 additions & 0 deletions
22
src/common/chat-participants/powerpages/PowerPagesChatParticipantTelemetryConstants.ts
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,22 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_INVOKED = 'VSCodeExtensionGitHubPowerPagesAgentInvoked'; | ||
export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS = 'VSCodeExtensionGitHubPowerPagesAgentOrgDetails'; | ||
export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS_NOT_FOUND = 'VSCodeExtensionGitHubPowerPagesAgentOrgDetailsNotFound'; | ||
export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO = 'VSCodeExtensionGitHubPowerPagesAgentScenario'; | ||
export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO_FEEDBACK_THUMBSUP = 'VSCodeExtensionGitHubPowerPagesAgentScenarioFeedbackThumbsUp'; | ||
export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO_FEEDBACK_THUMBSDOWN = 'VSCodeExtensionGitHubPowerPagesAgentScenarioFeedbackThumbsDown'; | ||
export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ERROR = 'VSCodeExtensionGitHubPowerPagesAgentError'; | ||
export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_WEBPAGE_RELATED_FILES = 'VSCodeExtensionGitHubPowerPagesAgentWebpageRelatedFiles'; | ||
export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_LOCATION_REFERENCED = 'VSCodeExtensionGitHubPowerPagesAgentLocationReferenced'; | ||
export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_NO_PROMPT = 'VSCodeExtensionGitHubPowerPagesAgentNoPrompt'; | ||
export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_WELCOME_PROMPT = 'VSCodeExtensionGitHubPowerPagesAgentWelcomePrompt'; | ||
export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SUCCESSFUL_PROMPT = 'VSCodeExtensionGitHubPowerPagesAgentSuccessfulPrompt'; | ||
export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_NOT_AVAILABLE_ECS = 'VSCodeExtensionGitHubPowerPagesAgentNotAvailableECS'; | ||
export const VSCODE_EXTENSION_NL2PAGE_REQUEST_FAILED = 'VSCodeExtensionNL2PageRequestFailed'; | ||
export const VSCODE_EXTENSION_NL2PAGE_REQUEST_SUCCESS = 'VSCodeExtensionNL2PageRequestSuccess'; | ||
export const VSCODE_EXTENSION_NL2SITE_REQUEST_FAILED = 'VSCodeExtensionNL2SiteRequestFailed'; | ||
export const VSCODE_EXTENSION_NL2SITE_REQUEST_SUCCESS = 'VSCodeExtensionNL2SiteRequestSuccess'; |
91 changes: 91 additions & 0 deletions
91
src/common/chat-participants/powerpages/commands/create-site/Nl2PageService.ts
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,91 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
import { ITelemetry } from "../../../../OneDSLoggerTelemetry/telemetry/ITelemetry"; | ||
import { getCommonHeaders } from "../../../../services/AuthenticationProvider"; | ||
import { ABOUT_PAGE_TYPE, FAQ_PAGE_TYPE, HOME_PAGE_TYPE, INFO_PAGE_TYPE, NL2PAGE_GENERATE_NEW_PAGE, NL2PAGE_REQUEST_FAILED, NL2PAGE_SCENARIO, NL2PAGE_SCOPE} from "../../PowerPagesChatParticipantConstants"; | ||
import { VSCODE_EXTENSION_NL2PAGE_REQUEST_FAILED, VSCODE_EXTENSION_NL2PAGE_REQUEST_SUCCESS } from "../../PowerPagesChatParticipantTelemetryConstants"; | ||
|
||
export async function getNL2PageData(aibEndpoint: string, aibToken: string, userPrompt: string, siteName: string, sitePagesList: string[], sessionId: string, telemetry: ITelemetry) { | ||
|
||
const constructRequestBody = (pageType: string, colorNumber:number, exampleNumber: number) => ({ | ||
"crossGeoOptions": { | ||
"enableCrossGeoCall": true | ||
}, | ||
"question": `${userPrompt} - ${pageType} page`, | ||
"context": { | ||
"shouldCheckBlockList": false, | ||
"sessionId": sessionId, | ||
"scenario": NL2PAGE_SCENARIO, | ||
"subScenario": NL2PAGE_GENERATE_NEW_PAGE, | ||
"version": "V1", | ||
"information": { | ||
"scope": NL2PAGE_SCOPE, | ||
"includeImages": true, | ||
"pageType": pageType === 'FAQ' ? 'FAQ' : 'Home', //Verify if this is correct | ||
"title": siteName, | ||
"pageName": pageType, | ||
"colorNumber": colorNumber, | ||
"shuffleImages": false, | ||
"exampleNumber": exampleNumber | ||
} | ||
} | ||
}); | ||
|
||
const requests = sitePagesList.map(async pageType => { | ||
const colorNumber = generateRandomColorNumber(); | ||
const exampleNumber = generateRandomExampleNumber(pageType); | ||
const requestBody = constructRequestBody(pageType, colorNumber, exampleNumber); | ||
|
||
const requestInit: RequestInit = { | ||
method: "POST", | ||
headers: getCommonHeaders(aibToken), | ||
body: JSON.stringify(requestBody) | ||
}; | ||
|
||
try { | ||
const response = await fetch(aibEndpoint, requestInit); | ||
if (!response.ok) { | ||
throw new Error(`${NL2PAGE_REQUEST_FAILED} ${pageType}`); | ||
} | ||
|
||
const responseData = await response.json(); | ||
|
||
if (responseData && responseData.additionalData[0]) { | ||
return responseData.additionalData[0].snippets[0]; | ||
} | ||
return null; | ||
} catch (error) { | ||
telemetry.sendTelemetryErrorEvent(VSCODE_EXTENSION_NL2PAGE_REQUEST_FAILED, { error: (error as Error)?.message, pageType }); | ||
return null; | ||
} | ||
}); | ||
|
||
const responses = await Promise.all(requests); | ||
|
||
telemetry.sendTelemetryEvent(VSCODE_EXTENSION_NL2PAGE_REQUEST_SUCCESS, { sessionId }); | ||
|
||
// TODO: Home page is mandatory, so if it is not generated, return null | ||
return responses.filter(response => response !== null); | ||
} | ||
|
||
export const generateRandomColorNumber = () => { | ||
const colorNumbers = [1, 2, 3, 5, 6, 7, 8]; | ||
return colorNumbers[Math.floor(Math.random() * colorNumbers.length)]; | ||
}; | ||
|
||
export const generateRandomExampleNumber = (pageType: string) => { | ||
const isFaqOrAboutPage = pageType === FAQ_PAGE_TYPE || pageType === ABOUT_PAGE_TYPE; | ||
if (isFaqOrAboutPage) { | ||
return 0; | ||
} else if (pageType === HOME_PAGE_TYPE) { | ||
const homeExampleNumbers = [1, 2, 3, 4]; | ||
return homeExampleNumbers[Math.floor(Math.random() * homeExampleNumbers.length)]; | ||
} else if (pageType === INFO_PAGE_TYPE) { | ||
const infoExampleNumbers = [1, 2, 3]; | ||
return infoExampleNumbers[Math.floor(Math.random() * infoExampleNumbers.length)]; | ||
} | ||
return 0; | ||
}; |
54 changes: 54 additions & 0 deletions
54
src/common/chat-participants/powerpages/commands/create-site/Nl2SiteService.ts
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,54 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
import { ITelemetry } from "../../../../OneDSLoggerTelemetry/telemetry/ITelemetry"; | ||
import { NL2SITE_GENERATE_NEW_SITE, NL2SITE_INVALID_RESPONSE, NL2SITE_SCENARIO} from "../../PowerPagesChatParticipantConstants"; | ||
import { VSCODE_EXTENSION_NL2SITE_REQUEST_SUCCESS, VSCODE_EXTENSION_NL2SITE_REQUEST_FAILED } from "../../PowerPagesChatParticipantTelemetryConstants"; | ||
import { getCommonHeaders } from "../../../../services/AuthenticationProvider"; | ||
|
||
export async function getNL2SiteData(aibEndpoint: string, aibToken: string, userPrompt: string, sessionId: string, telemetry: ITelemetry) { | ||
const requestBody = { | ||
"crossGeoOptions": { | ||
"enableCrossGeoCall": true | ||
}, | ||
"question": userPrompt, | ||
"context": { | ||
"sessionId": sessionId, | ||
"scenario": NL2SITE_SCENARIO, | ||
"subScenario": NL2SITE_GENERATE_NEW_SITE, | ||
// "shouldCheckBlockList": false, //TODO: Check if this is needed | ||
"version": "V1", | ||
"information": { | ||
"minPages": 7, | ||
"maxPages": 7 | ||
} | ||
} | ||
}; | ||
|
||
const requestInit: RequestInit = { | ||
method: "POST", | ||
headers: getCommonHeaders(aibToken), | ||
body: JSON.stringify(requestBody) | ||
}; | ||
|
||
try { | ||
const response = await fetch(aibEndpoint, requestInit); | ||
if (!response.ok) { | ||
throw new Error(`${response.statusText} - ${response.status}`); | ||
} | ||
|
||
const responseBody = await response.json(); | ||
|
||
if (responseBody && responseBody.additionalData[0]?.website) { | ||
telemetry.sendTelemetryEvent(VSCODE_EXTENSION_NL2SITE_REQUEST_SUCCESS, {sessionId: sessionId}); | ||
return responseBody.additionalData[0].website; // Contains the pages, siteName & site description | ||
} else { | ||
throw new Error(NL2SITE_INVALID_RESPONSE); | ||
} | ||
} catch (error) { | ||
telemetry.sendTelemetryErrorEvent(VSCODE_EXTENSION_NL2SITE_REQUEST_FAILED, { error: (error as Error)?.message }); | ||
return null; | ||
} | ||
} |