Skip to content

Commit 80b4306

Browse files
author
Jicheng Lu
committed
add response format in instruction test
1 parent 09371eb commit 80b4306

2 files changed

Lines changed: 45 additions & 4 deletions

File tree

src/routes/page/instruction/instruction-components/instruction-llm.svelte

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script>
22
import Select from '$lib/common/dropdowns/Select.svelte';
33
import { INTEGER_REGEX } from '$lib/helpers/constants';
4-
import { ReasoningEffortLevel } from '$lib/helpers/enums';
4+
import { ReasoningEffortLevel, ResponseFormat } from '$lib/helpers/enums';
55
66
/**
77
* @type {{
@@ -11,7 +11,8 @@
1111
* selectedModel?: string | null,
1212
* selectedReasoningEffortLevel?: string | null,
1313
* selectedMaxOutputTokens?: number | null,
14-
* onSelectLlm?: (detail: { provider: import('$commonTypes').LlmConfig | null, model: string | null, reasoning_effort_level: string | null, max_output_tokens: number | null }) => void
14+
* selectedResponseFormat?: string | null,
15+
* onSelectLlm?: (detail: { provider: import('$commonTypes').LlmConfig | null, model: string | null, reasoning_effort_level: string | null, max_output_tokens: number | null, response_format: string | null }) => void
1516
* }}
1617
*/
1718
let {
@@ -21,6 +22,7 @@
2122
selectedModel = $bindable(null),
2223
selectedReasoningEffortLevel = $bindable(null),
2324
selectedMaxOutputTokens = $bindable(null),
25+
selectedResponseFormat = $bindable(null),
2426
onSelectLlm
2527
} = $props();
2628
@@ -30,6 +32,12 @@
3032
label: v
3133
}));
3234
35+
/** @type {import('$commonTypes').LabelValuePair[]} */
36+
const responseFormatOptions = Object.values(ResponseFormat).map(v => ({
37+
value: v,
38+
label: v
39+
}));
40+
3341
/** @type {import('$commonTypes').LabelValuePair[]} */
3442
let providerOptions = $derived(
3543
llmConfigs?.map(x => ({
@@ -99,6 +107,14 @@
99107
fireSelectLlm();
100108
}
101109
110+
/** @param {any} e */
111+
function selectResponseFormat(e) {
112+
// @ts-ignore
113+
const selectedValues = e.detail.selecteds?.map(x => x.value) || [];
114+
selectedResponseFormat = selectedValues.length > 0 ? selectedValues[0] : null;
115+
fireSelectLlm();
116+
}
117+
102118
/** @param {any} e */
103119
function validateIntegerInput(e) {
104120
const reg = new RegExp(INTEGER_REGEX, 'g');
@@ -112,7 +128,8 @@
112128
provider: selectedProvider || null,
113129
model: selectedModel,
114130
reasoning_effort_level: selectedReasoningEffortLevel || null,
115-
max_output_tokens: selectedMaxOutputTokens || null
131+
max_output_tokens: selectedMaxOutputTokens || null,
132+
response_format: selectedResponseFormat || null
116133
});
117134
}
118135
</script>
@@ -183,4 +200,19 @@
183200
/>
184201
</div>
185202
{/if}
203+
204+
<div>
205+
<label for="response-format-select" class="mb-1.5 inline-flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wider text-primary">
206+
<i class="mdi mdi-code-json text-sm leading-none"></i>
207+
Response format
208+
</label>
209+
<Select
210+
tag={'response-format-select'}
211+
placeholder={'Select a format'}
212+
disabled={disabled}
213+
selectedValues={selectedResponseFormat ? [selectedResponseFormat] : []}
214+
options={responseFormatOptions}
215+
onselect={e => selectResponseFormat(e)}
216+
/>
217+
</div>
186218
</div>

src/routes/page/instruction/testing/+page.svelte

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
/** @type {number | null} */
5858
let selectedMaxOutputTokens = $state(null);
5959
60+
/** @type {string | null} */
61+
let selectedResponseFormat = $state(null);
62+
6063
/** @type {string | null} */
6164
let selectedTemplate = $state(null);
6265
@@ -114,6 +117,9 @@
114117
if (selectedMaxOutputTokens && selectedMaxOutputTokens > 0) {
115118
clonedStates.push({ key: 'max_tokens', value: selectedMaxOutputTokens.toString() });
116119
}
120+
if (selectedResponseFormat) {
121+
clonedStates.push({ key: 'response_format', value: selectedResponseFormat });
122+
}
117123
118124
const formattedStates = formatKeyValues(states, clonedStates);
119125
const formatedArgs = formatKeyValues(args);
@@ -194,6 +200,7 @@
194200
selectedModel = modelName;
195201
selectedReasoningEffortLevel = llmConfig?.reasoning_effort_level || null;
196202
selectedMaxOutputTokens = llmConfig?.max_output_tokens || null;
203+
selectedResponseFormat = llmConfig?.response_format || null;
197204
198205
if (selectedAgent?.id) {
199206
initAgentCodeScripts(selectedAgent.id);
@@ -202,12 +209,13 @@
202209
}
203210
}
204211
205-
/** @param {{ provider: import('$commonTypes').LlmConfig | null, model: string | null, reasoning_effort_level: string | null, max_output_tokens: number | null }} detail */
212+
/** @param {{ provider: import('$commonTypes').LlmConfig | null, model: string | null, reasoning_effort_level: string | null, max_output_tokens: number | null, response_format: string | null }} detail */
206213
function onLlmSelected(detail) {
207214
selectedProvider = detail.provider || null;
208215
selectedModel = detail.model || '';
209216
selectedReasoningEffortLevel = detail.reasoning_effort_level || null;
210217
selectedMaxOutputTokens = detail.max_output_tokens || null;
218+
selectedResponseFormat = detail.response_format || null;
211219
}
212220
213221
/** @param {string} agentId */
@@ -404,6 +412,7 @@
404412
bind:selectedModel={selectedModel}
405413
bind:selectedReasoningEffortLevel={selectedReasoningEffortLevel}
406414
bind:selectedMaxOutputTokens={selectedMaxOutputTokens}
415+
bind:selectedResponseFormat={selectedResponseFormat}
407416
onSelectLlm={detail => onLlmSelected(detail)}
408417
/>
409418
</div>

0 commit comments

Comments
 (0)