Skip to content

Commit 3b7de8f

Browse files
authored
Merge pull request #185 from Unity-Lab-AI/develop
Made system prompt usable on unity model
2 parents 08466ab + 42123ed commit 3b7de8f

3 files changed

Lines changed: 87 additions & 7 deletions

File tree

ai/demo/js/api.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,23 +283,39 @@ export async function getAIResponse(message, chatHistory, settings, generateRand
283283

284284
// CUSTOM: If Unity model is selected, use Mistral with Unity system prompt and tool calling
285285
let actualModel = settings.model;
286-
let effectiveSystemPrompt = settings.systemPrompt;
286+
let effectiveSystemPrompt = '';
287287
let useToolCalling = supportsTools;
288288

289289
if (settings.model === 'unity') {
290290
// Use Mistral model with Unity persona and enable tool calling
291291
actualModel = 'mistral';
292-
effectiveSystemPrompt = unitySystemPrompt + TOOL_CALLING_ADDON;
292+
// Append user's system prompt to Unity prompt if provided
293+
if (settings.systemPrompt && settings.systemPrompt.trim()) {
294+
effectiveSystemPrompt = unitySystemPrompt + '\n\n' + settings.systemPrompt + '\n\n' + TOOL_CALLING_ADDON;
295+
console.log('Unity model: appending user system prompt to Unity persona');
296+
} else {
297+
effectiveSystemPrompt = unitySystemPrompt + TOOL_CALLING_ADDON;
298+
}
293299
useToolCalling = true;
294300
console.log('Unity model selected: using Mistral with Unity persona and tool calling');
301+
} else if (isCommunityModel) {
302+
// Community models: ignore user system prompts, only add tool calling addon if supported
303+
if (supportsTools) {
304+
effectiveSystemPrompt = TOOL_CALLING_ADDON.trim();
305+
} else {
306+
effectiveSystemPrompt = '';
307+
}
308+
console.log('Community model: user system prompts are disabled');
295309
} else if (supportsTools) {
296-
// Add tool calling addon to system prompt for models that support it
297-
// This includes community models - voice playback is already disabled for them separately
298-
if (effectiveSystemPrompt) {
299-
effectiveSystemPrompt += TOOL_CALLING_ADDON;
310+
// Non-community models with tool support: use user system prompt + tool calling addon
311+
if (settings.systemPrompt && settings.systemPrompt.trim()) {
312+
effectiveSystemPrompt = settings.systemPrompt + '\n\n' + TOOL_CALLING_ADDON;
300313
} else {
301314
effectiveSystemPrompt = TOOL_CALLING_ADDON.trim();
302315
}
316+
} else {
317+
// Non-community models without tool support: use user system prompt as-is
318+
effectiveSystemPrompt = settings.systemPrompt || '';
303319
}
304320

305321
// If model supports tool calling, use OpenAI endpoint
@@ -509,17 +525,21 @@ async function getAIResponseLegacy(message, model, systemPrompt, chatHistory, se
509525
url += url.includes('?') ? '&' : '?';
510526
url += 'private=true';
511527

512-
// Add system prompt if specified
528+
// Add system prompt if specified (but not for community models, except Unity which is handled separately)
513529
const currentModel = getCurrentModelMetadata(settings.model);
514530
const isCommunityModel = currentModel && currentModel.community === true;
531+
const isUnityModel = settings.model === 'unity';
515532

516533
if (systemPrompt) {
534+
// Use the provided system prompt (this should already be processed correctly)
517535
url += url.includes('?') ? '&' : '?';
518536
url += `system=${encodeURIComponent(systemPrompt)}`;
519537
} else if (settings.systemPrompt && !isCommunityModel) {
538+
// For non-community models, use user's system prompt
520539
url += url.includes('?') ? '&' : '?';
521540
url += `system=${encodeURIComponent(settings.systemPrompt)}`;
522541
}
542+
// For community models (excluding Unity), system prompts are ignored
523543

524544
// Add reasoning effort if specified and model supports it
525545
const supportsReasoning = currentModel && currentModel.reasoning === true;

ai/demo/js/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
autoResizeTextarea,
3030
updateModelInfo,
3131
updateVoiceAvailability,
32+
updateSystemPromptAvailability,
3233
expandImage,
3334
setupMobileModalListeners,
3435
deleteAllData,
@@ -105,6 +106,9 @@ const DemoApp = {
105106
// Update voice availability based on initial model
106107
updateVoiceAvailability(this.settings);
107108

109+
// Update system prompt availability based on initial model
110+
updateSystemPromptAvailability(this.settings);
111+
108112
console.log('Unity AI Lab Demo initialized');
109113
},
110114

@@ -122,6 +126,7 @@ const DemoApp = {
122126
this.settings.model = modelValue;
123127
updateModelInfo(modelValue, getAvailableTextModels());
124128
updateVoiceAvailability(this.settings);
129+
updateSystemPromptAvailability(this.settings);
125130
this.saveSettings();
126131
},
127132
() => this.saveSettings(),

ai/demo/js/ui.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,61 @@ export function updateVoiceAvailability(settings) {
207207
}
208208
}
209209

210+
/**
211+
* Update system prompt availability based on current model
212+
*/
213+
export function updateSystemPromptAvailability(settings) {
214+
const currentModel = getCurrentModelMetadata(settings.model);
215+
const isCommunityModel = currentModel && currentModel.community === true;
216+
217+
// Unity is allowed system prompts (user prompt gets appended to Unity prompt)
218+
const isUnityModel = settings.model === 'unity';
219+
220+
// Get ALL system prompt textareas (desktop sidebar + mobile modal)
221+
const systemPromptTextareas = document.querySelectorAll('#systemPrompt');
222+
223+
systemPromptTextareas.forEach(systemPromptTextarea => {
224+
const systemPromptSection = systemPromptTextarea.closest('.control-section');
225+
226+
if (isCommunityModel && !isUnityModel) {
227+
// Disable system prompt for community models (excluding Unity)
228+
systemPromptTextarea.disabled = true;
229+
systemPromptTextarea.value = '';
230+
settings.systemPrompt = '';
231+
232+
// Add visual indicator
233+
if (systemPromptSection) {
234+
systemPromptSection.style.opacity = '0.5';
235+
systemPromptTextarea.title = 'System prompts are not available for community models';
236+
}
237+
} else if (isUnityModel) {
238+
// Enable system prompt for Unity (it will be appended to Unity prompt)
239+
systemPromptTextarea.disabled = false;
240+
systemPromptTextarea.placeholder = 'Add to Unity\'s system prompt (optional)';
241+
242+
// Remove visual indicator and set Unity-specific styling
243+
if (systemPromptSection) {
244+
systemPromptSection.style.opacity = '1';
245+
systemPromptTextarea.title = 'Your prompt will be appended to Unity\'s system prompt';
246+
}
247+
} else {
248+
// Enable system prompt for non-community models
249+
systemPromptTextarea.disabled = false;
250+
systemPromptTextarea.placeholder = 'Set AI personality (leave empty for default)';
251+
252+
// Remove visual indicator
253+
if (systemPromptSection) {
254+
systemPromptSection.style.opacity = '1';
255+
systemPromptTextarea.title = '';
256+
}
257+
}
258+
});
259+
260+
if (isCommunityModel && !isUnityModel) {
261+
console.log('System prompt disabled for model:', settings.model);
262+
}
263+
}
264+
210265
/**
211266
* Expand image to fullscreen overlay
212267
*/

0 commit comments

Comments
 (0)