LLMs: define, edit, and optionally spec the vendor model parameter 'Anthropic thinking budget'

This commit is contained in:
Enrico Ros
2025-02-24 15:54:12 -08:00
parent dfc110ca05
commit b6462225a7
3 changed files with 54 additions and 5 deletions
+16 -2
View File
@@ -51,7 +51,7 @@ export const DModelParameterRegistry = {
range: [0.0, 2.0] as const,
nullable: {
meaning: 'Explicitly avoid sending temperature to upstream API',
},
} as const,
requiredFallback: FALLBACK_LLM_PARAM_TEMPERATURE,
} as const,
@@ -66,6 +66,17 @@ export const DModelParameterRegistry = {
incompatibleWith: ['temperature'] as const,
} as const,
llmVndAntThinkingBudget: {
label: 'Thinking Budget',
type: 'integer' as const,
description: 'Budget for extended thinking',
range: [1024, 65536] as const,
initialValue: 8192,
nullable: {
meaning: 'Disable extended thinking',
} as const,
} as const,
llmVndGeminiShowThoughts: {
label: 'Show Thoughts',
type: 'boolean' as const,
@@ -110,7 +121,10 @@ export type DModelParameterId = keyof typeof DModelParameterRegistry;
type _EnumValues<T> = T extends { type: 'enum', values: readonly (infer U)[] } ? U : never;
type DModelParameterValue<T extends DModelParameterId> =
typeof DModelParameterRegistry[T]['type'] extends 'integer' ? number | null :
typeof DModelParameterRegistry[T]['type'] extends 'integer'
? typeof DModelParameterRegistry[T] extends { nullable: any }
? number | null
: number :
typeof DModelParameterRegistry[T]['type'] extends 'float'
? typeof DModelParameterRegistry[T] extends { nullable: any }
? number | null
@@ -1,9 +1,10 @@
import * as React from 'react';
import { Box, IconButton, Tooltip } from '@mui/joy';
import ClearIcon from '@mui/icons-material/Clear';
import LocalFireDepartmentIcon from '@mui/icons-material/LocalFireDepartment';
import { DModelParameterId, DModelParameterSpec, DModelParameterValues, FALLBACK_LLM_PARAM_RESPONSE_TOKENS, FALLBACK_LLM_PARAM_TEMPERATURE, getAllModelParameterValues } from '~/common/stores/llms/llms.parameters';
import { DModelParameterId, DModelParameterRegistry, DModelParameterSpec, DModelParameterValues, FALLBACK_LLM_PARAM_RESPONSE_TOKENS, FALLBACK_LLM_PARAM_TEMPERATURE, getAllModelParameterValues } from '~/common/stores/llms/llms.parameters';
import { FormSelectControl } from '~/common/components/forms/FormSelectControl';
import { FormSliderControl } from '~/common/components/forms/FormSliderControl';
import { FormSwitchControl } from '~/common/components/forms/FormSwitchControl';
@@ -41,6 +42,7 @@ export function LLMParametersEditor(props: {
// derived state
const llmTemperature: number | null = allParameters.llmTemperature === undefined ? FALLBACK_LLM_PARAM_TEMPERATURE : allParameters.llmTemperature;
const llmResponseTokens = allParameters.llmResponseTokens ?? FALLBACK_LLM_PARAM_RESPONSE_TOKENS;
const llmVndAntThinkingBudget = allParameters.llmVndAntThinkingBudget;
const llmVndGeminiShowThoughts = allParameters.llmVndGeminiShowThoughts;
const llmVndOaiReasoningEffort = allParameters.llmVndOaiReasoningEffort;
const llmVndOaiRestoreMarkdown = !!allParameters.llmVndOaiRestoreMarkdown;
@@ -62,13 +64,19 @@ export function LLMParametersEditor(props: {
}, [onChangeParameter, overheat, tempAboveOne]);
// optional params specs
// optional parameters definitions
const { llmVndAntThinkingBudget: defAntTB } = DModelParameterRegistry;
// optional params specs - a spec is a definition of a parameter, and whether it's required or hidden, for a particular model
const paramSpecAntThinkingBudget = parameterSpecs?.find(p => p.paramId === 'llmVndAntThinkingBudget') as DModelParameterSpec<'llmVndAntThinkingBudget'> | undefined;
const paramSpecGeminiShowThoughts = parameterSpecs?.find(p => p.paramId === 'llmVndGeminiShowThoughts') as DModelParameterSpec<'llmVndGeminiShowThoughts'> | undefined;
const paramSpecReasoningEffort = parameterSpecs?.find(p => p.paramId === 'llmVndOaiReasoningEffort') as DModelParameterSpec<'llmVndOaiReasoningEffort'> | undefined;
const paramSpecRestoreMarkdown = parameterSpecs?.find(p => p.paramId === 'llmVndOaiRestoreMarkdown') as DModelParameterSpec<'llmVndOaiRestoreMarkdown'> | undefined;
const showOverheatButton = overheat || llmTemperature === 1 || tempAboveOne;
const llmVndAntThinkingNull = llmVndAntThinkingBudget === null;
return <>
<FormSliderControl
@@ -80,7 +88,7 @@ export function LLMParametersEditor(props: {
value={llmTemperature}
onChange={value => onChangeParameter({ llmTemperature: value })}
endAdornment={
<Tooltip title={overheat ? 'Disable LLM Overheating' : 'Increase Max LLM Temperature to 2'} sx={{ p: 1 }}>
<Tooltip arrow disableInteractive title={overheat ? 'Disable LLM Overheating' : 'Increase Max LLM Temperature to 2'} sx={{ p: 1 }}>
<IconButton
disabled={!showOverheatButton}
variant={overheat ? 'soft' : 'plain'} color={overheat ? 'danger' : 'neutral'}
@@ -106,6 +114,32 @@ export function LLMParametersEditor(props: {
<InlineError error='Max Output Tokens: Token computations are disabled because this model does not declare the context window size.' />
)}
{paramSpecAntThinkingBudget && (
<FormSliderControl
title='Thinking Budget' ariaLabel='Anthropic Extended Thinking Token Budget'
description='Tokens'
min={defAntTB.range[0]} max={defAntTB.range[1]} step={1024}
valueLabelDisplay={llmVndAntThinkingNull ? 'off' : 'on'}
value={llmVndAntThinkingBudget ?? 0}
disabled={llmVndAntThinkingNull}
onChange={value => onChangeParameter({ llmVndAntThinkingBudget: value })}
endAdornment={
<Tooltip arrow disableInteractive title={llmVndAntThinkingNull ? 'Enable Thinking' : 'Disable Thinking'}>
<IconButton
variant={llmVndAntThinkingNull ? 'solid' : 'outlined'}
onClick={() => llmVndAntThinkingNull
? onRemoveParameter('llmVndAntThinkingBudget')
: onChangeParameter({ llmVndAntThinkingBudget: null })
}
sx={{ ml: 2 }}
>
<ClearIcon />
</IconButton>
</Tooltip>
}
/>
)}
{paramSpecGeminiShowThoughts && (
<FormSwitchControl
title='Show Chain of Thought'
@@ -74,6 +74,7 @@ const ModelParameterSpec_schema = z.object({
*/
paramId: z.enum([
'llmTopP',
'llmVndAntThinkingBudget',
'llmVndGeminiShowThoughts',
'llmVndOaiReasoningEffort',
'llmVndOaiRestoreMarkdown',