validated

This commit is contained in:
pablodanswer 2024-10-16 12:00:29 -07:00
parent d73c70caff
commit 1ef1e17629
11 changed files with 74 additions and 61 deletions

View File

@ -134,7 +134,7 @@ POSTGRES_PASSWORD = urllib.parse.quote_plus(
os.environ.get("POSTGRES_PASSWORD") or "password"
)
POSTGRES_HOST = os.environ.get("POSTGRES_HOST") or "localhost"
POSTGRES_PORT = os.environ.get("POSTGRES_PORT") or "5433"
POSTGRES_PORT = os.environ.get("POSTGRES_PORT") or "5432"
POSTGRES_DB = os.environ.get("POSTGRES_DB") or "postgres"
POSTGRES_API_SERVER_POOL_SIZE = int(

View File

@ -26,8 +26,6 @@ def get_notifications_api(
NotificationModel.from_model(notif)
for notif in get_notifications(user, db_session, include_dismissed=False)
]
print(user)
print(len(notificatinos))
return notificatinos

View File

@ -232,8 +232,6 @@ def list_personas(
include_deleted: bool = False,
persona_ids: list[int] = Query(None),
) -> list[PersonaSnapshot]:
print("LISTING PERSONAS")
print("user", user)
personas = get_personas(
user=user,
include_deleted=include_deleted,
@ -254,7 +252,6 @@ def list_personas(
and not is_image_generation_available(db_session=db_session)
)
]
print(len(personas))
return [PersonaSnapshot.from_model(p) for p in personas]

View File

@ -312,7 +312,7 @@ services:
- POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password}
ports:
- "5433:5432"
- "5432:5432"
volumes:
- db_volume:/var/lib/postgresql/data

View File

@ -312,7 +312,7 @@ services:
- POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password}
ports:
- "5433:5432"
- "5432:5432"
volumes:
- db_volume:/var/lib/postgresql/data

View File

@ -157,7 +157,7 @@ services:
- POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password}
ports:
- "5433"
- "5432"
volumes:
- db_volume:/var/lib/postgresql/data

View File

