schema res
This commit is contained in:
@@ -30,5 +30,19 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="inline-drawer">
|
||||
<div class="inline-drawer-content">
|
||||
<h2>Model Settings</h2>
|
||||
<p>Use structured output for models that support it (e.g., OpenAI, Gemini, Anthropic).</p>
|
||||
<div class="rts-settings-toggle">
|
||||
<label for="rts-structured-output-toggle" class="rts-toggle-label">Structured Output</label>
|
||||
<label class="rts-switch">
|
||||
<input type="checkbox" id="rts-structured-output-toggle">
|
||||
<span class="rts-slider round"></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -4,6 +4,7 @@ console.log('RTS-MODE: index.js script loading...');
|
||||
console.log('RTS-MODE: jQuery available:', typeof jQuery !== 'undefined');
|
||||
console.log('RTS-MODE: $ available:', typeof $ !== 'undefined');
|
||||
|
||||
import { extension_settings, saveSettingsDebounced } from '../../../script.js';
|
||||
import { renderExtensionTemplateAsync } from '../../extensions.js';
|
||||
import { eventSource, event_types } from '../../events.js';
|
||||
import { createMapCanvas } from './ui/MapCanvas.js';
|
||||
@@ -21,6 +22,62 @@ console.log('RTS-MODE: All imports successful');
|
||||
const extensionId = 'rts-mode';
|
||||
const extensionName = 'RTS Chat Mode';
|
||||
|
||||
// RTS-mode specific settings
|
||||
const rtsSettings = {
|
||||
structuredOutput: false,
|
||||
};
|
||||
|
||||
// Placeholder for the JSON schema
|
||||
const RTS_JSON_SCHEMA = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"narrative": {
|
||||
"type": "string",
|
||||
"description": "The story portion of the turn."
|
||||
},
|
||||
"state": {
|
||||
"type": "object",
|
||||
"description": "The complete game state."
|
||||
},
|
||||
"entityUpdates": {
|
||||
"type": "array",
|
||||
"description": "A list of entities that have changed.",
|
||||
"items": {
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["narrative", "state"]
|
||||
};
|
||||
|
||||
|
||||
function isModelCompatible(chatCompletionSettings) {
|
||||
// TODO: Expand this list with more models that support structured output
|
||||
const compatibleModels = [
|
||||
'claude-3',
|
||||
'gpt-4',
|
||||
'gemini',
|
||||
];
|
||||
|
||||
const modelName = chatCompletionSettings.model.toLowerCase();
|
||||
return compatibleModels.some(m => modelName.includes(m));
|
||||
}
|
||||
|
||||
async function loadRtsSettings() {
|
||||
// Load settings
|
||||
Object.assign(rtsSettings, extension_settings[extensionId]);
|
||||
|
||||
// Set UI elements
|
||||
$('#rts-structured-output-toggle').prop('checked', rtsSettings.structuredOutput);
|
||||
}
|
||||
|
||||
function onStructuredOutputToggle(event) {
|
||||
const value = Boolean($(event.target).prop('checked'));
|
||||
rtsSettings.structuredOutput = value;
|
||||
extension_settings[extensionId].structuredOutput = value;
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
|
||||
let root;
|
||||
let topButton;
|
||||
let uiMounted = false;
|
||||
@@ -144,8 +201,15 @@ async function onRtsUICommand() {
|
||||
jQuery(async function() {
|
||||
console.log('RTS Chat Mode: jQuery ready, initializing extension...');
|
||||
|
||||
// Load settings
|
||||
extension_settings[extensionId] = extension_settings[extensionId] || {};
|
||||
loadRtsSettings();
|
||||
|
||||
await addTopBarButton();
|
||||
|
||||
// Add event listeners
|
||||
$('#rts-structured-output-toggle').on('input', onStructuredOutputToggle);
|
||||
|
||||
// Register slash commands
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'rts-start',
|
||||
@@ -195,3 +259,11 @@ jQuery(async function() {
|
||||
|
||||
console.log('RTS Chat Mode: Extension initialized successfully');
|
||||
});
|
||||
|
||||
eventSource.on(event_types.CHAT_COMPLETION_SETTINGS_READY, (data) => {
|
||||
const { chatCompletionSettings } = SillyTavern.getContext();
|
||||
if (rtsSettings.structuredOutput && isModelCompatible(chatCompletionSettings)) {
|
||||
data.responseMimeType = "application/json";
|
||||
data.responseSchema = RTS_JSON_SCHEMA;
|
||||
}
|
||||
});
|
||||
+1
-1
@@ -102,7 +102,7 @@ export async function sendTurn(userCmd) {
|
||||
throw new Error('LLM returned an empty response.');
|
||||
}
|
||||
|
||||
const responseJson = extractJson(reply);
|
||||
const responseJson = typeof reply === 'object' ? reply : extractJson(reply);
|
||||
|
||||
if (responseJson && responseJson.state && responseJson.narrative) {
|
||||
console.log('RTS: Processing AI response with state:', responseJson.state);
|
||||
|
||||
Reference in New Issue
Block a user