Skip to content

Commit

Permalink
feat(ai-help): release 2.0 (#10155)
Browse files Browse the repository at this point in the history
Frontend changes for AI Help 2.0, see also: mdn/rumba#373.

Notable changes:

- New feature: History.
- New feature: Message tree.
- New feature: Playground integration.
- Improvement: Enhanced context.
- Improvement: New refined prompt.
- Improvement: Upgrade from GPT-3.5 to GPT-4.

Co-authored-by: Florian Dieminger <me@fiji-flo.de>
Co-authored-by: Leo McArdle <lmcardle@mozilla.com>
  • Loading branch information
3 people authored Dec 14, 2023
1 parent 7b79d32 commit 427b2fc
Show file tree
Hide file tree
Showing 93 changed files with 4,261 additions and 847 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/prod-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ jobs:
--min-instances=10 \
--max-instances=1000 \
--memory=2GB \
--timeout=60s \
--timeout=120s \
--set-env-vars="ORIGIN_MAIN=developer.mozilla.org" \
--set-env-vars="ORIGIN_LIVE_SAMPLES=live.mdnplay.dev" \
--set-env-vars="ORIGIN_PLAY=mdnplay.dev" \
Expand Down Expand Up @@ -380,6 +380,13 @@ jobs:
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}

- name: Update AI Help index with macros
run: yarn ai-help-macros update-index
env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}

- name: Slack Notification
if: failure()
uses: rtCamp/action-slack-notify@v2
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/stage-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ jobs:
--min-instances=1 \
--max-instances=100 \
--memory=2GB \
--timeout=60s \
--timeout=120s \
--set-env-vars="ORIGIN_MAIN=developer.allizom.org" \
--set-env-vars="ORIGIN_LIVE_SAMPLES=live.mdnyalp.dev" \
--set-env-vars="ORIGIN_PLAY=mdnyalp.dev" \
Expand Down Expand Up @@ -373,6 +373,13 @@ jobs:
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}

- name: Update AI Help index with macros
run: yarn ai-help-macros update-index
env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}

- name: Slack Notification
if: failure()
uses: rtCamp/action-slack-notify@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/xyz-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ jobs:
--min-instances=1 \
--max-instances=100 \
--memory=2GB \
--timeout=60s \
--timeout=120s \
--set-env-vars="ORIGIN_MAIN=developer.allizom.xyz" \
--set-env-vars="ORIGIN_LIVE_SAMPLES=live-samples.developer.allizom.xyz" \
--set-env-vars="SOURCE_CONTENT=https://storage.googleapis.com/${{ vars.GCP_BUCKET_NAME }}/main/" \
Expand Down
12 changes: 10 additions & 2 deletions build/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ async function buildDocumentInteractive(
);
}

return { document, doc: await buildDocument(document), skip: false };
return {
document,
doc: await buildDocument(document, { plainHTML: true }),
skip: false,
};
} catch (e) {
if (!interactive) {
throw e;
Expand Down Expand Up @@ -208,7 +212,7 @@ async function buildDocuments(
}

const {
doc: { doc: builtDocument, liveSamples, fileAttachmentMap },
doc: { doc: builtDocument, liveSamples, fileAttachmentMap, plainHTML },
document,
} = result;

Expand All @@ -230,6 +234,10 @@ async function buildDocuments(
);
}

if (plainHTML) {
fs.writeFileSync(path.join(outPath, "plain.html"), plainHTML);
}

// This is exploiting the fact that renderHTML has the side-effect of
// mutating the built document which makes this not great and refactor-worthy.
const docString = JSON.stringify({ doc: builtDocument });
Expand Down
10 changes: 9 additions & 1 deletion build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,15 @@ export interface BuiltDocument {
source?: {
github_url: string;
};
plainHTML?: string;
}

interface DocumentOptions {
fixFlaws?: boolean;
fixFlawsDryRun?: boolean;
fixFlawsTypes?: Iterable<string>;
fixFlawsVerbose?: boolean;
plainHTML?: boolean;
}

export async function buildDocument(
Expand Down Expand Up @@ -445,6 +447,12 @@ export async function buildDocument(
throw error;
}

// Dump HTML for GPT context.
let plainHTML;
if (documentOptions.plainHTML) {
plainHTML = $.html();
}

// Apply syntax highlighting all <pre> tags.
syntaxHighlight($, doc);

Expand Down Expand Up @@ -555,7 +563,7 @@ export async function buildDocument(
document.metadata.slug.startsWith("orphaned/") ||
document.metadata.slug.startsWith("conflicting/");

return { doc: doc as Doc, liveSamples, fileAttachmentMap };
return { doc: doc as Doc, liveSamples, fileAttachmentMap, plainHTML };
}

function addBaseline(doc: Partial<Doc>) {
Expand Down
4 changes: 2 additions & 2 deletions build/resolve-bcd.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import bcdUntyped from "@mdn/browser-compat-data/forLegacyNode";
import { CompatData } from "@mdn/browser-compat-data/types";
import { CompatData, Identifier } from "@mdn/browser-compat-data/types";

const bcd = bcdUntyped as CompatData;

export function packageBCD(query) {
const data = query.split(".").reduce((prev, curr) => {
const data: Identifier = query.split(".").reduce((prev, curr) => {
return prev && Object.prototype.hasOwnProperty.call(prev, curr)
? prev[curr]
: undefined;
Expand Down
2 changes: 1 addition & 1 deletion build/syntax-highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function syntaxHighlight($: cheerio.CheerioAPI, doc) {
$pre.wrapAll(`<div class='code-example'></div>`);
if (!$pre.hasClass("hidden")) {
$(
`<p class='example-header'><span class="language-name">${name}</span></p>`
`<div class='example-header'><span class="language-name">${name}</span></div>`
).insertBefore($pre);
}
const grammar = Prism.languages[name];
Expand Down
Binary file added client/public/assets/ai-help/ai-help_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/public/assets/ai-help/ai-help_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/public/assets/ai-help/context.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/public/assets/ai-help/gpt-4.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/public/assets/ai-help/history.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions client/public/assets/ai-help/lightbulb-question.svg
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.
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 removed client/public/assets/plus-docs/ai-help/context.png
Binary file not shown.
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.
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.
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 removed client/public/assets/plus-docs/ai-help/sources.png
Binary file not shown.
1 change: 1 addition & 0 deletions client/src/assets/icons/ai-help.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions client/src/assets/icons/bell-ring.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/src/assets/icons/edit-filled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions client/src/assets/icons/highlight.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions client/src/assets/icons/history.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions client/src/assets/icons/message.svg
3 changes: 3 additions & 0 deletions client/src/assets/icons/new-topic.svg
4 changes: 4 additions & 0 deletions client/src/assets/icons/play.svg
Loading

0 comments on commit 427b2fc

Please sign in to comment.