Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Disconnecting a Vector Database Provider #957

Merged
merged 2 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions libs/superagent/app/api/vector_dbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,14 @@ async def update(
return {"success": True, "data": data}
except Exception as e:
handle_exception(e)


@router.delete(
"/vector-dbs/{vector_db_id}",
name="delete",
description="Delete a Vector Database",
)
async def delete(vector_db_id: str, api_user=Depends(get_current_api_user)):
"""Endpoint for deleting a Vector Database"""
await prisma.vectordb.delete(where={"id": vector_db_id, "apiUserId": api_user.id})
return {"success": True}
65 changes: 48 additions & 17 deletions libs/ui/app/integrations/storage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import * as React from "react"
import Image from "next/image"
import { useRouter } from "next/navigation"
import { VectorDb } from "@/models/models"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import * as z from "zod"

import { siteConfig } from "@/config/site"
import { Api } from "@/lib/api"
import { cn } from "@/lib/utils"
import { Button } from "@/components/ui/button"
import {
Dialog,
Expand All @@ -29,8 +31,9 @@ import {
FormMessage,
} from "@/components/ui/form"
import { Input } from "@/components/ui/input"
import { Skeleton } from "@/components/ui/skeleton"
import { Spinner } from "@/components/ui/spinner"
import { Toaster } from "@/components/ui/toaster"
import { useToast } from "@/components/ui/use-toast"

const pineconeSchema = z.object({
PINECONE_API_KEY: z.string(),
Expand Down Expand Up @@ -83,6 +86,7 @@ export default function Storage({
const [open, setOpen] = React.useState<boolean>()
const [selectedDB, setSelectedDB] = React.useState<any>()
const router = useRouter()
const { toast } = useToast()
const api = new Api(profile.api_key)
const { ...form } = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
Expand Down Expand Up @@ -116,6 +120,20 @@ export default function Storage({
setOpen(false)
}

const onDelete = async (vectorDb: VectorDb) => {
await api.deleteVectorDb(vectorDb.id)
router.refresh()

let providerName = vectorDb.provider.toLowerCase()

providerName = providerName.charAt(0).toUpperCase() + providerName.slice(1)

toast({
title: "Success",
description: `Successfully disconnected: ${providerName}`,
})
}

return (
<div className="container flex max-w-4xl flex-col space-y-10 pt-10">
<div className="flex flex-col">
Expand All @@ -127,7 +145,7 @@ export default function Storage({
</div>
<div className="flex-col border-b">
{siteConfig.vectorDbs.map((vectorDb) => {
const isConfigured = configuredDBs.find(
const currentDB = configuredDBs.find(
(db: any) => db.provider === vectorDb.provider
)

Expand All @@ -137,11 +155,12 @@ export default function Storage({
key={vectorDb.provider}
>
<div className="flex items-center space-x-4">
{isConfigured ? (
<div className="h-2 w-2 rounded-full bg-green-400" />
) : (
<div className="h-2 w-2 rounded-full bg-muted" />
)}
<div
className={cn(
"h-2 w-2 rounded-full",
currentDB ? "bg-green-400" : "bg-muted"
)}
/>
<div className="flex items-center space-x-3">
<Image
src={vectorDb.logo}
Expand All @@ -152,16 +171,27 @@ export default function Storage({
<p className="font-medium">{vectorDb.name}</p>
</div>
</div>
<Button
variant="outline"
size="sm"
onClick={() => {
setSelectedDB(vectorDb)
setOpen(true)
}}
>
Settings
</Button>
{currentDB ? (
<Button
variant="outline"
className="border-destructive text-destructive hover:bg-destructive"
size="sm"
onClick={() => onDelete(new VectorDb(currentDB))}
>
Disconnect
</Button>
) : (
<Button
variant="outline"
size="sm"
onClick={() => {
setSelectedDB(vectorDb)
setOpen(true)
}}
>
Connect
</Button>
)}
</div>
)
})}
Expand Down Expand Up @@ -241,6 +271,7 @@ export default function Storage({
</div>
</DialogContent>
</Dialog>
<Toaster />
</div>
)
}
6 changes: 6 additions & 0 deletions libs/ui/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,10 @@ export class Api {
body: JSON.stringify(payload),
})
}

async deleteVectorDb(id: string) {
return this.fetchFromApi(`/vector-dbs/${id}`, {
method: "DELETE",
})
}
}