refactor(chat): derive model options from agent detail
parent
f665030ee6
commit
d6b416f5e7
|
|
@ -6,14 +6,12 @@ import ReactMarkdown from 'react-markdown';
|
|||
import {
|
||||
Agent,
|
||||
AgentAPI,
|
||||
AgentAllowedLLMResponse,
|
||||
BranchInfo,
|
||||
ChatAPI,
|
||||
ChatAttachment,
|
||||
ChatAttachmentsAPI,
|
||||
ChatMessage,
|
||||
ImageAPI,
|
||||
LLMProviderAPI,
|
||||
ModelOverrides,
|
||||
RetrievedSnippet,
|
||||
SessionAPI,
|
||||
|
|
@ -32,8 +30,8 @@ interface StreamingState {
|
|||
toolCalls: ToolCallTrace[];
|
||||
}
|
||||
|
||||
const parseAllowedModels = (payload?: Pick<AgentAllowedLLMResponse, 'model'> | null) =>
|
||||
String(payload?.model || '')
|
||||
const parseAgentModels = (value?: string) =>
|
||||
String(value || '')
|
||||
.split(',')
|
||||
.map((item) => item.trim())
|
||||
.filter(Boolean);
|
||||
|
|
@ -58,7 +56,6 @@ export default function ChatPage() {
|
|||
const [paramsDrawerOpen, setParamsDrawerOpen] = useState(false);
|
||||
const [tplDrawerOpen, setTplDrawerOpen] = useState(false);
|
||||
const [overrides, setOverrides] = useState<ModelOverrides>({});
|
||||
const [allowedModels, setAllowedModels] = useState<string[]>([]);
|
||||
const [attachments, setAttachments] = useState<ChatAttachment[]>([]);
|
||||
const [imageUrls, setImageUrls] = useState<string[]>([]);
|
||||
const [uploadingAtt, setUploadingAtt] = useState(false);
|
||||
|
|
@ -111,16 +108,6 @@ export default function ChatPage() {
|
|||
}
|
||||
};
|
||||
|
||||
const loadAllowedModels = async (agentId: string) => {
|
||||
try {
|
||||
const result = await LLMProviderAPI.allowedModels(agentId);
|
||||
setAllowedModels(parseAllowedModels(result));
|
||||
} catch (e: any) {
|
||||
setAllowedModels([]);
|
||||
msg.error('加载智能体模型失败:' + (e?.message ?? e));
|
||||
}
|
||||
};
|
||||
|
||||
const loadMessages = async () => {
|
||||
if (!id || !sessionId) return;
|
||||
const his = await ChatAPI.history(id, sessionId);
|
||||
|
|
@ -147,12 +134,10 @@ export default function ChatPage() {
|
|||
if (!id) {
|
||||
setAgent(null);
|
||||
setMessages([]);
|
||||
setAllowedModels([]);
|
||||
setOverrides({});
|
||||
return () => abortRef.current?.abort();
|
||||
}
|
||||
loadAgent();
|
||||
loadAllowedModels(id);
|
||||
setOverrides({});
|
||||
return () => abortRef.current?.abort();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
|
|
@ -413,17 +398,18 @@ export default function ChatPage() {
|
|||
|
||||
const isImageUrl = (url: string) => url?.startsWith('http') || url?.startsWith('/');
|
||||
const agentModel = agent?.model || '';
|
||||
const modelOptions = allowedModels.map((modelName) => ({
|
||||
const agentModels = parseAgentModels(agentModel);
|
||||
const modelOptions = agentModels.map((modelName) => ({
|
||||
value: modelName,
|
||||
label: modelName
|
||||
}));
|
||||
const activeModelValue = overrides.model || '';
|
||||
const defaultModelLabel = allowedModels.length > 0 ? allowedModels.join(', ') : agentModel || '默认模型';
|
||||
const defaultModelLabel = agentModel || '默认模型';
|
||||
const selectedModelKey = activeModelValue || '__default__';
|
||||
const modelSelectOptions = [
|
||||
{
|
||||
value: '__default__',
|
||||
label: `跟随默认 · ${defaultModelLabel}`
|
||||
label: defaultModelLabel
|
||||
},
|
||||
...modelOptions
|
||||
];
|
||||
|
|
|
|||
Loading…
Reference in New Issue