mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-04 21:32:39 +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
|
|
@ -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