mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 21:19:12 +00:00
Improve default selection of models to avoid infinite loops
This commit is contained in:
@@ -49,13 +49,16 @@ export function ModelSelector({ ...props }: ModelSelectorProps) {
|
|||||||
setModels(userConfig.chat_model_options);
|
setModels(userConfig.chat_model_options);
|
||||||
if (!props.initialModel) {
|
if (!props.initialModel) {
|
||||||
const selectedChatModelOption = userConfig.chat_model_options.find(model => model.id === userConfig.selected_chat_model_config);
|
const selectedChatModelOption = userConfig.chat_model_options.find(model => model.id === userConfig.selected_chat_model_config);
|
||||||
setSelectedModel(selectedChatModelOption);
|
if (!selectedChatModelOption) {
|
||||||
|
setSelectedModel(userConfig.chat_model_options[0]);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
setSelectedModel(selectedChatModelOption);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const model = userConfig.chat_model_options.find(model => model.name === props.initialModel);
|
const model = userConfig.chat_model_options.find(model => model.name === props.initialModel);
|
||||||
setSelectedModel(model);
|
setSelectedModel(model);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
setSelectedModel(models[0]);
|
|
||||||
}
|
}
|
||||||
}, [userConfig, props.initialModel, isLoadingUserConfig]);
|
}, [userConfig, props.initialModel, isLoadingUserConfig]);
|
||||||
|
|
||||||
|
|||||||
@@ -57,9 +57,8 @@ export function ChatSidebar({ ...props }: ChatSideBarProps) {
|
|||||||
|
|
||||||
function ChatSidebarInternal({ ...props }: ChatSideBarProps) {
|
function ChatSidebarInternal({ ...props }: ChatSideBarProps) {
|
||||||
const [isEditable, setIsEditable] = useState<boolean>(false);
|
const [isEditable, setIsEditable] = useState<boolean>(false);
|
||||||
const [isDefaultAgent, setIsDefaultAgent] = useState<boolean>(true);
|
|
||||||
const { data: agentConfigurationOptions, error: agentConfigurationOptionsError } =
|
const { data: agentConfigurationOptions, error: agentConfigurationOptionsError } =
|
||||||
useSWR<AgentConfigurationOptions>("/api/agents/options", fetcher);
|
useSWR<AgentConfigurationOptions>("/api/agents/options", fetcher);
|
||||||
|
|
||||||
const { data: agentData, isLoading: agentDataLoading, error: agentDataError } = useSWR<AgentData>(`/api/agents/conversation?conversation_id=${props.conversationId}`, fetcher);
|
const { data: agentData, isLoading: agentDataLoading, error: agentDataError } = useSWR<AgentData>(`/api/agents/conversation?conversation_id=${props.conversationId}`, fetcher);
|
||||||
const {
|
const {
|
||||||
@@ -73,6 +72,7 @@ function ChatSidebarInternal({ ...props }: ChatSideBarProps) {
|
|||||||
const [inputTools, setInputTools] = useState<string[] | undefined>();
|
const [inputTools, setInputTools] = useState<string[] | undefined>();
|
||||||
const [outputModes, setOutputModes] = useState<string[] | undefined>();
|
const [outputModes, setOutputModes] = useState<string[] | undefined>();
|
||||||
const [hasModified, setHasModified] = useState<boolean>(false);
|
const [hasModified, setHasModified] = useState<boolean>(false);
|
||||||
|
const [isDefaultAgent, setIsDefaultAgent] = useState<boolean>(agentData?.slug.toLowerCase() === "khoj" ? true : false);
|
||||||
|
|
||||||
const [isSaving, setIsSaving] = useState<boolean>(false);
|
const [isSaving, setIsSaving] = useState<boolean>(false);
|
||||||
|
|
||||||
@@ -94,6 +94,7 @@ function ChatSidebarInternal({ ...props }: ChatSideBarProps) {
|
|||||||
if (agentData.slug.toLowerCase() === "khoj") {
|
if (agentData.slug.toLowerCase() === "khoj") {
|
||||||
setSelectedModel(undefined);
|
setSelectedModel(undefined);
|
||||||
setCustomPrompt(undefined);
|
setCustomPrompt(undefined);
|
||||||
|
setIsDefaultAgent(true);
|
||||||
} else {
|
} else {
|
||||||
setIsDefaultAgent(false);
|
setIsDefaultAgent(false);
|
||||||
setCustomPrompt(agentData.persona);
|
setCustomPrompt(agentData.persona);
|
||||||
@@ -248,30 +249,34 @@ function ChatSidebarInternal({ ...props }: ChatSideBarProps) {
|
|||||||
</SidebarMenu>
|
</SidebarMenu>
|
||||||
</SidebarGroupContent>
|
</SidebarGroupContent>
|
||||||
</SidebarGroup>
|
</SidebarGroup>
|
||||||
<SidebarGroup key={"model"}>
|
{
|
||||||
<SidebarGroupContent>
|
!agentDataLoading && agentData && (
|
||||||
<SidebarGroupLabel>
|
<SidebarGroup key={"model"}>
|
||||||
Model
|
<SidebarGroupContent>
|
||||||
{
|
<SidebarGroupLabel>
|
||||||
!authenticatedData?.is_active && (
|
Model
|
||||||
<a href="/settings" className="hover:font-bold text-accent-foreground m-2 bg-accent bg-opacity-10 p-1 rounded-lg">
|
{
|
||||||
Upgrade
|
!authenticatedData?.is_active && (
|
||||||
</a>
|
<a href="/settings" className="hover:font-bold text-accent-foreground m-2 bg-accent bg-opacity-10 p-1 rounded-lg">
|
||||||
)
|
Upgrade
|
||||||
}
|
</a>
|
||||||
</SidebarGroupLabel>
|
)
|
||||||
<SidebarMenu className="p-0 m-0">
|
}
|
||||||
<SidebarMenuItem key={"model"} className="list-none">
|
</SidebarGroupLabel>
|
||||||
<ModelSelector
|
<SidebarMenu className="p-0 m-0">
|
||||||
disabled={!isEditable || !authenticatedData?.is_active}
|
<SidebarMenuItem key={"model"} className="list-none">
|
||||||
onSelect={(model, userModification) => handleModelSelect(model.name, userModification)}
|
<ModelSelector
|
||||||
initialModel={isDefaultAgent ? '' : agentData?.chat_model}
|
disabled={!isEditable || !authenticatedData?.is_active}
|
||||||
selectedModel={selectedModel}
|
onSelect={(model, userModification) => handleModelSelect(model.name, userModification)}
|
||||||
/>
|
initialModel={isDefaultAgent ? undefined : agentData?.chat_model}
|
||||||
</SidebarMenuItem>
|
selectedModel={selectedModel}
|
||||||
</SidebarMenu>
|
/>
|
||||||
</SidebarGroupContent>
|
</SidebarMenuItem>
|
||||||
</SidebarGroup>
|
</SidebarMenu>
|
||||||
|
</SidebarGroupContent>
|
||||||
|
</SidebarGroup>
|
||||||
|
)
|
||||||
|
}
|
||||||
<Popover defaultOpen={false}>
|
<Popover defaultOpen={false}>
|
||||||
<SidebarGroup>
|
<SidebarGroup>
|
||||||
<SidebarGroupLabel asChild>
|
<SidebarGroupLabel asChild>
|
||||||
|
|||||||
Reference in New Issue
Block a user