Skip to content

Commit 60a269e

Browse files
Wire VLM toggle + result badge in Scene Describer (tool 01)
Routes API calls through vlmToggle.getClient() so switching between Moondream and GPT-4o-mini actually changes the engine used. Shows a via Moondream or via GPT-4o-mini badge after each result. Fixed containerSelector to match actual page structure. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
1 parent f607af5 commit 60a269e

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

01-scene-describer/app.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ document.addEventListener('DOMContentLoaded', async function() {
2525
let detections = [];
2626
let detectionResults = {};
2727

28+
// VLM-aware client helper: routes through toggle when available
29+
function getVLMClient() {
30+
if (window.vlmToggle) return window.vlmToggle.getClient();
31+
return client;
32+
}
2833
const detectionCanvas = document.getElementById('detectionCanvas');
2934
const detectionCtx = detectionCanvas.getContext('2d');
3035
const detectionList = document.getElementById('detectionList');
@@ -78,7 +83,7 @@ document.addEventListener('DOMContentLoaded', async function() {
7883

7984
// Initialize VLM Toggle
8085
window.vlmToggle = new VLMToggle({
81-
containerSelector: '.control-panel h2',
86+
containerSelector: '.app-header h1',
8287
toolId: 'scene-describer',
8388
onChange: (engine) => {
8489
window.reasoningConsole.logInfo('Switched to ' + engine + ' VLM');
@@ -169,9 +174,10 @@ document.addEventListener('DOMContentLoaded', async function() {
169174
}
170175

171176
async function describeScene() {
172-
if (!client) {
177+
const activeClient = getVLMClient();
178+
if (!activeClient) {
173179
window.reasoningConsole.logError('No API key configured');
174-
updateStatus('Please configure your Moondream API key', 'error');
180+
updateStatus('Please configure an API key', 'error');
175181
window.apiKeyManager.showModal();
176182
return;
177183
}
@@ -187,7 +193,7 @@ document.addEventListener('DOMContentLoaded', async function() {
187193

188194
window.reasoningConsole.logApiCall('/describe', 0);
189195

190-
const result = await client.describeVideo(video, { maxTokens });
196+
const result = await activeClient.describeVideo(video, { maxTokens });
191197
const elapsed = Date.now() - startTime;
192198

193199
window.reasoningConsole.logSceneDescription(result.description, elapsed);
@@ -210,6 +216,7 @@ document.addEventListener('DOMContentLoaded', async function() {
210216
});
211217

212218
updateStatus(`Described in ${elapsed}ms`, 'success');
219+
VLMResultBadge.showCurrent(elapsed);
213220

214221
} catch (error) {
215222
window.reasoningConsole.logError(error.message);
@@ -233,9 +240,10 @@ document.addEventListener('DOMContentLoaded', async function() {
233240
return;
234241
}
235242

236-
if (!client) {
243+
const activeClient = getVLMClient();
244+
if (!activeClient) {
237245
window.reasoningConsole.logError('No API key configured');
238-
updateStatus('Please configure your Moondream API key', 'error');
246+
updateStatus('Please configure an API key', 'error');
239247
window.apiKeyManager.showModal();
240248
return;
241249
}
@@ -250,7 +258,7 @@ document.addEventListener('DOMContentLoaded', async function() {
250258
try {
251259
window.reasoningConsole.logApiCall('/ask', 0);
252260

253-
const result = await client.askVideo(video, question);
261+
const result = await activeClient.askVideo(video, question);
254262
const elapsed = Date.now() - startTime;
255263

256264
window.reasoningConsole.logDecision('Answer received', `${elapsed}ms`);
@@ -282,6 +290,7 @@ document.addEventListener('DOMContentLoaded', async function() {
282290
});
283291

284292
updateStatus(`Answered in ${elapsed}ms`, 'success');
293+
VLMResultBadge.showCurrent(elapsed);
285294

286295
} catch (error) {
287296
window.reasoningConsole.logError(error.message);
@@ -492,9 +501,10 @@ document.addEventListener('DOMContentLoaded', async function() {
492501
}
493502

494503
async function runDetection() {
495-
if (!client) {
504+
const activeClient = getVLMClient();
505+
if (!activeClient) {
496506
window.reasoningConsole.logError('No API key configured');
497-
updateStatus('Please configure your Moondream API key', 'error');
507+
updateStatus('Please configure an API key', 'error');
498508
window.apiKeyManager.showModal();
499509
return;
500510
}
@@ -513,7 +523,7 @@ document.addEventListener('DOMContentLoaded', async function() {
513523
try {
514524
const promises = activeDetections.map(async (detection) => {
515525
try {
516-
const result = await client.detectInVideo(video, detection.target);
526+
const result = await activeClient.detectInVideo(video, detection.target);
517527
detectionResults[detection.id] = result;
518528
window.reasoningConsole.logInfo(`Detected ${result.objects.length} "${detection.target}"`);
519529
return { id: detection.id, success: true, count: result.objects.length };
@@ -533,6 +543,7 @@ document.addEventListener('DOMContentLoaded', async function() {
533543

534544
updateStatus(`Detected ${totalObjects} object(s) across ${successCount} target(s) in ${elapsed}ms`, 'success');
535545
window.reasoningConsole.logDecision('Detection complete', `${totalObjects} objects found in ${elapsed}ms`);
546+
VLMResultBadge.showCurrent(elapsed);
536547

537548
updateJsonOutput({
538549
type: 'object_detection',

01-scene-describer/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ <h3>⚙️ Settings</h3>
623623
<script src="../shared/video-source-adapter.js"></script>
624624
<script src="../shared/openai-client.js"></script>
625625
<script src="../shared/vlm-toggle.js"></script>
626+
<script src="../shared/vlm-result-badge.js"></script>
626627
<script src="app.js"></script>
627628
<script src="../shared/ux-utils.js"></script>
628629
<script src="../shared/playground-header.js"></script>

0 commit comments

Comments
 (0)