Skip to content

Commit 94c6830

Browse files
committed
Refactor reasoning effort handling to validate support and standardize UI labels
1 parent f93e485 commit 94c6830

4 files changed

Lines changed: 157 additions & 32 deletions

File tree

‎apps/editor/src/utils/apply-reasoning-effort.ts‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@ export const apply_reasoning_effort = (
1414
}
1515
}
1616
} else if (provider.name == 'Google') {
17-
if (reasoning_effort == 'none') {
18-
body.reasoning_effort = reasoning_effort
19-
} else {
20-
body.extra_body = {
21-
google: {
22-
thinking_config: {
23-
thinking_level: reasoning_effort,
24-
include_thoughts: true
25-
}
17+
body.extra_body = {
18+
google: {
19+
thinking_config: {
20+
thinking_level: reasoning_effort,
21+
include_thoughts: true
2622
}
2723
}
2824
}

‎apps/editor/src/views/utils/config-editing.ts‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,18 +379,22 @@ export const edit_temperature_for_config = async (
379379

380380
export const edit_reasoning_effort_for_config = async () => {
381381
const effort_options: vscode.QuickPickItem[] = [
382-
{ label: 'Unset', description: 'Remove reasoning effort configuration' },
383-
{ label: 'none' },
384-
{ label: 'minimal' },
385-
{ label: 'low' },
386-
{ label: 'medium' },
387-
{ label: 'high' }
382+
{
383+
label: 'Unset',
384+
description: 'Remove reasoning effort from the configuration'
385+
},
386+
{ label: 'None' },
387+
{ label: 'Minimal' },
388+
{ label: 'Low' },
389+
{ label: 'Medium' },
390+
{ label: 'High' }
388391
]
389392

390393
return await new Promise<string | null | undefined>((resolve) => {
391394
const quick_pick = vscode.window.createQuickPick()
392395
quick_pick.items = effort_options
393-
quick_pick.title = 'Select Reasoning Effort'
396+
quick_pick.title = 'Reasoning Efforts'
397+
quick_pick.placeholder = 'Select reasoning effort'
394398
quick_pick.buttons = [vscode.QuickInputButtons.Back]
395399

396400
let accepted = false
@@ -401,7 +405,9 @@ export const edit_reasoning_effort_for_config = async () => {
401405
accepted = true
402406
const selected = quick_pick.selectedItems[0]
403407
if (selected) {
404-
resolve(selected.label === 'Unset' ? null : selected.label)
408+
resolve(
409+
selected.label == 'Unset' ? null : selected.label.toLowerCase()
410+
)
405411
} else {
406412
resolve(undefined)
407413
}

‎apps/editor/src/views/utils/upsert-configuration.ts‎

Lines changed: 135 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import {
1616
initial_select_model,
1717
initial_select_provider
1818
} from './config-editing'
19+
import axios from 'axios'
20+
import { PROVIDERS } from '@shared/constants/providers'
21+
import { apply_reasoning_effort } from '@/utils/apply-reasoning-effort'
1922

2023
export const upsert_configuration = async (params: {
2124
context: vscode.ExtensionContext
@@ -30,44 +33,38 @@ export const upsert_configuration = async (params: {
3033
let get_configs: () => Promise<ToolConfig[]>
3134
let save_configs: (configs: ToolConfig[]) => Promise<void>
3235
let advanced_options: string[] = []
33-
let advanced_details = ''
3436

3537
switch (params.tool_type) {
3638
case 'code-at-cursor':
3739
get_configs = () => providers_manager.get_code_completions_tool_configs()
3840
save_configs = (configs) =>
3941
providers_manager.save_code_completions_tool_configs(configs)
4042
advanced_options = ['Temperature', 'Reasoning Effort']
41-
advanced_details = 'Temperature, Reasoning Effort...'
4243
break
4344
case 'commit-messages':
4445
get_configs = () => providers_manager.get_commit_messages_tool_configs()
4546
save_configs = (configs) =>
4647
providers_manager.save_commit_messages_tool_configs(configs)
4748
advanced_options = ['Temperature', 'Reasoning Effort']
48-
advanced_details = 'Temperature, Reasoning Effort...'
4949
break
5050
case 'edit-context':
5151
get_configs = () => providers_manager.get_edit_context_tool_configs()
5252
save_configs = (configs) =>
5353
providers_manager.save_edit_context_tool_configs(configs)
5454
advanced_options = ['Temperature', 'Reasoning Effort']
55-
advanced_details = 'Temperature, Reasoning Effort...'
5655
break
5756
case 'intelligent-update':
5857
get_configs = () =>
5958
providers_manager.get_intelligent_update_tool_configs()
6059
save_configs = (configs) =>
6160
providers_manager.save_intelligent_update_tool_configs(configs)
6261
advanced_options = ['Temperature', 'Reasoning Effort', 'Max Concurrency']
63-
advanced_details = 'Temperature, Reasoning Effort, Max Concurrency...'
6462
break
6563
case 'prune-context':
6664
get_configs = () => providers_manager.get_prune_context_tool_configs()
6765
save_configs = (configs) =>
6866
providers_manager.save_prune_context_tool_configs(configs)
6967
advanced_options = ['Temperature', 'Reasoning Effort']
70-
advanced_details = 'Temperature, Reasoning Effort...'
7168
break
7269
default:
7370
throw new Error(`Unknown tool type: ${params.tool_type}`)
@@ -178,7 +175,7 @@ export const upsert_configuration = async (params: {
178175
const items: vscode.QuickPickItem[] = [
179176
{ label: 'Model Provider', detail: updated_config.provider_name },
180177
{ label: 'Model', detail: updated_config.model },
181-
{ label: 'Advanced', detail: advanced_details }
178+
{ label: 'Advanced' }
182179
]
183180

184181
const selected_item = await new Promise<vscode.QuickPickItem | undefined>(
@@ -191,7 +188,7 @@ export const upsert_configuration = async (params: {
191188
quick_pick.placeholder = 'Select a property to edit'
192189
const close_button: vscode.QuickInputButton = {
193190
iconPath: new vscode.ThemeIcon('close'),
194-
tooltip: 'Save and Close'
191+
tooltip: 'Save and close'
195192
}
196193
const redo_button: vscode.QuickInputButton = {
197194
iconPath: new vscode.ThemeIcon('redo'),
@@ -223,7 +220,7 @@ export const upsert_configuration = async (params: {
223220
detail: updated_config.provider_name
224221
},
225222
{ label: 'Model', detail: updated_config.model },
226-
{ label: 'Advanced', detail: advanced_details }
223+
{ label: 'Advanced' }
227224
]
228225
quick_pick.buttons = [close_button]
229226
}
@@ -266,7 +263,7 @@ export const upsert_configuration = async (params: {
266263
if (advanced_options.includes('Temperature')) {
267264
advanced_items.push({
268265
label: 'Temperature',
269-
description: 'Leave unset with reasoning models',
266+
description: 'Leave empty with reasoning models',
270267
detail: updated_config.temperature?.toString()
271268
})
272269
}
@@ -327,10 +324,60 @@ export const upsert_configuration = async (params: {
327324
new_temp === null ? undefined : new_temp
328325
}
329326
} else if (selected_advanced.label == 'Reasoning Effort') {
330-
const new_effort = await edit_reasoning_effort_for_config()
331-
if (new_effort !== undefined) {
332-
updated_config.reasoning_effort =
333-
new_effort === null ? undefined : (new_effort as any)
327+
// eslint-disable-next-line no-constant-condition
328+
while (true) {
329+
const new_effort = await edit_reasoning_effort_for_config()
330+
if (new_effort === undefined) break
331+
332+
let is_valid = true
333+
if (new_effort !== null) {
334+
const provider = await providers_manager.get_provider(
335+
updated_config.provider_name
336+
)
337+
if (provider) {
338+
const base_url =
339+
provider.type === 'built-in'
340+
? PROVIDERS[provider.name as keyof typeof PROVIDERS]
341+
?.base_url
342+
: provider.base_url
343+
344+
if (base_url) {
345+
try {
346+
await vscode.window.withProgress(
347+
{
348+
location: vscode.ProgressLocation.Notification,
349+
title: 'Checking reasoning effort support...',
350+
cancellable: true
351+
},
352+
async (_progress, token) => {
353+
await verify_reasoning_effort({
354+
endpoint_url: base_url!,
355+
api_key: provider.api_key,
356+
model: updated_config.model,
357+
reasoning_effort: new_effort as string,
358+
provider,
359+
cancellation_token: token
360+
})
361+
}
362+
)
363+
} catch (error: any) {
364+
is_valid = false
365+
if (error?.message != 'Cancelled') {
366+
vscode.window.showWarningMessage(
367+
dictionary.warning_message
368+
.REASONING_EFFORT_NOT_SUPPORTED
369+
)
370+
}
371+
}
372+
}
373+
}
374+
}
375+
376+
if (is_valid) {
377+
updated_config.reasoning_effort =
378+
new_effort === null ? undefined : (new_effort as any)
379+
break
380+
}
334381
}
335382
} else if (selected_advanced.label == 'Max Concurrency') {
336383
const new_concurrency =
@@ -392,3 +439,77 @@ export const upsert_configuration = async (params: {
392439

393440
await save_configs(configs)
394441
}
442+
443+
const verify_reasoning_effort = async (params: {
444+
endpoint_url: string
445+
api_key?: string
446+
model: string
447+
reasoning_effort: string
448+
provider: Provider
449+
cancellation_token: vscode.CancellationToken
450+
}): Promise<void> => {
451+
const cancel_source = axios.CancelToken.source()
452+
453+
const disposable = params.cancellation_token.onCancellationRequested(() => {
454+
cancel_source.cancel('User cancelled')
455+
})
456+
457+
const body: any = {
458+
model: params.model,
459+
messages: [
460+
{
461+
role: 'user',
462+
content: 'Respond with "Hello!" and nothing else.'
463+
}
464+
],
465+
stream: true
466+
}
467+
468+
apply_reasoning_effort(body, params.provider, params.reasoning_effort as any)
469+
470+
try {
471+
const response = await axios.post(
472+
params.endpoint_url + '/chat/completions',
473+
body,
474+
{
475+
headers: {
476+
...(params.api_key
477+
? { ['Authorization']: `Bearer ${params.api_key}` }
478+
: {}),
479+
['Content-Type']: 'application/json'
480+
},
481+
responseType: 'stream',
482+
cancelToken: cancel_source.token
483+
}
484+
)
485+
486+
await new Promise<void>((resolve, reject) => {
487+
const stream = response.data
488+
489+
stream.on('data', () => {
490+
cancel_source.cancel('Verified')
491+
resolve()
492+
})
493+
494+
stream.on('error', (err: any) => {
495+
reject(err)
496+
})
497+
498+
stream.on('end', () => {
499+
resolve()
500+
})
501+
})
502+
} catch (error) {
503+
if (axios.isCancel(error)) {
504+
if (error.message == 'Verified') {
505+
return
506+
}
507+
if (error.message == 'User cancelled') {
508+
throw new Error('Cancelled')
509+
}
510+
}
511+
throw error
512+
} finally {
513+
disposable.dispose()
514+
}
515+
}

‎packages/shared/src/constants/dictionary.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ export const dictionary = {
193193
`No results for "${search_value}" in the selected context.`,
194194
NO_MODEL_PROVIDERS_FOUND:
195195
'No model providers found. Please add a model provider first.',
196-
SELECT_PRESET_FROM_LIST: 'Select preset from the list.'
196+
SELECT_PRESET_FROM_LIST: 'Select preset from the list.',
197+
REASONING_EFFORT_NOT_SUPPORTED:
198+
'The selected reasoning effort is not supported by the model.'
197199
},
198200

199201
error_message: {

0 commit comments

Comments
 (0)