@ -1,6 +1,12 @@
"use client";
import React, { Dispatch, SetStateAction, useEffect, useState } from "react";
import React, {
Dispatch,
SetStateAction,
use,
useEffect,
useState,
} from "react";
import { MinimalUserSnapshot, User } from "@/lib/types";
import { Persona } from "@/app/admin/assistants/interfaces";
import { Button, Divider } from "@tremor/react";
@ -62,6 +68,7 @@ import {
} from "@/lib/assistants/utils";
import { CustomTooltip } from "@/components/tooltip/CustomTooltip";
import { useAssistants } from "@/components/context/AssisantsContext";
import { useUser } from "@/components/user/UserProvider";
function DraggableAssistantListItem(props: any) {
const {
@ -285,27 +292,20 @@ function AssistantListItem({
</>
);
}
export function AssistantsList({ user }: { user: User | null }) {
const { assistants } = useAssistants();
// Define the distinct groups of assistants
const { visibleAssistants, hiddenAssistants } = classifyAssistants(
user,
assistants
);
export function AssistantsList() {
const {
assistants,
ownedButHiddenAssistants,
finalAssistants,
refreshAssistants,
} = useAssistants();
const [currentlyVisibleAssistants, setCurrentlyVisibleAssistants] = useState<
Persona[]
>([]);
const [currentlyVisibleAssistants, setCurrentlyVisibleAssistants] =
useState(finalAssistants);
useEffect(() => {
const orderedAssistants = orderAssistantsForUser(visibleAssistants, user);
setCurrentlyVisibleAssistants(orderedAssistants);
}, [assistants, user]);
const ownedButHiddenAssistants = getUserCreatedAssistants(
user,
hiddenAssistants
);
setCurrentlyVisibleAssistants(finalAssistants);
}, [finalAssistants]);
const allAssistantIds = assistants.map((assistant) =>
assistant.id.toString()
@ -316,6 +316,8 @@ export function AssistantsList({ user }: { user: User | null }) {
null
);
const { refreshUser, user } = useUser();
const { popup, setPopup } = usePopup();
const router = useRouter();
const { data: users } = useSWR<MinimalUserSnapshot[]>(
@ -334,18 +336,22 @@ export function AssistantsList({ user }: { user: User | null }) {
const { active, over } = event;
if (over && active.id !== over.id) {
setCurrentlyVisibleAssistants((assistants) => {
const oldIndex = assistants.findIndex(
(a) => a.id.toString() === active.id
);
const newIndex = assistants.findIndex(
(a) => a.id.toString() === over.id
);
const newAssistants = arrayMove(assistants, oldIndex, newIndex);
const oldIndex = currentlyVisibleAssistants.findIndex(
(item) => item.id.toString() === active.id
);
const newIndex = currentlyVisibleAssistants.findIndex(
(item) => item.id.toString() === over.id
);
const updatedAssistants = arrayMove(
currentlyVisibleAssistants,
oldIndex,
newIndex
);
updateUserAssistantList(newAssistants.map((a) => a.id));
return newAssistants;
});
setCurrentlyVisibleAssistants(updatedAssistants);
await updateUserAssistantList(updatedAssistants.map((a) => a.id));
await refreshUser();
await refreshAssistants();
}
}

View File

@ -101,10 +101,6 @@ import ExceptionTraceModal from "@/components/modals/ExceptionTraceModal";
import { SEARCH_TOOL_NAME } from "./tools/constants";
import { useUser } from "@/components/user/UserProvider";
import { ApiKeyModal } from "@/components/llm/ApiKeyModal";
import {
classifyAssistants,
orderAssistantsForUser,
} from "@/lib/assistants/utils";
import BlurBackground from "./shared_chat_search/BlurBackground";
import { NoAssistantModal } from "@/components/modals/NoAssistantModal";
import { useAssistants } from "@/components/context/AssisantsContext";

View File

@ -8,7 +8,6 @@ import {
import { errorHandlingFetcher } from "@/lib/fetcher";
import { AssistantIcon } from "@/components/assistants/AssistantIcon";
import { addAssistantToList } from "@/lib/assistants/updateAssistantPreferences";
import { useChatContext } from "../context/ChatContext";
import { useAssistants } from "../context/AssisantsContext";
import { useUser } from "../user/UserProvider";

View File

@ -1,22 +1,19 @@
"use client";
import React, {
createContext,
useState,
useEffect,
useContext,
useMemo,
} from "react";
import React, { createContext, useState, useContext, useMemo } from "react";
import { Persona } from "@/app/admin/assistants/interfaces";
import { User } from "@/lib/types";
import {
classifyAssistants,
orderAssistantsForUser,
getUserCreatedAssistants,
} from "@/lib/assistants/utils";
import { useUser } from "../user/UserProvider";
interface AssistantsContextProps {
assistants: Persona[];
visibleAssistants: Persona[];
hiddenAssistants: Persona[];
finalAssistants: Persona[];
ownedButHiddenAssistants: Persona[];
refreshAssistants: () => Promise<void>;
}
@ -43,27 +40,48 @@ export const AssistantsProvider: React.FC<{
});
if (!response.ok) throw new Error("Failed to fetch assistants");
const assistants = await response.json();
console.log("ASSISTANTS ARE", assistants);
setAssistants(assistants);
} catch (error) {
console.error("Error refreshing assistants:", error);
}
};
const { finalAssistants } = useMemo(() => {
const { visibleAssistants } = classifyAssistants(user, assistants);
console.log("VISIBLE ASSISTANTS", visibleAssistants);
const {
visibleAssistants,
hiddenAssistants,
finalAssistants,
ownedButHiddenAssistants,
} = useMemo(() => {
const { visibleAssistants, hiddenAssistants } = classifyAssistants(
user,
assistants
);
const finalAssistants = user
? orderAssistantsForUser(visibleAssistants, user)
: visibleAssistants;
console.log("FINAL ASSISTANTS", finalAssistants);
return { finalAssistants };
const ownedButHiddenAssistants = getUserCreatedAssistants(
user,
hiddenAssistants
);
return {
visibleAssistants,
hiddenAssistants,
finalAssistants,
ownedButHiddenAssistants,
};
}, [user, assistants]);
return (
<AssistantsContext.Provider
value={{ assistants, finalAssistants, refreshAssistants }}
value={{
assistants,
visibleAssistants,
hiddenAssistants,
finalAssistants,
ownedButHiddenAssistants,
refreshAssistants,
}}
>
{children}
</AssistantsContext.Provider>

View File

@ -24,7 +24,6 @@ export function UserProvider({ children }: { children: React.ReactNode }) {
try {
const user = await getCurrentUser();
setUser(user);
console.log("user has been updated");
setIsAdmin(user?.role === UserRole.ADMIN);
setIsCurator(
user?.role === UserRole.CURATOR || user?.role == UserRole.GLOBAL_CURATOR