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