import { ColumnDef } from "@tanstack/react-table"; import { Button, Badge, Icon } from "@tremor/react"; import { Tooltip } from "antd"; import { getProviderLogoAndName } from "../provider_info_helpers"; import { ModelData } from "./types"; import { TrashIcon, PencilIcon, PencilAltIcon } from "@heroicons/react/outline"; import DeleteModelButton from "../delete_model_button"; export const columns = ( userRole: string, userID: string, premiumUser: boolean, setSelectedModelId: (id: string) => void, setSelectedTeamId: (id: string) => void, getDisplayModelName: (model: any) => string, handleEditClick: (model: any) => void, handleRefreshClick: () => void, setEditModel: (edit: boolean) => void, ): ColumnDef[] => [ { header: "Model ID", accessorKey: "model_info.id", cell: ({ row }) => { const model = row.original; return (
setSelectedModelId(model.model_info.id)} > {model.model_info.id}
); }, }, { header: "Public Model Name", accessorKey: "model_name", cell: ({ row }) => { const displayName = getDisplayModelName(row.original) || "-"; return (
{displayName}
); }, }, { header: "Provider", accessorKey: "provider", cell: ({ row }) => { const model = row.original; return (
{model.provider && ( {`${model.provider} { const target = e.target as HTMLImageElement; const parent = target.parentElement; if (parent) { const fallbackDiv = document.createElement('div'); fallbackDiv.className = 'w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs'; fallbackDiv.textContent = model.provider?.charAt(0) || '-'; parent.replaceChild(fallbackDiv, target); } }} /> )}

{model.provider || "-"}

); }, }, { header: "LiteLLM Model Name", accessorKey: "litellm_model_name", cell: ({ row }) => { const model = row.original; return (
{model.litellm_model_name || "-"}
); }, }, { header: "Created At", accessorKey: "model_info.created_at", sortingFn: "datetime", cell: ({ row }) => { const model = row.original; return ( {model.model_info.created_at ? new Date(model.model_info.created_at).toLocaleDateString() : "-"} ); }, }, { header: "Updated At", accessorKey: "model_info.updated_at", sortingFn: "datetime", cell: ({ row }) => { const model = row.original; return ( {model.model_info.updated_at ? new Date(model.model_info.updated_at).toLocaleDateString() : "-"} ); }, }, { header: "Created By", accessorKey: "model_info.created_by", cell: ({ row }) => { const model = row.original; return ( {model.model_info.created_by || "-"} ); }, }, { header: () => ( Input Cost ), accessorKey: "input_cost", cell: ({ row }) => { const model = row.original; return (
          {model.input_cost || "-"}
        
); }, }, { header: () => ( Output Cost ), accessorKey: "output_cost", cell: ({ row }) => { const model = row.original; return (
          {model.output_cost || "-"}
        
); }, }, { header: "Team ID", accessorKey: "model_info.team_id", cell: ({ row }) => { const model = row.original; return model.model_info.team_id ? (
) : ( "-" ); }, }, { header: "Credentials", accessorKey: "litellm_credential_name", cell: ({ row }) => { const model = row.original; return model.litellm_params && model.litellm_params.litellm_credential_name ? (
{model.litellm_params.litellm_credential_name.slice(0, 7)}...
) : ( - ); }, }, { header: "Status", accessorKey: "model_info.db_model", cell: ({ row }) => { const model = row.original; return (
{model.model_info.db_model ? "DB Model" : "Config Model"}
); }, }, { id: "actions", header: "", cell: ({ row }) => { const model = row.original; const canEditModel = userRole === "Admin" || model.model_info?.created_by === userID; return (
{ if (canEditModel) { setSelectedModelId(model.model_info.id); setEditModel(true); } }} className={!canEditModel ? "opacity-50 cursor-not-allowed" : "cursor-pointer"} /> { if (canEditModel) { setSelectedModelId(model.model_info.id); setEditModel(false); } }} className={!canEditModel ? "opacity-50 cursor-not-allowed" : "cursor-pointer"} />
); }, }, ];