Skip to content

Commit e5b1311

Browse files
authored
Merge pull request #1797 from vespa-engine/cars_improvements
use faster model and say Thinking
2 parents 7140d6a + a08cdcf commit e5b1311

File tree

2 files changed

+46
-38
lines changed
  • examples/ecommerce-user-preferences/webapp

2 files changed

+46
-38
lines changed

examples/ecommerce-user-preferences/webapp/app.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,9 @@ def chat():
450450
try:
451451
# Get response from OpenAI
452452
response = client.responses.create(
453-
model="gpt-5",
454-
input=openai_messages
453+
model="gpt-5-mini",
454+
input=openai_messages,
455+
reasoning={"effort": "low"}
455456
)
456457

457458
# Extract assistant's response

examples/ecommerce-user-preferences/webapp/static/js/app.js

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ document.addEventListener('DOMContentLoaded', function() {
107107
addMessage(message, true);
108108
userInput.value = '';
109109

110-
// Show loading
111-
loadingOverlay.classList.remove('d-none');
110+
// Add thinking message
111+
const thinkingMessage = addMessage('Thinking...', false);
112112

113113
try {
114114
const response = await fetch('/api/chat', {
@@ -130,11 +130,8 @@ document.addEventListener('DOMContentLoaded', function() {
130130

131131
const data = await response.json();
132132

133-
// Hide loading
134-
loadingOverlay.classList.add('d-none');
135-
136-
// Add assistant response
137-
addMessage(data.response, false);
133+
// Replace thinking message with actual response
134+
updateMessage(thinkingMessage, data.response);
138135

139136
// Display preferences if available
140137
if (data.preferences) {
@@ -174,11 +171,8 @@ document.addEventListener('DOMContentLoaded', function() {
174171
} catch (error) {
175172
console.error('Error:', error);
176173

177-
// Hide loading
178-
loadingOverlay.classList.add('d-none');
179-
180-
// Add error message
181-
addMessage('Sorry, there was an error processing your request. Please try again.', false);
174+
// Replace thinking message with error
175+
updateMessage(thinkingMessage, 'Sorry, there was an error processing your request. Please try again.');
182176
}
183177
}
184178

@@ -210,6 +204,31 @@ document.addEventListener('DOMContentLoaded', function() {
210204

211205
// Scroll to bottom
212206
chatContainer.scrollTop = chatContainer.scrollHeight;
207+
208+
// Return the message element for future updates
209+
return messageDiv;
210+
}
211+
212+
// Update an existing message
213+
function updateMessage(messageElement, content) {
214+
if (!messageElement) return;
215+
216+
// Strip out the JSON part before displaying
217+
let displayContent = content;
218+
const jsonIndex = displayContent.indexOf("===JSON");
219+
if (jsonIndex !== -1) {
220+
displayContent = displayContent.substring(0, jsonIndex).trim();
221+
}
222+
223+
const messageContent = messageElement.querySelector('.message-content');
224+
if (messageContent) {
225+
// Render with Markdown, sanitize first
226+
const html = marked.parse(displayContent, { mangle: false, headerIds: false });
227+
messageContent.innerHTML = DOMPurify.sanitize(html, { USE_PROFILES: { html: true } });
228+
}
229+
230+
// Scroll to bottom
231+
chatContainer.scrollTop = chatContainer.scrollHeight;
213232
}
214233

215234
// Display preferences as pills
@@ -362,8 +381,8 @@ document.addEventListener('DOMContentLoaded', function() {
362381

363382
// Send preference adjustment message
364383
async function sendPreferenceAdjustment(message, key, value) {
365-
// Show loading
366-
loadingOverlay.classList.remove('d-none');
384+
// Add thinking message
385+
const thinkingMessage = addMessage('Thinking...', false);
367386

368387
try {
369388
const response = await fetch('/api/chat', {
@@ -389,11 +408,8 @@ document.addEventListener('DOMContentLoaded', function() {
389408

390409
const data = await response.json();
391410

392-
// Hide loading
393-
loadingOverlay.classList.add('d-none');
394-
395-
// Add assistant response
396-
addMessage(data.response, false);
411+
// Replace thinking message with actual response
412+
updateMessage(thinkingMessage, data.response);
397413

398414
// Display preferences if available
399415
if (data.preferences) {
@@ -409,18 +425,15 @@ document.addEventListener('DOMContentLoaded', function() {
409425
} catch (error) {
410426
console.error('Error updating preferences:', error);
411427

412-
// Hide loading
413-
loadingOverlay.classList.add('d-none');
414-
415-
// Add error message
416-
addMessage('Sorry, there was an error updating your preferences. Please try again.', false);
428+
// Replace thinking message with error
429+
updateMessage(thinkingMessage, 'Sorry, there was an error updating your preferences. Please try again.');
417430
}
418431
}
419432

420433
// Send preference removal message
421434
async function sendPreferenceRemoval(message, keyToRemove) {
422-
// Show loading
423-
loadingOverlay.classList.remove('d-none');
435+
// Add thinking message
436+
const thinkingMessage = addMessage('Thinking...', false);
424437

425438
try {
426439
const response = await fetch('/api/chat', {
@@ -446,11 +459,8 @@ document.addEventListener('DOMContentLoaded', function() {
446459

447460
const data = await response.json();
448461

449-
// Hide loading
450-
loadingOverlay.classList.add('d-none');
451-
452-
// Add assistant response
453-
addMessage(data.response, false);
462+
// Replace thinking message with actual response
463+
updateMessage(thinkingMessage, data.response);
454464

455465
// Display preferences if available
456466
if (data.preferences) {
@@ -464,11 +474,8 @@ document.addEventListener('DOMContentLoaded', function() {
464474
} catch (error) {
465475
console.error('Error removing preference:', error);
466476

467-
// Hide loading
468-
loadingOverlay.classList.add('d-none');
469-
470-
// Add error message
471-
addMessage('Sorry, there was an error removing your preference. Please try again.', false);
477+
// Replace thinking message with error
478+
updateMessage(thinkingMessage, 'Sorry, there was an error removing your preference. Please try again.');
472479
}
473480
}
474481

0 commit comments

Comments
 (0)