mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-15 01:21:48 +03:00
refactor: remove explore route from back & front (#1741)
# Description - Removes the explore route from back & front as it has been replaced by the knowledge route
This commit is contained in:
parent
0782df5e37
commit
9858a484a1
@ -22,7 +22,6 @@ from routes.brain_routes import brain_router
|
||||
from routes.chat_routes import chat_router
|
||||
from routes.contact_routes import router as contact_router
|
||||
from routes.crawl_routes import crawl_router
|
||||
from routes.explore_routes import explore_router
|
||||
from routes.knowledge_routes import knowledge_router
|
||||
from routes.misc_routes import misc_router
|
||||
from routes.subscription_routes import subscription_router
|
||||
@ -66,7 +65,6 @@ app.include_router(brain_router)
|
||||
app.include_router(chat_router)
|
||||
app.include_router(crawl_router)
|
||||
app.include_router(onboarding_router)
|
||||
app.include_router(explore_router)
|
||||
app.include_router(misc_router)
|
||||
|
||||
app.include_router(upload_router)
|
||||
|
@ -1,82 +0,0 @@
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from middlewares.auth import AuthBearer, get_current_user
|
||||
from models import Brain, get_supabase_db
|
||||
from modules.user.entity.user_identity import UserIdentity
|
||||
from routes.authorizations.brain_authorization import (
|
||||
RoleEnum,
|
||||
has_brain_authorization,
|
||||
validate_brain_authorization,
|
||||
)
|
||||
|
||||
explore_router = APIRouter()
|
||||
|
||||
|
||||
@explore_router.get("/explore/", dependencies=[Depends(AuthBearer())], tags=["Explore"])
|
||||
async def explore_endpoint(
|
||||
brain_id: UUID = Query(..., description="The ID of the brain"),
|
||||
):
|
||||
"""
|
||||
Retrieve and explore unique user data vectors.
|
||||
"""
|
||||
brain = Brain(id=brain_id)
|
||||
unique_data = brain.get_unique_brain_files()
|
||||
|
||||
unique_data.sort(key=lambda x: int(x["size"]), reverse=True)
|
||||
return {"documents": unique_data}
|
||||
|
||||
|
||||
@explore_router.delete(
|
||||
"/explore/{file_name}/",
|
||||
dependencies=[
|
||||
Depends(AuthBearer()),
|
||||
Depends(has_brain_authorization(RoleEnum.Owner)),
|
||||
],
|
||||
tags=["Explore"],
|
||||
)
|
||||
async def delete_endpoint(
|
||||
file_name: str,
|
||||
current_user: UserIdentity = Depends(get_current_user),
|
||||
brain_id: UUID = Query(..., description="The ID of the brain"),
|
||||
):
|
||||
"""
|
||||
Delete a specific user file by file name.
|
||||
"""
|
||||
brain = Brain(id=brain_id)
|
||||
brain.delete_file_from_brain(file_name)
|
||||
|
||||
return {
|
||||
"message": f"{file_name} of brain {brain_id} has been deleted by user {current_user.email}."
|
||||
}
|
||||
|
||||
|
||||
@explore_router.get(
|
||||
"/explore/{file_name}/", dependencies=[Depends(AuthBearer())], tags=["Explore"]
|
||||
)
|
||||
async def download_endpoint(
|
||||
file_name: str, current_user: UserIdentity = Depends(get_current_user)
|
||||
):
|
||||
"""
|
||||
Download a specific user file by file name.
|
||||
"""
|
||||
# check if user has the right to get the file: add brain_id to the query
|
||||
|
||||
supabase_db = get_supabase_db()
|
||||
response = supabase_db.get_vectors_by_file_name(file_name)
|
||||
documents = response.data
|
||||
|
||||
if len(documents) == 0:
|
||||
return {"documents": []}
|
||||
|
||||
related_brain_id = (
|
||||
documents[0]["brains_vectors"][0]["brain_id"]
|
||||
if len(documents[0]["brains_vectors"]) != 0
|
||||
else None
|
||||
)
|
||||
if related_brain_id is None:
|
||||
raise Exception(f"File {file_name} has no brain_id associated with it")
|
||||
|
||||
validate_brain_authorization(brain_id=related_brain_id, user_id=current_user.id)
|
||||
|
||||
return {"documents": documents}
|
@ -1,21 +0,0 @@
|
||||
def test_explore_with_default_brain(client, api_key):
|
||||
# Retrieve the default brain
|
||||
brain_response = client.get(
|
||||
"/brains/default", headers={"Authorization": "Bearer " + api_key}
|
||||
)
|
||||
assert brain_response.status_code == 200
|
||||
default_brain_id = brain_response.json()["id"]
|
||||
|
||||
# Now use the default brain_id as parameter in the /explore/ endpoint
|
||||
response = client.get(
|
||||
f"/explore/{default_brain_id}",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
)
|
||||
|
||||
# Assert that the response status code is 200 (HTTP OK)
|
||||
assert response.status_code == 200
|
||||
|
||||
# Optionally, you can assert on specific fields in the response data
|
||||
response_data = response.json()
|
||||
# e.g., assert that the response contains a 'results' field
|
||||
assert "documents" in response_data
|
@ -42,19 +42,6 @@ describe("useBrainApi", () => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("should call getBrainDocuments with the correct parameters", async () => {
|
||||
const {
|
||||
result: {
|
||||
current: { getBrainDocuments },
|
||||
},
|
||||
} = renderHook(() => useBrainApi());
|
||||
const brainId = "123";
|
||||
await getBrainDocuments(brainId);
|
||||
|
||||
expect(axiosGetMock).toHaveBeenCalledTimes(1);
|
||||
expect(axiosGetMock).toHaveBeenCalledWith(`/explore/?brain_id=${brainId}`);
|
||||
});
|
||||
|
||||
it("should call createBrain with the correct parameters", async () => {
|
||||
const {
|
||||
result: {
|
||||
|
@ -8,7 +8,6 @@ import {
|
||||
MinimalBrainForUser,
|
||||
PublicBrain,
|
||||
} from "@/lib/context/BrainProvider/types";
|
||||
import { Document } from "@/lib/types/Document";
|
||||
|
||||
import {
|
||||
CreateBrainInput,
|
||||
@ -22,17 +21,6 @@ import {
|
||||
} from "./utils/mapSubscriptionToBackendSubscription";
|
||||
import { mapSubscriptionUpdatablePropertiesToBackendSubscriptionUpdatableProperties } from "./utils/mapSubscriptionUpdatablePropertiesToBackendSubscriptionUpdatableProperties";
|
||||
|
||||
export const getBrainDocuments = async (
|
||||
brainId: string,
|
||||
axiosInstance: AxiosInstance
|
||||
): Promise<Document[]> => {
|
||||
const response = await axiosInstance.get<{ documents: Document[] }>(
|
||||
`/explore/?brain_id=${brainId}`
|
||||
);
|
||||
|
||||
return response.data.documents;
|
||||
};
|
||||
|
||||
export const createBrain = async (
|
||||
brain: CreateBrainInput,
|
||||
axiosInstance: AxiosInstance
|
||||
|
@ -5,7 +5,6 @@ import {
|
||||
createBrain,
|
||||
deleteBrain,
|
||||
getBrain,
|
||||
getBrainDocuments,
|
||||
getBrains,
|
||||
getBrainUsers,
|
||||
getDefaultBrain,
|
||||
@ -27,8 +26,6 @@ export const useBrainApi = () => {
|
||||
const { axiosInstance } = useAxios();
|
||||
|
||||
return {
|
||||
getBrainDocuments: async (brainId: string) =>
|
||||
getBrainDocuments(brainId, axiosInstance),
|
||||
createBrain: async (brain: CreateBrainInput) =>
|
||||
createBrain(brain, axiosInstance),
|
||||
deleteBrain: async (id: string) => deleteBrain(id, axiosInstance),
|
||||
|
Loading…
Reference in New Issue
Block a user