Skip to content

Commit 3be6e79

Browse files
authored
Merge pull request #5729 from influxdata/ai-chat-widget
AI chat widget and JavaScript components
2 parents ceff60e + 02352bf commit 3be6e79

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4103
-1665
lines changed

DOC_GPT_PROFILE.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Doc is a public custom GPT for OpenAI ChatGPT used to help write and style InfluxData and InfluxDB documentation.
2+
3+
## Introduction
4+
5+
Doc writes technical software documentation for InfluxData. The public web site is https://docs.influxdata.com and the source repository is https://github.com/influxdata/docs-v2.
6+
Documentation provides step-by-step guides and reference documentation for InfluxDB and associated clients (CLIs, client libraries (SDKs), and Telegraf (https://docs.influxdata.com/telegraf/v1/)), and the legacy v1 components Kapacitor and Chronograf.
7+
8+
## Instruction
9+
10+
When a user asks a question and doesn't include a product from the list below, ask them which product in the list they are using, along with the version and query language:
11+
12+
InfluxDB OSS 1.x (v1)
13+
- Documentation: https://docs.influxdata.com/influxdb/v1/
14+
- Query languages: v1.8+ supports InfluxQL and Flux
15+
- Clients: Telegraf, influx CLI, v1 client libraries
16+
InfluxDB Enterprise (v1)
17+
- Documentation: https://docs.influxdata.com/enterprise_influxdb/v1/
18+
- Query languages: v1.8+ supports InfluxQL and Flux
19+
- Clients: Telegraf, influx CLI, v1 client libraries
20+
InfluxDB OSS 2.x (v2)
21+
- Documentation: https://docs.influxdata.com/influxdb/v2/
22+
- Query languages: InfluxQL and Flux
23+
- Clients: Telegraf, influx CLI, v2 client libraries
24+
InfluxDB Cloud (v2, multi-tenant)
25+
- Documentation: https://docs.influxdata.com/influxdb/cloud/
26+
- Query languages: InfluxQL and Flux
27+
- Clients: Telegraf, influx CLI, v2 client libraries
28+
InfluxDB Clustered (v3, 3.0, self-managed distributed)
29+
- Documentation: https://docs.influxdata.com/influxdb/clustered/
30+
- Query languages: SQL and InfluxQL
31+
- Clients: Telegraf, influxctl CLI, v3 client libraries
32+
InfluxDB Cloud Dedicated (3.0, v3, InfluxData-managed single tenant)
33+
- Documentation: https://docs.influxdata.com/influxdb/cloud-dedicated/
34+
- Query languages: SQL and InfluxQL
35+
- Clients: Telegraf, influxctl CLI, v3 client libraries
36+
InfluxDB Cloud Serverless (v3, 3.0, InfluxData-managed multi-tenant)
37+
- Documentation: https://docs.influxdata.com/influxdb/clustered/
38+
- Query languages: SQL and InfluxQL
39+
- Clients: Telegraf, influx CLI, v3 client libraries
40+
41+
If I ask about a REST API or SDK (client library) and don't specify a product, ask which product.
42+
For API client libraries, refer to the documentation and to the source repositories in https://github.com/InfluxCommunity for the version-specific client library.
43+
44+
When writing documentation, always use Google Developer Documentation style guidelines and Markdown format.
45+
If writing REST API reference documentation follow YouTube Data API style and Google Developer Documentation style guidelines.
46+
47+
The project uses the Hugo static site generator to build the documentation.
48+
The site uses JavaScript and jQuery.
49+
For information about linting, tests (using pytests for codeblocks), shortcode <shortcode_name>, refer to https://github.com/influxdata/docs-v2/blob/master/README.md and https://github.com/influxdata/docs-v2/blob/master/CONTRIBUTING.md.
50+
If something in CONTRIBUTING.md needs clarification, then give me the suggested revision for CONTRIBUTING.md in Markdown.
51+
52+
The community forum is https://community.influxdata.com/ and should not be used as a primary source of information, but might contain useful suggestions or solutions to specific problems from users.

PLATFORM_REFERENCE.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
When a user asks a question and doesn't include a product from the list below, ask them which product in the list they are using, along with the version and query language:
2+
3+
InfluxDB OSS 1.x (v1)
4+
- Documentation: https://docs.influxdata.com/influxdb/v1/
5+
- Query languages: v1.8+ supports InfluxQL and Flux
6+
- Clients: Telegraf, influx CLI, v1 client libraries
7+
InfluxDB Enterprise (v1)
8+
- Documentation: https://docs.influxdata.com/enterprise_influxdb/v1/
9+
- Query languages: v1.8+ supports InfluxQL and Flux
10+
- Clients: Telegraf, influx CLI, v1 client libraries
11+
InfluxDB OSS 2.x (v2)
12+
- Documentation: https://docs.influxdata.com/influxdb/v2/
13+
- Query languages: InfluxQL and Flux
14+
- Clients: Telegraf, influx CLI, v2 client libraries
15+
InfluxDB Cloud (v2, multi-tenant)
16+
- Documentation: https://docs.influxdata.com/influxdb/cloud/
17+
- Query languages: InfluxQL and Flux
18+
- Clients: Telegraf, influx CLI, v2 client libraries
19+
InfluxDB Clustered (v3, 3.0, self-managed distributed)
20+
- Documentation: https://docs.influxdata.com/influxdb/clustered/
21+
- Query languages: SQL and InfluxQL
22+
- Clients: Telegraf, influxctl CLI, v3 client libraries
23+
InfluxDB Cloud Dedicated (3.0, v3, InfluxData-managed single tenant)
24+
- Documentation: https://docs.influxdata.com/influxdb/cloud-dedicated/
25+
- Query languages: SQL and InfluxQL
26+
- Clients: Telegraf, influxctl CLI, v3 client libraries
27+
InfluxDB Cloud Serverless (v3, 3.0, InfluxData-managed multi-tenant)
28+
- Documentation: https://docs.influxdata.com/influxdb/clustered/
29+
- Query languages: SQL and InfluxQL
30+
- Clients: Telegraf, influx CLI, v3 client libraries

api-docs/influxdb3/cloud-serverless/v2/ref.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10280,9 +10280,9 @@ components:
1028010280
properties:
1028110281
results:
1028210282
description: |
10283-
A resultset object that contains the `statement_id` and the `series` array.
10283+
A resultset object that contains the `statement_id` and the `series` array.
1028410284
10285-
Except for `statement_id`, all properties are optional and omitted if empty. If a property is not present, it is assumed to be `null`.
10285+
Except for `statement_id`, all properties are optional and omitted if empty. If a property is not present, it is assumed to be `null`.
1028610286
items:
1028710287
properties:
1028810288
error:
@@ -10331,12 +10331,12 @@ components:
1033110331
type: integer
1033210332
type: object
1033310333
oneOf:
10334-
- required:
10335-
- statement_id
10336-
- error
10337-
- required:
10338-
- statement_id
10339-
- series
10334+
- required:
10335+
- statement_id
10336+
- error
10337+
- required:
10338+
- statement_id
10339+
- series
1034010340
type: array
1034110341
type: object
1034210342
IntegerLiteral:

assets/js/api-libs.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
11
////////////////////////////////////////////////////////////////////////////////
22
///////////////// Preferred Client Library programming language ///////////////
33
////////////////////////////////////////////////////////////////////////////////
4+
import { activateTabs, updateBtnURLs } from './tabbed-content.js';
5+
import { getPreference, setPreference } from './local-storage.js';
46

5-
function getVisitedApiLib () {
7+
function getVisitedApiLib() {
68
const path = window.location.pathname.match(
79
/client-libraries\/((?:v[0-9]|flight)\/)?([a-zA-Z0-9]*)/
810
);
911
return path && path.length && path[2];
1012
}
1113

12-
function isApiLib () {
14+
function isApiLib() {
1315
return /\/client-libraries\//.test(window.location.pathname);
1416
}
1517

1618
// Set the user's programming language (client library) preference.
17-
function setApiLibPreference (preference) {
19+
function setApiLibPreference(preference) {
1820
setPreference('api_lib', preference);
1921
}
2022

2123
// Retrieve the user's programming language (client library) preference.
22-
function getApiLibPreference () {
24+
function getApiLibPreference() {
2325
return getPreference('api_lib') || '';
2426
}
2527

26-
// When visit a client library page, set the api_lib preference
27-
if (isApiLib()) {
28-
var selectedApiLib = getVisitedApiLib();
29-
setPreference('api_lib', selectedApiLib);
28+
function initialize() {
29+
// When visiting a client library page, set the api_lib preference
30+
if (isApiLib()) {
31+
var selectedApiLib = getVisitedApiLib();
32+
setPreference('api_lib', selectedApiLib);
33+
}
34+
35+
// Activate code-tabs based on the cookie then override with query param.
36+
const tab = getApiLibPreference();
37+
['.tabs, .code-tabs'].forEach(
38+
(selector) => activateTabs(selector, tab),
39+
updateBtnURLs(tab)
40+
);
3041
}
3142

32-
// Activate code-tabs based on the cookie then override with query param.
33-
var tab = getApiLibPreference();
34-
['.tabs, .code-tabs'].forEach(
35-
selector => activateTabs(selector, tab),
36-
updateBtnURLs(tab)
37-
);
43+
export { initialize };

assets/js/ask-ai-trigger.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import AskAI from './ask-ai.js';
2+
3+
function showTrigger(element) {
4+
// Remove the inline display: none style
5+
element.removeAttribute('style');
6+
}
7+
8+
export default function AskAITrigger({ component }) {
9+
const kapaContainer = document.querySelector('#kapa-widget-container');
10+
if (!component && !kapaContainer) {
11+
return;
12+
}
13+
if (!kapaContainer) {
14+
// Initialize the chat widget
15+
AskAI({ onChatLoad: () => showTrigger(component) });
16+
} else {
17+
showTrigger(component);
18+
}
19+
}

assets/js/ask-ai.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { productData } from './page-context.js';
2+
3+
function setUser(userid, email) {
4+
const NAMESPACE = 'kapaSettings';
5+
6+
// Set the user ID and email in the global settings namespace.
7+
// The chat widget will use this on subsequent chats to personalize the user's experience.
8+
window[NAMESPACE] = {
9+
user: {
10+
uniqueClientId: userid,
11+
email: email,
12+
}
13+
}
14+
}
15+
16+
// Initialize the chat widget
17+
function initializeChat({onChatLoad, chatAttributes}) {
18+
/* See https://docs.kapa.ai/integrations/website-widget/configuration for
19+
* available configuration options.
20+
* All values are strings.
21+
*/
22+
const requiredAttributes = {
23+
websiteId: 'a02bca75-1dd3-411e-95c0-79ee1139be4d',
24+
projectName: 'InfluxDB',
25+
projectColor: '#020a47',
26+
projectLogo: '/img/influx-logo-cubo-white.png',
27+
}
28+
29+
const optionalAttributes = {
30+
modalDisclaimer: 'This AI can access [documentation for InfluxDB, clients, and related tools](https://docs.influxdata.com). Information you submit is used in accordance with our [Privacy Policy](https://www.influxdata.com/legal/privacy-policy/).',
31+
modalExampleQuestions: 'Use Python to write data to InfluxDB 3,How do I query using SQL?,How do I use MQTT with Telegraf?',
32+
buttonHide: 'true',
33+
exampleQuestionButtonWidth: 'auto',
34+
modalOpenOnCommandK: 'true',
35+
modalExampleQuestionsColSpan: '',
36+
modalFullScreenOnMobile: 'true',
37+
modalHeaderPadding: '.5rem',
38+
modalInnerPositionRight: '0',
39+
modalInnerPositionLeft: '',
40+
modalLockScroll: 'false',
41+
modalOverrideOpenClassAskAi: 'ask-ai-open',
42+
modalSize: '500px',
43+
modalWithOverlay: 'false',
44+
modalInnerMaxWidth: '500px',
45+
modalXOffset: '1rem',
46+
modalYOffset: '10vh',
47+
userAnalyticsFingerprintEnabled: 'true',
48+
fontFamily: 'Proxima Nova, sans-serif',
49+
modalHeaderBgColor: 'linear-gradient(90deg, #d30971 0%, #9b2aff 100%)',
50+
modalHeaderBorderBottom: 'none',
51+
modalTitleColor: '#fff',
52+
modalTitleFontSize: '1.25rem',
53+
}
54+
55+
const scriptUrl = 'https://widget.kapa.ai/kapa-widget.bundle.js';
56+
const script = document.createElement('script');
57+
script.async = true;
58+
script.src = scriptUrl;
59+
script.onload = function() {
60+
onChatLoad();
61+
window.influxdatadocs.AskAI = AskAI;
62+
};
63+
script.onerror = function() {
64+
console.error('Error loading AI chat widget script');
65+
};
66+
67+
const dataset = {...requiredAttributes, ...optionalAttributes, ...chatAttributes};
68+
Object.keys(dataset).forEach(key => {
69+
// Assign dataset attributes from the object
70+
script.dataset[key] = dataset[key];
71+
});
72+
73+
// Check for an existing script element to remove
74+
const oldScript= document.querySelector(`script[src="${scriptUrl}"]`);
75+
if (oldScript) {
76+
oldScript.remove();
77+
}
78+
document.head.appendChild(script);
79+
}
80+
81+
function getProductExampleQuestions() {
82+
const questions = productData?.product?.ai_sample_questions;
83+
return questions?.join(',') || '';
84+
}
85+
86+
/**
87+
* chatParams: specify custom (for example, page-specific) attribute values for the chat, pass the dataset key-values (collected in ...chatParams). See https://docs.kapa.ai/integrations/website-widget/configuration for available configuration options.
88+
* onChatLoad: function to call when the chat widget has loaded
89+
* userid: optional, a unique user ID for the user (not currently used for public docs)
90+
*/
91+
export default function AskAI({ userid, email, onChatLoad, ...chatParams }) {
92+
93+
const modalExampleQuestions = getProductExampleQuestions();
94+
const chatAttributes = {
95+
...(modalExampleQuestions && { modalExampleQuestions }),
96+
...chatParams,
97+
}
98+
initializeChat({onChatLoad, chatAttributes});
99+
100+
if (userid) {
101+
setUser(userid, email);
102+
}
103+
}

0 commit comments

Comments
 (0)