mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-09 04:40:57 +00:00
feat(provider): add pipeline reasoning controls
This commit is contained in:
@@ -144,6 +144,7 @@ function getValueSchema(spec: DynamicFormValueSpec) {
|
||||
return z.object({
|
||||
primary: z.string(),
|
||||
fallbacks: z.array(z.string()),
|
||||
reasoning: z.record(z.string()),
|
||||
});
|
||||
case DynamicFormItemType.PROMPT_EDITOR:
|
||||
return z.array(
|
||||
@@ -488,12 +489,24 @@ export default function DynamicFormComponent({
|
||||
(v): v is string => typeof v === 'string',
|
||||
)
|
||||
: [],
|
||||
reasoning:
|
||||
obj.reasoning != null &&
|
||||
typeof obj.reasoning === 'object' &&
|
||||
!Array.isArray(obj.reasoning)
|
||||
? Object.fromEntries(
|
||||
Object.entries(obj.reasoning).filter(
|
||||
(entry): entry is [string, string] =>
|
||||
typeof entry[1] === 'string',
|
||||
),
|
||||
)
|
||||
: {},
|
||||
};
|
||||
}
|
||||
// Legacy string format or any other unexpected type
|
||||
return {
|
||||
primary: typeof value === 'string' ? value : '',
|
||||
fallbacks: [],
|
||||
reasoning: {},
|
||||
};
|
||||
}
|
||||
if (item.type === 'prompt-editor') {
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
EmbeddingModel,
|
||||
RerankModel,
|
||||
PluginTool,
|
||||
ReasoningLevel,
|
||||
} from '@/app/infra/entities/api';
|
||||
import { toast } from 'sonner';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@@ -66,6 +67,9 @@ import SettingsDialog, {
|
||||
} from '@/app/home/components/settings-dialog/SettingsDialog';
|
||||
import ToolResourceSelectors from '@/app/home/components/dynamic-form/ToolResourceSelectors';
|
||||
import { LANGBOT_MODELS_PROVIDER_REQUESTER } from '@/app/home/components/models-dialog/types';
|
||||
import ReasoningLevelPicker, {
|
||||
REASONING_LEVELS,
|
||||
} from '@/app/home/components/reasoning/ReasoningLevelPicker';
|
||||
|
||||
function hasUsableUuid<T extends { uuid?: string | null }>(
|
||||
item: T,
|
||||
@@ -874,7 +878,11 @@ export default function DynamicFormItemComponent({
|
||||
];
|
||||
|
||||
const rawModelValue = field.value;
|
||||
const modelValue: { primary: string; fallbacks: string[] } =
|
||||
const modelValue: {
|
||||
primary: string;
|
||||
fallbacks: string[];
|
||||
reasoning: Record<string, ReasoningLevel>;
|
||||
} =
|
||||
rawModelValue != null &&
|
||||
typeof rawModelValue === 'object' &&
|
||||
!Array.isArray(rawModelValue)
|
||||
@@ -893,10 +901,31 @@ export default function DynamicFormItemComponent({
|
||||
.fallbacks as unknown[]
|
||||
).filter((v): v is string => typeof v === 'string')
|
||||
: [],
|
||||
reasoning:
|
||||
(rawModelValue as Record<string, unknown>).reasoning != null &&
|
||||
typeof (rawModelValue as Record<string, unknown>).reasoning ===
|
||||
'object' &&
|
||||
!Array.isArray(
|
||||
(rawModelValue as Record<string, unknown>).reasoning,
|
||||
)
|
||||
? (Object.fromEntries(
|
||||
Object.entries(
|
||||
(rawModelValue as Record<string, unknown>)
|
||||
.reasoning as Record<string, unknown>,
|
||||
).filter(
|
||||
(entry): entry is [string, ReasoningLevel] =>
|
||||
typeof entry[1] === 'string' &&
|
||||
REASONING_LEVELS.includes(
|
||||
entry[1] as ReasoningLevel,
|
||||
),
|
||||
),
|
||||
) as Record<string, ReasoningLevel>)
|
||||
: {},
|
||||
}
|
||||
: {
|
||||
primary: typeof rawModelValue === 'string' ? rawModelValue : '',
|
||||
fallbacks: [],
|
||||
reasoning: {},
|
||||
};
|
||||
|
||||
const renderModelSelect = (
|
||||
@@ -1043,20 +1072,78 @@ export default function DynamicFormItemComponent({
|
||||
field.onChange({ ...modelValue, ...patch });
|
||||
};
|
||||
|
||||
const updateModelReasoning = (
|
||||
modelUuid: string,
|
||||
level: ReasoningLevel,
|
||||
) => {
|
||||
if (!modelUuid) return;
|
||||
const updated = { ...modelValue.reasoning };
|
||||
if (level === 'provider_default') {
|
||||
delete updated[modelUuid];
|
||||
} else {
|
||||
updated[modelUuid] = level;
|
||||
}
|
||||
updateValue({ reasoning: updated });
|
||||
};
|
||||
|
||||
const replaceModel = (
|
||||
currentUuid: string,
|
||||
nextUuid: string,
|
||||
patch: Partial<typeof modelValue>,
|
||||
) => {
|
||||
const nextValue = { ...modelValue, ...patch };
|
||||
const updatedReasoning = { ...modelValue.reasoning };
|
||||
const currentModelStillSelected =
|
||||
nextValue.primary === currentUuid ||
|
||||
nextValue.fallbacks.includes(currentUuid);
|
||||
if (
|
||||
currentUuid &&
|
||||
currentUuid !== nextUuid &&
|
||||
!currentModelStillSelected
|
||||
) {
|
||||
delete updatedReasoning[currentUuid];
|
||||
}
|
||||
updateValue({ ...nextValue, reasoning: updatedReasoning });
|
||||
};
|
||||
|
||||
const renderReasoningPicker = (modelUuid: string) => {
|
||||
if (!modelUuid) return null;
|
||||
const model = llmModels.find((candidate) => candidate.uuid === modelUuid);
|
||||
const currentLevel =
|
||||
modelValue.reasoning[modelUuid] || 'provider_default';
|
||||
const availableLevels = model?.reasoning_capabilities?.levels || [
|
||||
'provider_default',
|
||||
];
|
||||
const levels = REASONING_LEVELS.filter(
|
||||
(level) =>
|
||||
availableLevels.includes(level) || level === currentLevel,
|
||||
);
|
||||
|
||||
return (
|
||||
<ReasoningLevelPicker
|
||||
value={currentLevel}
|
||||
levels={levels}
|
||||
onChange={(level) => updateModelReasoning(modelUuid, level)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const addFallbackModel = () => {
|
||||
updateValue({ fallbacks: [...modelValue.fallbacks, ''] });
|
||||
};
|
||||
|
||||
const updateFallbackModel = (index: number, value: string) => {
|
||||
const updated = [...modelValue.fallbacks];
|
||||
const currentUuid = updated[index];
|
||||
updated[index] = value;
|
||||
updateValue({ fallbacks: updated });
|
||||
replaceModel(currentUuid, value, { fallbacks: updated });
|
||||
};
|
||||
|
||||
const removeFallbackModel = (index: number) => {
|
||||
const updated = [...modelValue.fallbacks];
|
||||
const removedUuid = updated[index];
|
||||
updated.splice(index, 1);
|
||||
updateValue({ fallbacks: updated });
|
||||
replaceModel(removedUuid, '', { fallbacks: updated });
|
||||
};
|
||||
|
||||
const moveFallbackModel = (index: number, direction: 'up' | 'down') => {
|
||||
@@ -1081,10 +1168,12 @@ export default function DynamicFormItemComponent({
|
||||
<div className="min-w-0 flex-1">
|
||||
{renderModelSelect(
|
||||
modelValue.primary,
|
||||
(val) => updateValue({ primary: val }),
|
||||
(val) =>
|
||||
replaceModel(modelValue.primary, val, { primary: val }),
|
||||
t('models.selectModel'),
|
||||
)}
|
||||
</div>
|
||||
{renderReasoningPicker(modelValue.primary)}
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
@@ -1118,15 +1207,18 @@ export default function DynamicFormItemComponent({
|
||||
</p>
|
||||
{modelValue.fallbacks.map((fbUuid: string, index: number) => (
|
||||
<div key={index} className="flex min-w-0 items-center gap-2">
|
||||
<span className="text-xs text-muted-foreground w-4 shrink-0">
|
||||
<span className="w-4 shrink-0 text-xs text-muted-foreground">
|
||||
{index + 1}.
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
{renderModelSelect(
|
||||
fbUuid,
|
||||
(val) => updateFallbackModel(index, val),
|
||||
t('models.selectModel'),
|
||||
)}
|
||||
<div className="flex min-w-0 flex-1 items-center gap-1.5">
|
||||
<div className="min-w-0 flex-1">
|
||||
{renderModelSelect(
|
||||
fbUuid,
|
||||
(val) => updateFallbackModel(index, val),
|
||||
t('models.selectModel'),
|
||||
)}
|
||||
</div>
|
||||
{renderReasoningPicker(fbUuid)}
|
||||
</div>
|
||||
<div className="flex gap-1 shrink-0">
|
||||
<Button
|
||||
|
||||
@@ -5,6 +5,56 @@ export type DynamicFormSaveValueSpec = Pick<
|
||||
'default' | 'name' | 'type'
|
||||
>;
|
||||
|
||||
const reasoningLevels = new Set([
|
||||
'disabled',
|
||||
'enabled',
|
||||
'minimal',
|
||||
'low',
|
||||
'medium',
|
||||
'high',
|
||||
'xhigh',
|
||||
'max',
|
||||
]);
|
||||
|
||||
function normalizeModelFallbackValue(value: unknown): {
|
||||
primary: string;
|
||||
fallbacks: string[];
|
||||
reasoning: Record<string, string>;
|
||||
} {
|
||||
const raw =
|
||||
value != null && typeof value === 'object' && !Array.isArray(value)
|
||||
? (value as Record<string, unknown>)
|
||||
: {};
|
||||
const primary =
|
||||
typeof raw.primary === 'string'
|
||||
? raw.primary
|
||||
: typeof value === 'string'
|
||||
? value
|
||||
: '';
|
||||
const fallbacks = Array.isArray(raw.fallbacks)
|
||||
? raw.fallbacks.filter(
|
||||
(fallback): fallback is string => typeof fallback === 'string',
|
||||
)
|
||||
: [];
|
||||
const selectedModels = new Set([primary, ...fallbacks].filter(Boolean));
|
||||
const rawReasoning =
|
||||
raw.reasoning != null &&
|
||||
typeof raw.reasoning === 'object' &&
|
||||
!Array.isArray(raw.reasoning)
|
||||
? (raw.reasoning as Record<string, unknown>)
|
||||
: {};
|
||||
const reasoning = Object.fromEntries(
|
||||
Object.entries(rawReasoning).filter(
|
||||
([modelUuid, level]) =>
|
||||
selectedModels.has(modelUuid) &&
|
||||
typeof level === 'string' &&
|
||||
reasoningLevels.has(level),
|
||||
),
|
||||
) as Record<string, string>;
|
||||
|
||||
return { primary, fallbacks, reasoning };
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the value snapshot emitted to parent forms for persistence.
|
||||
* Only single-line string fields trim surrounding whitespace; multiline text
|
||||
@@ -16,10 +66,14 @@ export function normalizeDynamicFormValuesForSave(
|
||||
): Record<string, unknown> {
|
||||
return specs.reduce<Record<string, unknown>>((values, spec) => {
|
||||
const value = formValues[spec.name] ?? spec.default;
|
||||
values[spec.name] =
|
||||
spec.type === 'string' && typeof value === 'string'
|
||||
? value.trim()
|
||||
: value;
|
||||
if (spec.type === 'model-fallback-selector') {
|
||||
values[spec.name] = normalizeModelFallbackValue(value);
|
||||
} else {
|
||||
values[spec.name] =
|
||||
spec.type === 'string' && typeof value === 'string'
|
||||
? value.trim()
|
||||
: value;
|
||||
}
|
||||
return values;
|
||||
}, {});
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Plus, Boxes } from 'lucide-react';
|
||||
import { httpClient, systemInfo } from '@/app/infra/http/HttpClient';
|
||||
import { ModelProvider } from '@/app/infra/entities/api';
|
||||
import { ModelProvider, ReasoningConfig } from '@/app/infra/entities/api';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@@ -15,6 +15,7 @@ import ProviderForm from './component/provider-form/ProviderForm';
|
||||
import { ProviderCard } from './components';
|
||||
import {
|
||||
ExtraArg,
|
||||
DEFAULT_REASONING_CONFIG,
|
||||
ModelType,
|
||||
ScanModelsResult,
|
||||
SelectedScannedModel,
|
||||
@@ -285,6 +286,7 @@ export default function ModelsPanel({
|
||||
name: string,
|
||||
abilities: string[],
|
||||
extraArgs: ExtraArg[],
|
||||
reasoningConfig: ReasoningConfig,
|
||||
contextLength?: number | null,
|
||||
) {
|
||||
if (!name.trim()) {
|
||||
@@ -300,6 +302,7 @@ export default function ModelsPanel({
|
||||
name,
|
||||
provider_uuid: providerUuid,
|
||||
abilities,
|
||||
reasoning_config: reasoningConfig,
|
||||
context_length: parseContextLength(
|
||||
contextLength,
|
||||
t('models.contextLengthInvalid'),
|
||||
@@ -361,6 +364,7 @@ export default function ModelsPanel({
|
||||
name: item.model.name,
|
||||
provider_uuid: providerUuid,
|
||||
abilities: item.abilities,
|
||||
reasoning_config: DEFAULT_REASONING_CONFIG,
|
||||
context_length: item.model.context_length ?? null,
|
||||
extra_args: {},
|
||||
} as never);
|
||||
@@ -398,6 +402,7 @@ export default function ModelsPanel({
|
||||
name: string,
|
||||
abilities: string[],
|
||||
extraArgs: ExtraArg[],
|
||||
reasoningConfig: ReasoningConfig,
|
||||
contextLength?: number | null,
|
||||
) {
|
||||
if (!name.trim()) {
|
||||
@@ -413,6 +418,7 @@ export default function ModelsPanel({
|
||||
name,
|
||||
provider_uuid: providerUuid,
|
||||
abilities,
|
||||
reasoning_config: reasoningConfig,
|
||||
context_length: parseContextLength(
|
||||
contextLength,
|
||||
t('models.contextLengthInvalid'),
|
||||
@@ -469,6 +475,7 @@ export default function ModelsPanel({
|
||||
modelType: ModelType,
|
||||
abilities: string[],
|
||||
extraArgs: ExtraArg[],
|
||||
reasoningConfig: ReasoningConfig,
|
||||
) {
|
||||
setIsTesting(true);
|
||||
setTestResult(null);
|
||||
@@ -491,6 +498,7 @@ export default function ModelsPanel({
|
||||
provider_uuid: '',
|
||||
provider: providerData,
|
||||
abilities,
|
||||
reasoning_config: reasoningConfig,
|
||||
extra_args: extraArgsObj,
|
||||
} as never);
|
||||
} else if (modelType === 'embedding') {
|
||||
@@ -554,13 +562,21 @@ export default function ModelsPanel({
|
||||
onSpaceLogin={handleSpaceLogin}
|
||||
onOpenAddModel={() => setAddModelPopoverOpen(provider.uuid)}
|
||||
onCloseAddModel={() => setAddModelPopoverOpen(null)}
|
||||
onAddModel={(modelType, name, abilities, extraArgs, contextLength) =>
|
||||
onAddModel={(
|
||||
modelType,
|
||||
name,
|
||||
abilities,
|
||||
extraArgs,
|
||||
reasoningConfig,
|
||||
contextLength,
|
||||
) =>
|
||||
handleAddModel(
|
||||
provider.uuid,
|
||||
modelType,
|
||||
name,
|
||||
abilities,
|
||||
extraArgs,
|
||||
reasoningConfig,
|
||||
contextLength,
|
||||
)
|
||||
}
|
||||
@@ -576,6 +592,7 @@ export default function ModelsPanel({
|
||||
name,
|
||||
abilities,
|
||||
extraArgs,
|
||||
reasoningConfig,
|
||||
contextLength,
|
||||
) =>
|
||||
handleUpdateModel(
|
||||
@@ -585,6 +602,7 @@ export default function ModelsPanel({
|
||||
name,
|
||||
abilities,
|
||||
extraArgs,
|
||||
reasoningConfig,
|
||||
contextLength,
|
||||
)
|
||||
}
|
||||
@@ -593,8 +611,15 @@ export default function ModelsPanel({
|
||||
onDeleteModel={(modelId, modelType) =>
|
||||
handleDeleteModel(provider.uuid, modelId, modelType)
|
||||
}
|
||||
onTestModel={(name, modelType, abilities, extraArgs) =>
|
||||
handleTestModel(provider.uuid, name, modelType, abilities, extraArgs)
|
||||
onTestModel={(name, modelType, abilities, extraArgs, reasoningConfig) =>
|
||||
handleTestModel(
|
||||
provider.uuid,
|
||||
name,
|
||||
modelType,
|
||||
abilities,
|
||||
extraArgs,
|
||||
reasoningConfig,
|
||||
)
|
||||
}
|
||||
isSubmitting={isSubmitting}
|
||||
isTesting={isTesting}
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
ArrowUpDown,
|
||||
Eye,
|
||||
Wrench,
|
||||
BrainCircuit,
|
||||
Check,
|
||||
RefreshCw,
|
||||
} from 'lucide-react';
|
||||
@@ -20,8 +21,12 @@ import {
|
||||
} from '@/components/ui/popover';
|
||||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ScannedProviderModel } from '@/app/infra/entities/api';
|
||||
import {
|
||||
ReasoningConfig,
|
||||
ScannedProviderModel,
|
||||
} from '@/app/infra/entities/api';
|
||||
import {
|
||||
DEFAULT_REASONING_CONFIG,
|
||||
ExtraArg,
|
||||
ModelType,
|
||||
ScanModelsResult,
|
||||
@@ -42,6 +47,7 @@ interface AddModelPopoverProps {
|
||||
name: string,
|
||||
abilities: string[],
|
||||
extraArgs: ExtraArg[],
|
||||
reasoningConfig: ReasoningConfig,
|
||||
contextLength?: number | null,
|
||||
) => Promise<void>;
|
||||
onScanModels: (modelType?: ModelType) => Promise<ScanModelsResult>;
|
||||
@@ -54,6 +60,7 @@ interface AddModelPopoverProps {
|
||||
modelType: ModelType,
|
||||
abilities: string[],
|
||||
extraArgs: ExtraArg[],
|
||||
reasoningConfig: ReasoningConfig,
|
||||
) => Promise<void>;
|
||||
isSubmitting: boolean;
|
||||
isTesting: boolean;
|
||||
@@ -143,11 +150,24 @@ export default function AddModelPopover({
|
||||
tab === 'llm' && contextLength.trim()
|
||||
? Number(contextLength.trim())
|
||||
: null;
|
||||
await onAddModel(tab, name, abilities, extraArgs, parsedContextLength);
|
||||
await onAddModel(
|
||||
tab,
|
||||
name,
|
||||
abilities,
|
||||
extraArgs,
|
||||
DEFAULT_REASONING_CONFIG,
|
||||
parsedContextLength,
|
||||
);
|
||||
};
|
||||
|
||||
const handleTest = async () => {
|
||||
await onTestModel(name, tab, tab === 'llm' ? abilities : [], extraArgs);
|
||||
await onTestModel(
|
||||
name,
|
||||
tab,
|
||||
tab === 'llm' ? abilities : [],
|
||||
extraArgs,
|
||||
DEFAULT_REASONING_CONFIG,
|
||||
);
|
||||
};
|
||||
|
||||
const handleScan = async () => {
|
||||
@@ -322,7 +342,7 @@ export default function AddModelPopover({
|
||||
{tab === 'llm' && (
|
||||
<div className="space-y-2">
|
||||
<Label>{t('models.abilities')}</Label>
|
||||
<div className="flex gap-4">
|
||||
<div className="flex flex-wrap gap-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id="add-vision"
|
||||
@@ -349,6 +369,19 @@ export default function AddModelPopover({
|
||||
{t('models.functionCallAbility')}
|
||||
</Label>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id="add-reasoning"
|
||||
checked={abilities.includes('reasoning')}
|
||||
onCheckedChange={(checked) =>
|
||||
toggleAbility('reasoning', checked as boolean)
|
||||
}
|
||||
/>
|
||||
<Label htmlFor="add-reasoning" className="text-sm">
|
||||
<BrainCircuit className="h-3 w-3 inline mr-1" />
|
||||
{t('models.reasoningAbility')}
|
||||
</Label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Trash2, Eye, Wrench, Check } from 'lucide-react';
|
||||
import { Trash2, Eye, Wrench, Check, BrainCircuit } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
@@ -11,8 +11,17 @@ import {
|
||||
PopoverTrigger,
|
||||
} from '@/components/ui/popover';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { LLMModel, EmbeddingModel } from '@/app/infra/entities/api';
|
||||
import { ExtraArg, ModelType, TestResult } from '../types';
|
||||
import {
|
||||
LLMModel,
|
||||
EmbeddingModel,
|
||||
ReasoningConfig,
|
||||
} from '@/app/infra/entities/api';
|
||||
import {
|
||||
DEFAULT_REASONING_CONFIG,
|
||||
ExtraArg,
|
||||
ModelType,
|
||||
TestResult,
|
||||
} from '../types';
|
||||
import ExtraArgsEditor from './ExtraArgsEditor';
|
||||
import { userInfo } from '@/app/infra/http';
|
||||
|
||||
@@ -32,12 +41,14 @@ interface ModelItemProps {
|
||||
name: string,
|
||||
abilities: string[],
|
||||
extraArgs: ExtraArg[],
|
||||
reasoningConfig: ReasoningConfig,
|
||||
contextLength?: number | null,
|
||||
) => Promise<void>;
|
||||
onTestModel: (
|
||||
name: string,
|
||||
abilities: string[],
|
||||
extraArgs: ExtraArg[],
|
||||
reasoningConfig: ReasoningConfig,
|
||||
) => Promise<void>;
|
||||
isSubmitting: boolean;
|
||||
isTesting: boolean;
|
||||
@@ -103,7 +114,6 @@ export default function ModelItem({
|
||||
const [editExtraArgs, setEditExtraArgs] = useState<ExtraArg[]>(
|
||||
convertExtraArgsToArray(model.extra_args),
|
||||
);
|
||||
|
||||
const isEditOpen = editModelPopoverOpen === model.uuid;
|
||||
const isDeleteOpen = deleteConfirmOpen === model.uuid;
|
||||
|
||||
@@ -133,12 +143,20 @@ export default function ModelItem({
|
||||
editName,
|
||||
editAbilities,
|
||||
editExtraArgs,
|
||||
modelType === 'llm'
|
||||
? (model as LLMModel).reasoning_config || DEFAULT_REASONING_CONFIG
|
||||
: DEFAULT_REASONING_CONFIG,
|
||||
parsedContextLength,
|
||||
);
|
||||
};
|
||||
|
||||
const handleTest = async () => {
|
||||
await onTestModel(editName, editAbilities, editExtraArgs);
|
||||
await onTestModel(
|
||||
editName,
|
||||
editAbilities,
|
||||
editExtraArgs,
|
||||
DEFAULT_REASONING_CONFIG,
|
||||
);
|
||||
};
|
||||
|
||||
const toggleAbility = (ability: string, checked: boolean) => {
|
||||
@@ -149,6 +167,12 @@ export default function ModelItem({
|
||||
}
|
||||
};
|
||||
|
||||
const supportsReasoning =
|
||||
modelType === 'llm' &&
|
||||
((model as LLMModel).reasoning_capabilities?.supported === true ||
|
||||
(model as LLMModel).abilities?.includes('reasoning'));
|
||||
const canSaveModel = !isLangBotModels;
|
||||
|
||||
// Check if popover should be disabled (space models when not logged in)
|
||||
const isPopoverDisabled =
|
||||
!canManage || (isLangBotModels && userInfo?.account_type !== 'space');
|
||||
@@ -194,6 +218,12 @@ export default function ModelItem({
|
||||
<Wrench className="h-3 w-3" />
|
||||
</Badge>
|
||||
)}
|
||||
{supportsReasoning && (
|
||||
<Badge variant="outline" className="text-xs gap-1">
|
||||
<BrainCircuit className="h-3 w-3" />
|
||||
{t('models.reasoningAbility')}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
{canManage && !isLangBotModels && (
|
||||
<Popover
|
||||
@@ -270,7 +300,7 @@ export default function ModelItem({
|
||||
{modelType === 'llm' && (
|
||||
<div className="space-y-2">
|
||||
<Label>{t('models.abilities')}</Label>
|
||||
<div className="flex gap-4">
|
||||
<div className="flex flex-wrap gap-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id={`edit-vision-${model.uuid}`}
|
||||
@@ -305,6 +335,23 @@ export default function ModelItem({
|
||||
{t('models.functionCallAbility')}
|
||||
</Label>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id={`edit-reasoning-${model.uuid}`}
|
||||
checked={editAbilities.includes('reasoning')}
|
||||
disabled={isLangBotModels}
|
||||
onCheckedChange={(checked) =>
|
||||
toggleAbility('reasoning', checked as boolean)
|
||||
}
|
||||
/>
|
||||
<Label
|
||||
htmlFor={`edit-reasoning-${model.uuid}`}
|
||||
className="text-sm"
|
||||
>
|
||||
<BrainCircuit className="h-3 w-3 inline mr-1" />
|
||||
{t('models.reasoningAbility')}
|
||||
</Label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@@ -336,7 +383,7 @@ export default function ModelItem({
|
||||
/>
|
||||
|
||||
<div className="flex gap-2">
|
||||
{!isLangBotModels && (
|
||||
{canSaveModel && (
|
||||
<Button
|
||||
className="flex-1"
|
||||
size="sm"
|
||||
@@ -347,7 +394,7 @@ export default function ModelItem({
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
className={isLangBotModels ? 'w-full' : 'flex-1'}
|
||||
className={canSaveModel ? 'flex-1' : 'w-full'}
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={handleTest}
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
Radar,
|
||||
} from 'lucide-react';
|
||||
import { httpClient, systemInfo } from '@/app/infra/http/HttpClient';
|
||||
import { ModelProvider } from '@/app/infra/entities/api';
|
||||
import { ModelProvider, ReasoningConfig } from '@/app/infra/entities/api';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Collapsible,
|
||||
@@ -63,6 +63,7 @@ interface ProviderCardProps {
|
||||
name: string,
|
||||
abilities: string[],
|
||||
extraArgs: ExtraArg[],
|
||||
reasoningConfig: ReasoningConfig,
|
||||
contextLength?: number | null,
|
||||
) => Promise<void>;
|
||||
onScanModels: (modelType?: ModelType) => Promise<ScanModelsResult>;
|
||||
@@ -78,6 +79,7 @@ interface ProviderCardProps {
|
||||
name: string,
|
||||
abilities: string[],
|
||||
extraArgs: ExtraArg[],
|
||||
reasoningConfig: ReasoningConfig,
|
||||
contextLength?: number | null,
|
||||
) => Promise<void>;
|
||||
onOpenDeleteConfirm: (modelId: string) => void;
|
||||
@@ -88,6 +90,7 @@ interface ProviderCardProps {
|
||||
modelType: ModelType,
|
||||
abilities: string[],
|
||||
extraArgs: ExtraArg[],
|
||||
reasoningConfig: ReasoningConfig,
|
||||
) => Promise<void>;
|
||||
isSubmitting: boolean;
|
||||
isTesting: boolean;
|
||||
@@ -430,6 +433,7 @@ export default function ProviderCard({
|
||||
name,
|
||||
abilities,
|
||||
extraArgs,
|
||||
reasoningConfig,
|
||||
contextLength,
|
||||
) =>
|
||||
onUpdateModel(
|
||||
@@ -438,11 +442,23 @@ export default function ProviderCard({
|
||||
name,
|
||||
abilities,
|
||||
extraArgs,
|
||||
reasoningConfig,
|
||||
contextLength,
|
||||
)
|
||||
}
|
||||
onTestModel={(name, abilities, extraArgs) =>
|
||||
onTestModel(name, 'llm', abilities, extraArgs)
|
||||
onTestModel={(
|
||||
name,
|
||||
abilities,
|
||||
extraArgs,
|
||||
reasoningConfig,
|
||||
) =>
|
||||
onTestModel(
|
||||
name,
|
||||
'llm',
|
||||
abilities,
|
||||
extraArgs,
|
||||
reasoningConfig,
|
||||
)
|
||||
}
|
||||
isSubmitting={isSubmitting}
|
||||
isTesting={isTesting}
|
||||
@@ -464,17 +480,34 @@ export default function ProviderCard({
|
||||
onOpenDeleteConfirm={onOpenDeleteConfirm}
|
||||
onCloseDeleteConfirm={onCloseDeleteConfirm}
|
||||
onDeleteModel={() => onDeleteModel(model.uuid, 'embedding')}
|
||||
onUpdateModel={(name, abilities, extraArgs) =>
|
||||
onUpdateModel={(
|
||||
name,
|
||||
abilities,
|
||||
extraArgs,
|
||||
reasoningConfig,
|
||||
) =>
|
||||
onUpdateModel(
|
||||
model.uuid,
|
||||
'embedding',
|
||||
name,
|
||||
abilities,
|
||||
extraArgs,
|
||||
reasoningConfig,
|
||||
)
|
||||
}
|
||||
onTestModel={(name, abilities, extraArgs) =>
|
||||
onTestModel(name, 'embedding', abilities, extraArgs)
|
||||
onTestModel={(
|
||||
name,
|
||||
abilities,
|
||||
extraArgs,
|
||||
reasoningConfig,
|
||||
) =>
|
||||
onTestModel(
|
||||
name,
|
||||
'embedding',
|
||||
abilities,
|
||||
extraArgs,
|
||||
reasoningConfig,
|
||||
)
|
||||
}
|
||||
isSubmitting={isSubmitting}
|
||||
isTesting={isTesting}
|
||||
@@ -496,17 +529,34 @@ export default function ProviderCard({
|
||||
onOpenDeleteConfirm={onOpenDeleteConfirm}
|
||||
onCloseDeleteConfirm={onCloseDeleteConfirm}
|
||||
onDeleteModel={() => onDeleteModel(model.uuid, 'rerank')}
|
||||
onUpdateModel={(name, abilities, extraArgs) =>
|
||||
onUpdateModel={(
|
||||
name,
|
||||
abilities,
|
||||
extraArgs,
|
||||
reasoningConfig,
|
||||
) =>
|
||||
onUpdateModel(
|
||||
model.uuid,
|
||||
'rerank',
|
||||
name,
|
||||
abilities,
|
||||
extraArgs,
|
||||
reasoningConfig,
|
||||
)
|
||||
}
|
||||
onTestModel={(name, abilities, extraArgs) =>
|
||||
onTestModel(name, 'rerank', abilities, extraArgs)
|
||||
onTestModel={(
|
||||
name,
|
||||
abilities,
|
||||
extraArgs,
|
||||
reasoningConfig,
|
||||
) =>
|
||||
onTestModel(
|
||||
name,
|
||||
'rerank',
|
||||
abilities,
|
||||
extraArgs,
|
||||
reasoningConfig,
|
||||
)
|
||||
}
|
||||
isSubmitting={isSubmitting}
|
||||
isTesting={isTesting}
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
ModelProvider,
|
||||
ProviderScanDebugInfo,
|
||||
ScannedProviderModel,
|
||||
ReasoningConfig,
|
||||
} from '@/app/infra/entities/api';
|
||||
|
||||
export type ExtraArg = {
|
||||
@@ -16,6 +17,10 @@ export type ExtraArg = {
|
||||
|
||||
export type ModelType = 'llm' | 'embedding' | 'rerank';
|
||||
|
||||
export const DEFAULT_REASONING_CONFIG: ReasoningConfig = {
|
||||
level: 'provider_default',
|
||||
};
|
||||
|
||||
export interface ProviderModels {
|
||||
llm: LLMModel[];
|
||||
embedding: EmbeddingModel[];
|
||||
@@ -53,12 +58,14 @@ export interface ModelItemProps {
|
||||
name: string,
|
||||
abilities: string[],
|
||||
extraArgs: ExtraArg[],
|
||||
reasoningConfig: ReasoningConfig,
|
||||
contextLength?: number | null,
|
||||
) => Promise<void>;
|
||||
onTest: (
|
||||
name: string,
|
||||
abilities: string[],
|
||||
extraArgs: ExtraArg[],
|
||||
reasoningConfig: ReasoningConfig,
|
||||
) => Promise<void>;
|
||||
isSubmitting: boolean;
|
||||
isTesting: boolean;
|
||||
@@ -90,6 +97,7 @@ export interface ProviderCardProps {
|
||||
name: string,
|
||||
abilities: string[],
|
||||
extraArgs: ExtraArg[],
|
||||
reasoningConfig: ReasoningConfig,
|
||||
contextLength?: number | null,
|
||||
) => Promise<void>;
|
||||
onScanModels: (modelType?: ModelType) => Promise<ScanModelsResult>;
|
||||
@@ -105,6 +113,7 @@ export interface ProviderCardProps {
|
||||
name: string,
|
||||
abilities: string[],
|
||||
extraArgs: ExtraArg[],
|
||||
reasoningConfig: ReasoningConfig,
|
||||
contextLength?: number | null,
|
||||
) => Promise<void>;
|
||||
onOpenDeleteConfirm: (modelId: string) => void;
|
||||
@@ -115,6 +124,7 @@ export interface ProviderCardProps {
|
||||
modelType: ModelType,
|
||||
abilities: string[],
|
||||
extraArgs: ExtraArg[],
|
||||
reasoningConfig: ReasoningConfig,
|
||||
) => Promise<void>;
|
||||
isSubmitting: boolean;
|
||||
isTesting: boolean;
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
.control {
|
||||
position: relative;
|
||||
height: 2.5rem;
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
.track,
|
||||
.fill {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 0;
|
||||
height: 2rem;
|
||||
transform: translateY(-50%);
|
||||
border-radius: 1rem;
|
||||
}
|
||||
|
||||
.track {
|
||||
width: 100%;
|
||||
background: var(--muted);
|
||||
}
|
||||
|
||||
.fill {
|
||||
background: var(--primary);
|
||||
}
|
||||
|
||||
.tick {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
width: 0.3rem;
|
||||
height: 0.3rem;
|
||||
transform: translate(-50%, -50%);
|
||||
border-radius: 50%;
|
||||
background: color-mix(in oklch, var(--muted-foreground) 46%, transparent);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.tickActive {
|
||||
background: color-mix(in oklch, var(--primary-foreground) 42%, transparent);
|
||||
}
|
||||
|
||||
.input {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
appearance: none;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.input::-webkit-slider-runnable-track {
|
||||
height: 2rem;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.input::-webkit-slider-thumb {
|
||||
width: 2.125rem;
|
||||
height: 2.125rem;
|
||||
margin-top: -0.0625rem;
|
||||
appearance: none;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 50%;
|
||||
background: var(--background);
|
||||
box-shadow: 0 1px 4px color-mix(in oklch, var(--foreground) 20%, transparent);
|
||||
}
|
||||
|
||||
.input::-moz-range-track {
|
||||
height: 2rem;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.input::-moz-range-thumb {
|
||||
width: 2.125rem;
|
||||
height: 2.125rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 50%;
|
||||
background: var(--background);
|
||||
box-shadow: 0 1px 4px color-mix(in oklch, var(--foreground) 20%, transparent);
|
||||
}
|
||||
|
||||
.input:focus-visible {
|
||||
outline: 2px solid var(--ring);
|
||||
outline-offset: 2px;
|
||||
border-radius: 1rem;
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
import { BrainCircuit, ChevronDown, ChevronRight } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ReasoningLevel } from '@/app/infra/entities/api';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from '@/components/ui/popover';
|
||||
import styles from './ReasoningLevelPicker.module.css';
|
||||
|
||||
export const REASONING_LEVELS: ReasoningLevel[] = [
|
||||
'provider_default',
|
||||
'disabled',
|
||||
'enabled',
|
||||
'minimal',
|
||||
'low',
|
||||
'medium',
|
||||
'high',
|
||||
'xhigh',
|
||||
'max',
|
||||
];
|
||||
|
||||
export const REASONING_LEVEL_LABEL_KEYS: Record<ReasoningLevel, string> = {
|
||||
provider_default: 'models.reasoningLevels.providerDefault',
|
||||
disabled: 'models.reasoningLevels.disabled',
|
||||
enabled: 'models.reasoningLevels.enabled',
|
||||
minimal: 'models.reasoningLevels.minimal',
|
||||
low: 'models.reasoningLevels.low',
|
||||
medium: 'models.reasoningLevels.medium',
|
||||
high: 'models.reasoningLevels.high',
|
||||
xhigh: 'models.reasoningLevels.xhigh',
|
||||
max: 'models.reasoningLevels.max',
|
||||
};
|
||||
|
||||
interface ReasoningLevelPickerProps {
|
||||
value: ReasoningLevel;
|
||||
levels: ReasoningLevel[];
|
||||
disabled?: boolean;
|
||||
onChange: (value: ReasoningLevel) => void;
|
||||
}
|
||||
|
||||
export default function ReasoningLevelPicker({
|
||||
value,
|
||||
levels,
|
||||
disabled = false,
|
||||
onChange,
|
||||
}: ReasoningLevelPickerProps) {
|
||||
const { t } = useTranslation();
|
||||
const safeLevels: ReasoningLevel[] =
|
||||
levels.length > 0 ? levels : ['provider_default'];
|
||||
const safeValue: ReasoningLevel = safeLevels.includes(value)
|
||||
? value
|
||||
: safeLevels[0];
|
||||
const currentLabel = t(REASONING_LEVEL_LABEL_KEYS[safeValue]);
|
||||
const isExplicit = safeValue !== 'provider_default';
|
||||
const currentIndex = Math.max(0, safeLevels.indexOf(safeValue));
|
||||
const denominator = Math.max(1, safeLevels.length - 1);
|
||||
const progress = currentIndex / denominator;
|
||||
|
||||
return (
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
disabled={disabled || safeLevels.length <= 1}
|
||||
aria-label={`${t('models.reasoningLevel')}: ${currentLabel}`}
|
||||
className="h-9 w-9 shrink-0 gap-1.5 px-2.5 text-xs font-normal sm:w-auto sm:max-w-36"
|
||||
>
|
||||
<BrainCircuit
|
||||
className={`size-4 shrink-0 ${isExplicit ? 'text-primary' : 'text-muted-foreground'}`}
|
||||
/>
|
||||
<span className="hidden min-w-0 truncate sm:block">
|
||||
{currentLabel}
|
||||
</span>
|
||||
<ChevronDown className="hidden size-3.5 shrink-0 text-muted-foreground sm:block" />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent align="end" className="w-[272px] p-4">
|
||||
<div className="flex h-5 items-center gap-0.5 text-sm text-muted-foreground">
|
||||
<span>{currentLabel}</span>
|
||||
<ChevronRight className="size-3.5" />
|
||||
</div>
|
||||
<div className={styles.control}>
|
||||
<div className={styles.track} />
|
||||
<div
|
||||
className={styles.fill}
|
||||
style={{
|
||||
width: `calc(17px + (100% - 34px) * ${progress})`,
|
||||
}}
|
||||
/>
|
||||
{safeLevels.map((level, index) => {
|
||||
const tickProgress = index / denominator;
|
||||
return (
|
||||
<span
|
||||
key={level}
|
||||
className={`${styles.tick} ${index <= currentIndex ? styles.tickActive : ''}`}
|
||||
style={{
|
||||
left: `calc(17px + (100% - 34px) * ${tickProgress})`,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
<input
|
||||
className={styles.input}
|
||||
type="range"
|
||||
min={0}
|
||||
max={Math.max(0, safeLevels.length - 1)}
|
||||
step={1}
|
||||
value={currentIndex}
|
||||
aria-label={t('models.reasoningLevel')}
|
||||
aria-valuetext={currentLabel}
|
||||
onChange={(event) =>
|
||||
onChange(safeLevels[Number(event.target.value)])
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
@@ -99,9 +99,32 @@ export interface LLMModel {
|
||||
provider?: ModelProvider;
|
||||
abilities?: string[];
|
||||
context_length?: number | null;
|
||||
reasoning_config?: ReasoningConfig;
|
||||
reasoning_capabilities?: ReasoningCapabilities;
|
||||
extra_args?: object;
|
||||
}
|
||||
|
||||
export type ReasoningLevel =
|
||||
| 'provider_default'
|
||||
| 'disabled'
|
||||
| 'enabled'
|
||||
| 'minimal'
|
||||
| 'low'
|
||||
| 'medium'
|
||||
| 'high'
|
||||
| 'xhigh'
|
||||
| 'max';
|
||||
|
||||
export interface ReasoningConfig {
|
||||
level: ReasoningLevel;
|
||||
}
|
||||
|
||||
export interface ReasoningCapabilities {
|
||||
supported: boolean;
|
||||
levels: ReasoningLevel[];
|
||||
source: 'litellm' | 'provider' | 'manual' | 'unknown';
|
||||
}
|
||||
|
||||
export interface ApiRespProviderEmbeddingModels {
|
||||
models: EmbeddingModel[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user