Skip to content

Commit 7140d6a

Browse files
authored
Merge pull request #1795 from vespa-engine/cars_gpt5
cars demo: using gpt5 and rendering markdown
2 parents 0979574 + 8bcac8b commit 7140d6a

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,13 @@ def chat():
449449

450450
try:
451451
# Get response from OpenAI
452-
response = client.chat.completions.create(
453-
model="gpt-4o",
454-
messages=openai_messages,
455-
temperature=0.7,
452+
response = client.responses.create(
453+
model="gpt-5",
454+
input=openai_messages
456455
)
457456

458457
# Extract assistant's response
459-
assistant_response = response.choices[0].message.content
458+
assistant_response = response.output_text
460459

461460
# Add assistant response to session history
462461
session['messages'].append({"role": "assistant", "content": assistant_response})

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,13 @@ document.addEventListener('DOMContentLoaded', function() {
198198
const messageContent = messageNode.querySelector('.message-content');
199199

200200
messageDiv.classList.add(isUser ? 'user' : 'assistant');
201-
messageContent.textContent = displayContent;
201+
if (!isUser) {
202+
// Render assistant messages with Markdown, sanitize first
203+
const html = marked.parse(displayContent, { mangle: false, headerIds: false });
204+
messageContent.innerHTML = DOMPurify.sanitize(html, { USE_PROFILES: { html: true } });
205+
} else {
206+
messageContent.textContent = displayContent;
207+
}
202208

203209
chatContainer.appendChild(messageNode);
204210

examples/ecommerce-user-preferences/webapp/templates/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ <h3 class="car-title"></h3>
144144
</template>
145145

146146
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
147+
<!-- Lightweight Markdown rendering (assistant messages only) -->
148+
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
149+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/purify.min.js"></script>
147150
<script src="{{ url_for('static', filename='js/app.js') }}"></script>
148151
</body>
149152
</html>

0 commit comments

Comments
 (0)