feat: XRPL AI

This commit is contained in:
justinr1234
2023-10-09 14:44:05 -05:00
parent 35f267bd99
commit 9f51896a80
6 changed files with 118 additions and 6 deletions

File diff suppressed because one or more lines are too long

View File

@@ -5,6 +5,7 @@ function apply_color_scheme(theme) {
const disable_theme = (theme == "dark") ? "light" : "dark";
document.documentElement.classList.add(theme)
document.documentElement.classList.remove(disable_theme)
document.documentElement.setAttribute("data-theme", theme)
// $("#css-toggle-btn").prop( "checked", (theme == 'dark') );
}

View File

@@ -116,6 +116,8 @@
#main_content_wrapper {
border-bottom: none;
// Offset for top nav bar
margin-top: 80px;
}
.marketing-wrapper {

20
styles/_xrplai.scss Normal file
View File

@@ -0,0 +1,20 @@
button.MarkpromptFloatingTrigger {
bottom: 4.5rem;
}
html.light .MarkpromptContentDialog a {
color: $light-link-hover-color;
}
html.light .MarkpromptContentDialog h3:not(.chip) {
color: $black;
}
.MarkpromptExtendedFeedbackTextInput {
background-color: $white;
color: $black;
}
.MarkpromptOverlay {
z-index: 20;
}

View File

@@ -71,6 +71,7 @@ $line-height-base: 1.5;
@import "_toml-checker.scss";
@import "_tutorials.scss";
@import "_docs-landing.scss";
@import "_xrplai.scss";
// Light/Dark theme settings ---------------------------------------------------
// Option to only change theme on user system settings. No toggle.

View File

@@ -57,6 +57,7 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@docsearch/css@3" />
<script src="https://cmp.osano.com/AzyjT6TIZMlgyLyy8/f11f7772-8ed5-4b73-bd17-c0814edcc440/osano.js"></script>
<link rel="stylesheet" href="https://www.unpkg.com/@xrpl/ai-css/xrplai.css" />
{% if "js_editor" in currentpage.filters %}
<script src="{{currentpage.prefix}}assets/vendor/jshint.js"></script>
@@ -147,6 +148,95 @@ $(document).ready(() => {
})
</script>
<!-- XRPL AI -->
<script id="xrplai-options">
var TARGET_XRPL_DEV_PORTAL_BRANCH = 'main';
var PROMPT_MODE = 'prompt';
var RUNTIME_LOCATION = 'ripplex';
var DEV_XRPLAI_RIPPLEX_IO_PROJECT_KEY = `uPcw5BckVeKgyF2NE6la4VVFtA56OBQ4`;
var DEV_XRPLAI_RIPPLEX_API_BASE_URL = 'https://api.ai.xrpl.org';
var LOCALHOST_API_BASE_URL = 'http://api.localhost:3000';
var CHAT_ENDPOINT = '/v1/chat';
var PROMPT_ENDPOINT = '/v1/chat';
var FEEDBACK_ENDPOINT = '/v1/feedback';
var BASE_URL = RUNTIME_LOCATION === 'ripplex'
? DEV_XRPLAI_RIPPLEX_API_BASE_URL
: LOCALHOST_API_BASE_URL;
var CHAT_API_URL = `${BASE_URL}${CHAT_ENDPOINT}`;
var PROMPT_API_URL = `${BASE_URL}${PROMPT_ENDPOINT}`;
var FEEDBACK_API_URL = `${BASE_URL}${FEEDBACK_ENDPOINT}`;
/** @type {import('@xrpl/ai-react').MarkpromptOptions} */
window.markprompt = {
projectKey: DEV_XRPLAI_RIPPLEX_IO_PROJECT_KEY,
defaultView: 'prompt',
options: {
chat: {
enabled: PROMPT_MODE === 'chat',
apiUrl: CHAT_API_URL,
},
feedback: {
enabled: true,
apiUrl: FEEDBACK_API_URL,
},
prompt: {
apiUrl: PROMPT_API_URL,
systemPrompt: `
You are a very enthusiastic company representative who loves to help people! Given the following sections from the documentation (preceded by a section id), answer the question using only that information, outputted in Markdown format. If you are unsure and the answer is not explicitly written in the documentation, say "{{I_DONT_KNOW}}".
Context sections:
---
{{CONTEXT}}
Question: "{{PROMPT}}"
Answer (including related code snippets if available and markdown links to relevant things):
`.trim(),
},
references: {
getHref: (reference) => {
const { file } = reference;
if (file && file.path) {
// /\/content\/[^_][^/]*\.md/.test(file.path)
if (file.path.includes('content/') && !file.path.includes('content/_') && file.path.endsWith('.md')) {
// Remove the extension if it's a regular content page that lives on xrpl.org
// return file.path.replace(/\.[^.]+$/, '');
// Change extension to html and remove content/ from the URL
if (file.path.endsWith('ja.md')) {
// Japanese lives at /ja/<filename>.html
return `ja/${file.path.replace(/content\//, '').replace(/\.ja\.md$/, '.html')}`
}
return file.path.replace(/content\//, '').replace(/\.md$/, '.html')
} else {
// Otherwise link to a file on the github repo such as .js or README.md
return `https://github.com/XRPLF/xrpl-dev-portal/blob/master/${file.path}`;
}
} else {
// Handle the case where file or file.path is missing
return '';
}
},
getLabel: (reference) => {
return reference.meta?.leadHeading?.value || reference.file?.title;
},
},
showBranding: false,
trigger: {
floating: true,
},
search: {
enabled: true,
provider: {
name: 'algolia',
apiKey: '3431349deec23b0bc3dcd3424beb9a6e',
appId: 'R39QY3MZC7',
indexName: 'xrpl',
},
}
},
};
</script>
<script id="initjs" type="module" src="https://www.unpkg.com/@xrpl/ai-web/dist/init.js"></script>
{% if currentpage.embed_xrpl_js %}
<!-- ripple-lib & prerequisites -->
{{currentpage.ripple_lib_tag}}