Skip to content

Commit cbfcadc

Browse files
onceLearnerestherk15
authored andcommitted
feat(docs-ai): shuffle suggestion questions (#36348)
* feat: shuffle suggestion questions * chore: refactor
1 parent 62a000e commit cbfcadc

3 files changed

Lines changed: 52 additions & 3 deletions

File tree

assets/scripts/components/conversational-search/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { attachTooltips, buildSourceCards, showSourceTooltip, closeAllSourceTool
77
import { addMessageActions, injectCodeCopyButtons } from './actions';
88
import { streamConversation, fetchConversation, resetTypesenseClient } from './streaming';
99
import { streamDocsAiChat } from './docsai-client';
10+
import { pickQuestions } from './suggested-questions';
1011

1112
const { env } = document.documentElement.dataset;
1213
const docsConfig = getConfig(env);
@@ -161,9 +162,23 @@ class ConversationalSearch {
161162
const emptyStateTemplate = document.getElementById('conv-search-empty-state');
162163
if (emptyStateTemplate) {
163164
container.appendChild(emptyStateTemplate.content.cloneNode(true));
165+
this.renderSuggestions(container);
164166
}
165167
}
166168

169+
renderSuggestions(container = this.messagesContainer) {
170+
const suggestionsContainer = container?.querySelector('.conv-search-suggestions');
171+
const template = document.getElementById('conv-search-suggestion-template');
172+
if (!suggestionsContainer || !template) return;
173+
174+
suggestionsContainer.replaceChildren(...pickQuestions().map((q) => {
175+
const btn = template.content.firstElementChild.cloneNode(true);
176+
btn.dataset.query = q;
177+
btn.querySelector('span').textContent = q;
178+
return btn;
179+
}));
180+
}
181+
167182
// --- Events ------------------------------------------------------------------
168183

169184
bindEvents() {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const SUGGESTED_QUESTIONS = [
2+
'What is the Datadog Agent?',
3+
'How to define a Datadog monitor in Terraform (example)?',
4+
'Which OpenTelemetry semantic conventions should I use for LLM traces in Datadog?',
5+
'How do I install the Datadog Agent on a Linux host?',
6+
'What are Datadog API and application keys, and how do I create them?',
7+
'How do I tag my infrastructure in Datadog?',
8+
'How do I set up APM tracing for a Python application?',
9+
'What is the difference between a service, a resource, and a trace in Datadog APM?',
10+
'How do I send logs from a Docker container to Datadog?',
11+
'How do I create a log processing pipeline to parse custom logs?',
12+
'How do I monitor Kubernetes clusters with Datadog?',
13+
'How do I set up the AWS integration with Datadog?',
14+
'How do I create a metric monitor with alert conditions in Datadog?',
15+
'What monitor types are available in Datadog?',
16+
'How do I build a custom dashboard with template variables?',
17+
'How do I create a Synthetic API test to monitor an endpoint?',
18+
'How do I set up Real User Monitoring (RUM) for a web application?',
19+
'How do I monitor AWS Lambda functions with Datadog?',
20+
'How do I enable Continuous Profiler for a Java service?',
21+
'How do I trace LLM application calls with Datadog LLM Observability?',
22+
'How do I create a Service Level Objective (SLO) in Datadog?',
23+
'How do I send OpenTelemetry traces to Datadog?',
24+
'How do I track AWS cloud costs in Datadog?'
25+
];
26+
27+
export function pickQuestions() {
28+
const indexes = new Set();
29+
// Pick 3 random distinct indexes
30+
while (indexes.size < 3) indexes.add(Math.floor(Math.random() * SUGGESTED_QUESTIONS.length));
31+
return [...indexes].map((index) => SUGGESTED_QUESTIONS[index]);
32+
}

layouts/partials/conversational-search.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ <h3 class="conv-search-empty-title">How can I help you today?</h3>
6969
<p class="conv-search-empty-subtitle">Ask me anything about Datadog documentation</p>
7070
</div>
7171
<div class="conv-search-suggestions">
72-
<button class="conv-search-suggestion" data-query="What is the Datadog Agent?"><span>What is the Datadog Agent?</span></button>
73-
<button class="conv-search-suggestion" data-query="How to define a Datadog monitor in Terraform (example)?"><span>How to define a Datadog monitor in Terraform (example)?</span></button>
74-
<button class="conv-search-suggestion" data-query="Which OpenTelemetry semantic conventions should I use for LLM traces in Datadog?"><span>Which OpenTelemetry semantic conventions should I use for LLM traces in Datadog?</span></button>
7572
</div>
7673
</div>
7774
</template>
7875

76+
{{/* Suggestion button shell — text + data-query are filled in by JS */}}
77+
<template id="conv-search-suggestion-template">
78+
<button class="conv-search-suggestion"><span></span></button>
79+
</template>
80+
7981
{{/* Reusable assistant message actions (thumbs/copy) */}}
8082
<template id="conv-search-actions-template">
8183
<div class="conv-search-message-actions">

0 commit comments

Comments
 (0)