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

(ui) fix bug when editing keys - selecting models #2828

Merged
merged 1 commit into from
Apr 4, 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
2 changes: 1 addition & 1 deletion ui/litellm-dashboard/src/components/user_dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ const UserDashboard: React.FC<UserDashboardProps> = ({

<ViewKeyTable
userID={userID}
userRole={userRole}
accessToken={accessToken}
selectedTeam={selectedTeam ? selectedTeam : null}
data={keys}
userModels={userModels}
setData={setKeys}
/>
<CreateKey
Expand Down
39 changes: 30 additions & 9 deletions ui/litellm-dashboard/src/components/view_key_table.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";
import React, { useEffect, useState } from "react";
import { keyDeleteCall } from "./networking";
import { keyDeleteCall, modelAvailableCall } from "./networking";
import { InformationCircleIcon, StatusOnlineIcon, TrashIcon, PencilAltIcon } from "@heroicons/react/outline";
import { keySpendLogsCall, PredictedSpendLogsCall, keyUpdateCall } from "./networking";
import {
Expand Down Expand Up @@ -47,9 +47,9 @@ interface EditKeyModalProps {
// Define the props type
interface ViewKeyTableProps {
userID: string;
userRole: string | null;
accessToken: string;
selectedTeam: any | null;
userModels: string[];
data: any[] | null;
setData: React.Dispatch<React.SetStateAction<any[] | null>>;
}
Expand All @@ -73,9 +73,9 @@ interface ItemData {

const ViewKeyTable: React.FC<ViewKeyTableProps> = ({
userID,
userRole,
accessToken,
selectedTeam,
userModels,
data,
setData,
}) => {
Expand All @@ -91,18 +91,39 @@ const ViewKeyTable: React.FC<ViewKeyTableProps> = ({

const [editModalVisible, setEditModalVisible] = useState(false);
const [selectedToken, setSelectedToken] = useState<ItemData | null>(null);
const [userModels, setUserModels] = useState([]);

useEffect(() => {
const fetchUserModels = async () => {
try {
if (userID === null) {
return;
}

if (accessToken !== null && userRole !== null) {
const model_available = await modelAvailableCall(accessToken, userID, userRole);
let available_model_names = model_available["data"].map(
(element: { id: string }) => element.id
);
console.log("available_model_names:", available_model_names);
setUserModels(available_model_names);
}
} catch (error) {
console.error("Error fetching user models:", error);
}
};

fetchUserModels();
}, [accessToken, userID, userRole]);

const EditKeyModal: React.FC<EditKeyModalProps> = ({ visible, onCancel, token, onSubmit }) => {
const [form] = Form.useForm();

// check token.models length == 0
if (token.models.length == 0 && selectedTeam) {
token.models = selectedTeam.models;

}
console.log("in edit key modal:", token);
console.log("in edit key modal, team:", selectedTeam);




const handleOk = () => {
form
.validateFields()
Expand Down
Loading