mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-12 22:42:13 +02:00
feat: moved LLMConfigs from User to SearchSpaces
- RBAC soon?? - Updated various services and routes to handle search space-specific LLM preferences. - Modified frontend components to pass search space ID for LLM configuration management. - Removed onboarding page and settings page as part of the refactor.
This commit is contained in:
parent
a1b1db3895
commit
633ea3ac0f
44 changed files with 1075 additions and 518 deletions
|
|
@ -1,12 +1,16 @@
|
|||
"use client";
|
||||
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
import type React from "react";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { DashboardBreadcrumb } from "@/components/dashboard-breadcrumb";
|
||||
import { AppSidebarProvider } from "@/components/sidebar/AppSidebarProvider";
|
||||
import { ThemeTogglerComponent } from "@/components/theme/theme-toggle";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { SidebarInset, SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar";
|
||||
import { useLLMPreferences } from "@/hooks/use-llm-configs";
|
||||
|
||||
export function DashboardClientLayout({
|
||||
children,
|
||||
|
|
@ -19,6 +23,16 @@ export function DashboardClientLayout({
|
|||
navSecondary: any[];
|
||||
navMain: any[];
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchSpaceIdNum = Number(searchSpaceId);
|
||||
|
||||
const { loading, error, isOnboardingComplete } = useLLMPreferences(searchSpaceIdNum);
|
||||
const [hasCheckedOnboarding, setHasCheckedOnboarding] = useState(false);
|
||||
|
||||
// Skip onboarding check if we're already on the onboarding page
|
||||
const isOnboardingPage = pathname?.includes("/onboard");
|
||||
|
||||
const [open, setOpen] = useState<boolean>(() => {
|
||||
try {
|
||||
const match = document.cookie.match(/(?:^|; )sidebar_state=([^;]+)/);
|
||||
|
|
@ -29,6 +43,68 @@ export function DashboardClientLayout({
|
|||
return true;
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
// Skip check if already on onboarding page
|
||||
if (isOnboardingPage) {
|
||||
setHasCheckedOnboarding(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Only check once after preferences have loaded
|
||||
if (!loading && !hasCheckedOnboarding) {
|
||||
const onboardingComplete = isOnboardingComplete();
|
||||
|
||||
if (!onboardingComplete) {
|
||||
router.push(`/dashboard/${searchSpaceId}/onboard`);
|
||||
}
|
||||
|
||||
setHasCheckedOnboarding(true);
|
||||
}
|
||||
}, [
|
||||
loading,
|
||||
isOnboardingComplete,
|
||||
isOnboardingPage,
|
||||
router,
|
||||
searchSpaceId,
|
||||
hasCheckedOnboarding,
|
||||
]);
|
||||
|
||||
// Show loading screen while checking onboarding status (only on first load)
|
||||
if (!hasCheckedOnboarding && loading && !isOnboardingPage) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center min-h-screen space-y-4">
|
||||
<Card className="w-[350px] bg-background/60 backdrop-blur-sm">
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-xl font-medium">Loading Configuration</CardTitle>
|
||||
<CardDescription>Checking your LLM preferences...</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex justify-center py-6">
|
||||
<Loader2 className="h-12 w-12 text-primary animate-spin" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Show error screen if there's an error loading preferences (but not on onboarding page)
|
||||
if (error && !hasCheckedOnboarding && !isOnboardingPage) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center min-h-screen space-y-4">
|
||||
<Card className="w-[400px] bg-background/60 backdrop-blur-sm border-destructive/20">
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-xl font-medium text-destructive">
|
||||
Configuration Error
|
||||
</CardTitle>
|
||||
<CardDescription>Failed to load your LLM configuration</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-sm text-muted-foreground">{error}</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<SidebarProvider open={open} onOpenChange={setOpen}>
|
||||
{/* Use AppSidebarProvider which fetches user, search space, and recent chats */}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,12 @@ export default function DashboardLayout({
|
|||
icon: "SquareTerminal",
|
||||
items: [],
|
||||
},
|
||||
{
|
||||
title: "Manage LLMs",
|
||||
url: `/dashboard/${search_space_id}/settings`,
|
||||
icon: "Settings2",
|
||||
items: [],
|
||||
},
|
||||
|
||||
{
|
||||
title: "Documents",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import { ArrowLeft, ArrowRight, Bot, CheckCircle, Sparkles } from "lucide-react";
|
||||
import { AnimatePresence, motion } from "motion/react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Logo } from "@/components/Logo";
|
||||
import { AddProviderStep } from "@/components/onboard/add-provider-step";
|
||||
|
|
@ -17,13 +17,16 @@ const TOTAL_STEPS = 3;
|
|||
|
||||
const OnboardPage = () => {
|
||||
const router = useRouter();
|
||||
const { llmConfigs, loading: configsLoading, refreshConfigs } = useLLMConfigs();
|
||||
const params = useParams();
|
||||
const searchSpaceId = Number(params.search_space_id);
|
||||
|
||||
const { llmConfigs, loading: configsLoading, refreshConfigs } = useLLMConfigs(searchSpaceId);
|
||||
const {
|
||||
preferences,
|
||||
loading: preferencesLoading,
|
||||
isOnboardingComplete,
|
||||
refreshPreferences,
|
||||
} = useLLMPreferences();
|
||||
} = useLLMPreferences(searchSpaceId);
|
||||
const [currentStep, setCurrentStep] = useState(1);
|
||||
const [hasUserProgressed, setHasUserProgressed] = useState(false);
|
||||
|
||||
|
|
@ -44,11 +47,23 @@ const OnboardPage = () => {
|
|||
}, [currentStep]);
|
||||
|
||||
// Redirect to dashboard if onboarding is already complete and user hasn't progressed (fresh page load)
|
||||
// But only check once to avoid redirect loops
|
||||
useEffect(() => {
|
||||
if (!preferencesLoading && isOnboardingComplete() && !hasUserProgressed) {
|
||||
router.push("/dashboard");
|
||||
if (!preferencesLoading && !configsLoading && isOnboardingComplete() && !hasUserProgressed) {
|
||||
// Small delay to ensure the check is stable
|
||||
const timer = setTimeout(() => {
|
||||
router.push(`/dashboard/${searchSpaceId}`);
|
||||
}, 100);
|
||||
return () => clearTimeout(timer);
|
||||
}
|
||||
}, [preferencesLoading, isOnboardingComplete, hasUserProgressed, router]);
|
||||
}, [
|
||||
preferencesLoading,
|
||||
configsLoading,
|
||||
isOnboardingComplete,
|
||||
hasUserProgressed,
|
||||
router,
|
||||
searchSpaceId,
|
||||
]);
|
||||
|
||||
const progress = (currentStep / TOTAL_STEPS) * 100;
|
||||
|
||||
|
|
@ -80,7 +95,7 @@ const OnboardPage = () => {
|
|||
};
|
||||
|
||||
const handleComplete = () => {
|
||||
router.push("/dashboard");
|
||||
router.push(`/dashboard/${searchSpaceId}/documents`);
|
||||
};
|
||||
|
||||
if (configsLoading || preferencesLoading) {
|
||||
|
|
@ -184,12 +199,18 @@ const OnboardPage = () => {
|
|||
>
|
||||
{currentStep === 1 && (
|
||||
<AddProviderStep
|
||||
searchSpaceId={searchSpaceId}
|
||||
onConfigCreated={refreshConfigs}
|
||||
onConfigDeleted={refreshConfigs}
|
||||
/>
|
||||
)}
|
||||
{currentStep === 2 && <AssignRolesStep onPreferencesUpdated={refreshPreferences} />}
|
||||
{currentStep === 3 && <CompletionStep />}
|
||||
{currentStep === 2 && (
|
||||
<AssignRolesStep
|
||||
searchSpaceId={searchSpaceId}
|
||||
onPreferencesUpdated={refreshPreferences}
|
||||
/>
|
||||
)}
|
||||
{currentStep === 3 && <CompletionStep searchSpaceId={searchSpaceId} />}
|
||||
</motion.div>
|
||||
</AnimatePresence>
|
||||
</CardContent>
|
||||
|
|
@ -1,14 +1,16 @@
|
|||
"use client";
|
||||
|
||||
import { ArrowLeft, Bot, Brain, Settings } from "lucide-react"; // Import ArrowLeft icon
|
||||
import { useRouter } from "next/navigation"; // Add this import
|
||||
import { ArrowLeft, Bot, Brain, Settings } from "lucide-react";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { LLMRoleManager } from "@/components/settings/llm-role-manager";
|
||||
import { ModelConfigManager } from "@/components/settings/model-config-manager";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
|
||||
export default function SettingsPage() {
|
||||
const router = useRouter(); // Initialize router
|
||||
const router = useRouter();
|
||||
const params = useParams();
|
||||
const searchSpaceId = Number(params.search_space_id);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-background">
|
||||
|
|
@ -19,7 +21,7 @@ export default function SettingsPage() {
|
|||
<div className="flex items-center space-x-4">
|
||||
{/* Back Button */}
|
||||
<button
|
||||
onClick={() => router.push("/dashboard")}
|
||||
onClick={() => router.push(`/dashboard/${searchSpaceId}`)}
|
||||
className="flex items-center justify-center h-10 w-10 rounded-lg bg-primary/10 hover:bg-primary/20 transition-colors"
|
||||
aria-label="Back to Dashboard"
|
||||
type="button"
|
||||
|
|
@ -32,7 +34,7 @@ export default function SettingsPage() {
|
|||
<div className="space-y-1">
|
||||
<h1 className="text-3xl font-bold tracking-tight">Settings</h1>
|
||||
<p className="text-lg text-muted-foreground">
|
||||
Manage your LLM configurations and role assignments.
|
||||
Manage your LLM configurations and role assignments for this search space.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -57,11 +59,11 @@ export default function SettingsPage() {
|
|||
</div>
|
||||
|
||||
<TabsContent value="models" className="space-y-6">
|
||||
<ModelConfigManager />
|
||||
<ModelConfigManager searchSpaceId={searchSpaceId} />
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="roles" className="space-y-6">
|
||||
<LLMRoleManager />
|
||||
<LLMRoleManager searchSpaceId={searchSpaceId} />
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
|
|
@ -4,7 +4,6 @@ import { Loader2 } from "lucide-react";
|
|||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { useLLMPreferences } from "@/hooks/use-llm-configs";
|
||||
|
||||
interface DashboardLayoutProps {
|
||||
children: React.ReactNode;
|
||||
|
|
@ -12,7 +11,6 @@ interface DashboardLayoutProps {
|
|||
|
||||
export default function DashboardLayout({ children }: DashboardLayoutProps) {
|
||||
const router = useRouter();
|
||||
const { loading, error, isOnboardingComplete } = useLLMPreferences();
|
||||
const [isCheckingAuth, setIsCheckingAuth] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -25,23 +23,14 @@ export default function DashboardLayout({ children }: DashboardLayoutProps) {
|
|||
setIsCheckingAuth(false);
|
||||
}, [router]);
|
||||
|
||||
useEffect(() => {
|
||||
// Wait for preferences to load, then check if onboarding is complete
|
||||
if (!loading && !error && !isCheckingAuth) {
|
||||
if (!isOnboardingComplete()) {
|
||||
router.push("/onboard");
|
||||
}
|
||||
}
|
||||
}, [loading, error, isCheckingAuth, isOnboardingComplete, router]);
|
||||
|
||||
// Show loading screen while checking authentication or loading preferences
|
||||
if (isCheckingAuth || loading) {
|
||||
// Show loading screen while checking authentication
|
||||
if (isCheckingAuth) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center min-h-screen space-y-4">
|
||||
<Card className="w-[350px] bg-background/60 backdrop-blur-sm">
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-xl font-medium">Loading Dashboard</CardTitle>
|
||||
<CardDescription>Checking your configuration...</CardDescription>
|
||||
<CardDescription>Checking authentication...</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex justify-center py-6">
|
||||
<Loader2 className="h-12 w-12 text-primary animate-spin" />
|
||||
|
|
@ -51,42 +40,5 @@ export default function DashboardLayout({ children }: DashboardLayoutProps) {
|
|||
);
|
||||
}
|
||||
|
||||
// Show error screen if there's an error loading preferences
|
||||
if (error) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center min-h-screen space-y-4">
|
||||
<Card className="w-[400px] bg-background/60 backdrop-blur-sm border-destructive/20">
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-xl font-medium text-destructive">
|
||||
Configuration Error
|
||||
</CardTitle>
|
||||
<CardDescription>Failed to load your LLM configuration</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-sm text-muted-foreground">{error}</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Only render children if onboarding is complete
|
||||
if (isOnboardingComplete()) {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
// This should not be reached due to redirect, but just in case
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center min-h-screen space-y-4">
|
||||
<Card className="w-[350px] bg-background/60 backdrop-blur-sm">
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-xl font-medium">Redirecting...</CardTitle>
|
||||
<CardDescription>Taking you to complete your setup</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex justify-center py-6">
|
||||
<Loader2 className="h-12 w-12 text-primary animate-spin" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,10 +66,6 @@ export function UserDropdown({
|
|||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onClick={() => router.push(`/settings`)}>
|
||||
<Settings className="mr-2 h-4 w-4" />
|
||||
Settings
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={handleLogout}>
|
||||
<LogOut className="mr-2 h-4 w-4" />
|
||||
Log out
|
||||
|
|
|
|||
|
|
@ -332,8 +332,11 @@ const ResearchModeSelector = React.memo(
|
|||
ResearchModeSelector.displayName = "ResearchModeSelector";
|
||||
|
||||
const LLMSelector = React.memo(() => {
|
||||
const { llmConfigs, loading: llmLoading, error } = useLLMConfigs();
|
||||
const { preferences, updatePreferences, loading: preferencesLoading } = useLLMPreferences();
|
||||
const { search_space_id } = useParams();
|
||||
const searchSpaceId = Number(search_space_id);
|
||||
|
||||
const { llmConfigs, loading: llmLoading, error } = useLLMConfigs(searchSpaceId);
|
||||
const { preferences, updatePreferences, loading: preferencesLoading } = useLLMPreferences(searchSpaceId);
|
||||
|
||||
const isLoading = llmLoading || preferencesLoading;
|
||||
|
||||
|
|
|
|||
|
|
@ -23,12 +23,17 @@ import { type CreateLLMConfig, useLLMConfigs } from "@/hooks/use-llm-configs";
|
|||
import InferenceParamsEditor from "../inference-params-editor";
|
||||
|
||||
interface AddProviderStepProps {
|
||||
searchSpaceId: number;
|
||||
onConfigCreated?: () => void;
|
||||
onConfigDeleted?: () => void;
|
||||
}
|
||||
|
||||
export function AddProviderStep({ onConfigCreated, onConfigDeleted }: AddProviderStepProps) {
|
||||
const { llmConfigs, createLLMConfig, deleteLLMConfig } = useLLMConfigs();
|
||||
export function AddProviderStep({
|
||||
searchSpaceId,
|
||||
onConfigCreated,
|
||||
onConfigDeleted,
|
||||
}: AddProviderStepProps) {
|
||||
const { llmConfigs, createLLMConfig, deleteLLMConfig } = useLLMConfigs(searchSpaceId);
|
||||
const [isAddingNew, setIsAddingNew] = useState(false);
|
||||
const [formData, setFormData] = useState<CreateLLMConfig>({
|
||||
name: "",
|
||||
|
|
@ -38,6 +43,7 @@ export function AddProviderStep({ onConfigCreated, onConfigDeleted }: AddProvide
|
|||
api_key: "",
|
||||
api_base: "",
|
||||
litellm_params: {},
|
||||
search_space_id: searchSpaceId,
|
||||
});
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
|
|
@ -65,6 +71,7 @@ export function AddProviderStep({ onConfigCreated, onConfigDeleted }: AddProvide
|
|||
api_key: "",
|
||||
api_base: "",
|
||||
litellm_params: {},
|
||||
search_space_id: searchSpaceId,
|
||||
});
|
||||
setIsAddingNew(false);
|
||||
// Notify parent component that a config was created
|
||||
|
|
@ -253,7 +260,6 @@ export function AddProviderStep({ onConfigCreated, onConfigDeleted }: AddProvide
|
|||
/>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="flex gap-2 pt-4">
|
||||
<Button type="submit" disabled={isSubmitting}>
|
||||
{isSubmitting ? "Adding..." : "Add Provider"}
|
||||
|
|
|
|||
|
|
@ -41,12 +41,13 @@ const ROLE_DESCRIPTIONS = {
|
|||
};
|
||||
|
||||
interface AssignRolesStepProps {
|
||||
searchSpaceId: number;
|
||||
onPreferencesUpdated?: () => Promise<void>;
|
||||
}
|
||||
|
||||
export function AssignRolesStep({ onPreferencesUpdated }: AssignRolesStepProps) {
|
||||
const { llmConfigs } = useLLMConfigs();
|
||||
const { preferences, updatePreferences } = useLLMPreferences();
|
||||
export function AssignRolesStep({ searchSpaceId, onPreferencesUpdated }: AssignRolesStepProps) {
|
||||
const { llmConfigs } = useLLMConfigs(searchSpaceId);
|
||||
const { preferences, updatePreferences } = useLLMPreferences(searchSpaceId);
|
||||
|
||||
const [assignments, setAssignments] = useState({
|
||||
long_context_llm_id: preferences.long_context_llm_id || "",
|
||||
|
|
|
|||
|
|
@ -12,9 +12,13 @@ const ROLE_ICONS = {
|
|||
strategic: Bot,
|
||||
};
|
||||
|
||||
export function CompletionStep() {
|
||||
const { llmConfigs } = useLLMConfigs();
|
||||
const { preferences } = useLLMPreferences();
|
||||
interface CompletionStepProps {
|
||||
searchSpaceId: number;
|
||||
}
|
||||
|
||||
export function CompletionStep({ searchSpaceId }: CompletionStepProps) {
|
||||
const { llmConfigs } = useLLMConfigs(searchSpaceId);
|
||||
const { preferences } = useLLMPreferences(searchSpaceId);
|
||||
|
||||
const assignedConfigs = {
|
||||
long_context: llmConfigs.find((c) => c.id === preferences.long_context_llm_id),
|
||||
|
|
|
|||
|
|
@ -56,20 +56,24 @@ const ROLE_DESCRIPTIONS = {
|
|||
},
|
||||
};
|
||||
|
||||
export function LLMRoleManager() {
|
||||
interface LLMRoleManagerProps {
|
||||
searchSpaceId: number;
|
||||
}
|
||||
|
||||
export function LLMRoleManager({ searchSpaceId }: LLMRoleManagerProps) {
|
||||
const {
|
||||
llmConfigs,
|
||||
loading: configsLoading,
|
||||
error: configsError,
|
||||
refreshConfigs,
|
||||
} = useLLMConfigs();
|
||||
} = useLLMConfigs(searchSpaceId);
|
||||
const {
|
||||
preferences,
|
||||
loading: preferencesLoading,
|
||||
error: preferencesError,
|
||||
updatePreferences,
|
||||
refreshPreferences,
|
||||
} = useLLMPreferences();
|
||||
} = useLLMPreferences(searchSpaceId);
|
||||
|
||||
const [assignments, setAssignments] = useState({
|
||||
long_context_llm_id: preferences.long_context_llm_id || "",
|
||||
|
|
|
|||
|
|
@ -41,7 +41,11 @@ import { LLM_PROVIDERS } from "@/contracts/enums/llm-providers";
|
|||
import { type CreateLLMConfig, type LLMConfig, useLLMConfigs } from "@/hooks/use-llm-configs";
|
||||
import InferenceParamsEditor from "../inference-params-editor";
|
||||
|
||||
export function ModelConfigManager() {
|
||||
interface ModelConfigManagerProps {
|
||||
searchSpaceId: number;
|
||||
}
|
||||
|
||||
export function ModelConfigManager({ searchSpaceId }: ModelConfigManagerProps) {
|
||||
const {
|
||||
llmConfigs,
|
||||
loading,
|
||||
|
|
@ -50,7 +54,7 @@ export function ModelConfigManager() {
|
|||
updateLLMConfig,
|
||||
deleteLLMConfig,
|
||||
refreshConfigs,
|
||||
} = useLLMConfigs();
|
||||
} = useLLMConfigs(searchSpaceId);
|
||||
const [isAddingNew, setIsAddingNew] = useState(false);
|
||||
const [editingConfig, setEditingConfig] = useState<LLMConfig | null>(null);
|
||||
const [showApiKey, setShowApiKey] = useState<Record<number, boolean>>({});
|
||||
|
|
@ -62,6 +66,7 @@ export function ModelConfigManager() {
|
|||
api_key: "",
|
||||
api_base: "",
|
||||
litellm_params: {},
|
||||
search_space_id: searchSpaceId,
|
||||
});
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
|
|
@ -76,9 +81,10 @@ export function ModelConfigManager() {
|
|||
api_key: editingConfig.api_key,
|
||||
api_base: editingConfig.api_base || "",
|
||||
litellm_params: editingConfig.litellm_params || {},
|
||||
search_space_id: searchSpaceId,
|
||||
});
|
||||
}
|
||||
}, [editingConfig]);
|
||||
}, [editingConfig, searchSpaceId]);
|
||||
|
||||
const handleInputChange = (field: keyof CreateLLMConfig, value: string) => {
|
||||
setFormData((prev) => ({ ...prev, [field]: value }));
|
||||
|
|
@ -113,6 +119,7 @@ export function ModelConfigManager() {
|
|||
api_key: "",
|
||||
api_base: "",
|
||||
litellm_params: {},
|
||||
search_space_id: searchSpaceId,
|
||||
});
|
||||
setIsAddingNew(false);
|
||||
setEditingConfig(null);
|
||||
|
|
@ -426,6 +433,7 @@ export function ModelConfigManager() {
|
|||
api_key: "",
|
||||
api_base: "",
|
||||
litellm_params: {},
|
||||
search_space_id: searchSpaceId,
|
||||
});
|
||||
}
|
||||
}}
|
||||
|
|
@ -462,18 +470,12 @@ export function ModelConfigManager() {
|
|||
value={formData.provider}
|
||||
onValueChange={(value) => handleInputChange("provider", value)}
|
||||
>
|
||||
<SelectTrigger className="h-auto min-h-[2.5rem] py-2">
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select a provider">
|
||||
{formData.provider && (
|
||||
<div className="flex items-center space-x-2 py-1">
|
||||
<div className="font-medium">
|
||||
{LLM_PROVIDERS.find((p) => p.value === formData.provider)?.label}
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground">•</div>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
{LLM_PROVIDERS.find((p) => p.value === formData.provider)?.description}
|
||||
</div>
|
||||
</div>
|
||||
<span className="font-medium">
|
||||
{LLM_PROVIDERS.find((p) => p.value === formData.provider)?.label}
|
||||
</span>
|
||||
)}
|
||||
</SelectValue>
|
||||
</SelectTrigger>
|
||||
|
|
@ -549,7 +551,7 @@ export function ModelConfigManager() {
|
|||
<InferenceParamsEditor
|
||||
params={formData.litellm_params || {}}
|
||||
setParams={(newParams) =>
|
||||
setFormData((prev) => ({ ...prev, litellm_params: newParams }))
|
||||
setFormData((prev) => ({ ...prev, litellm_params: newParams }))
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
|
@ -578,6 +580,7 @@ export function ModelConfigManager() {
|
|||
api_key: "",
|
||||
api_base: "",
|
||||
litellm_params: {},
|
||||
search_space_id: searchSpaceId,
|
||||
});
|
||||
}}
|
||||
disabled={isSubmitting}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ export interface LLMConfig {
|
|||
api_base?: string;
|
||||
litellm_params?: Record<string, any>;
|
||||
created_at: string;
|
||||
user_id: string;
|
||||
search_space_id: number;
|
||||
}
|
||||
|
||||
export interface LLMPreferences {
|
||||
|
|
@ -32,6 +32,7 @@ export interface CreateLLMConfig {
|
|||
api_key: string;
|
||||
api_base?: string;
|
||||
litellm_params?: Record<string, any>;
|
||||
search_space_id: number;
|
||||
}
|
||||
|
||||
export interface UpdateLLMConfig {
|
||||
|
|
@ -44,16 +45,21 @@ export interface UpdateLLMConfig {
|
|||
litellm_params?: Record<string, any>;
|
||||
}
|
||||
|
||||
export function useLLMConfigs() {
|
||||
export function useLLMConfigs(searchSpaceId: number | null) {
|
||||
const [llmConfigs, setLlmConfigs] = useState<LLMConfig[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const fetchLLMConfigs = async () => {
|
||||
if (!searchSpaceId) {
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/llm-configs/`,
|
||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/llm-configs/?search_space_id=${searchSpaceId}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${localStorage.getItem("surfsense_bearer_token")}`,
|
||||
|
|
@ -79,7 +85,7 @@ export function useLLMConfigs() {
|
|||
|
||||
useEffect(() => {
|
||||
fetchLLMConfigs();
|
||||
}, []);
|
||||
}, [searchSpaceId]);
|
||||
|
||||
const createLLMConfig = async (config: CreateLLMConfig): Promise<LLMConfig | null> => {
|
||||
try {
|
||||
|
|
@ -181,16 +187,21 @@ export function useLLMConfigs() {
|
|||
};
|
||||
}
|
||||
|
||||
export function useLLMPreferences() {
|
||||
export function useLLMPreferences(searchSpaceId: number | null) {
|
||||
const [preferences, setPreferences] = useState<LLMPreferences>({});
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const fetchPreferences = async () => {
|
||||
if (!searchSpaceId) {
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/users/me/llm-preferences`,
|
||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/llm-preferences`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${localStorage.getItem("surfsense_bearer_token")}`,
|
||||
|
|
@ -216,12 +227,17 @@ export function useLLMPreferences() {
|
|||
|
||||
useEffect(() => {
|
||||
fetchPreferences();
|
||||
}, []);
|
||||
}, [searchSpaceId]);
|
||||
|
||||
const updatePreferences = async (newPreferences: Partial<LLMPreferences>): Promise<boolean> => {
|
||||
if (!searchSpaceId) {
|
||||
toast.error("Search space ID is required");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/users/me/llm-preferences`,
|
||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/llm-preferences`,
|
||||
{
|
||||
method: "PUT",
|
||||
headers: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue