import React, { useState, useEffect } from "react"; import { Card, Title, Text, Tab, TabList, TabGroup, TabPanel, TabPanels, Grid, Badge, Button as TremorButton, TextInput, } from "@tremor/react"; import NumericalInput from "./shared/numerical_input"; import { ArrowLeftIcon, TrashIcon, KeyIcon } from "@heroicons/react/outline"; import { modelDeleteCall, modelUpdateCall, CredentialItem, credentialGetCall, credentialCreateCall, modelInfoCall, modelInfoV1Call } from "./networking"; import { Button, Form, Input, InputNumber, message, Select, Modal } from "antd"; import EditModelModal from "./edit_model/edit_model_modal"; import { handleEditModelSubmit } from "./edit_model/edit_model_modal"; import { getProviderLogoAndName } from "./provider_info_helpers"; import { getDisplayModelName } from "./view_model/model_name_display"; import AddCredentialsModal from "./model_add/add_credentials_tab"; import ReuseCredentialsModal from "./model_add/reuse_credentials"; interface ModelInfoViewProps { modelId: string; onClose: () => void; modelData: any; accessToken: string | null; userID: string | null; userRole: string | null; editModel: boolean; setEditModalVisible: (visible: boolean) => void; setSelectedModel: (model: any) => void; onModelUpdate?: (updatedModel: any) => void; } export default function ModelInfoView({ modelId, onClose, modelData, accessToken, userID, userRole, editModel, setEditModalVisible, setSelectedModel, onModelUpdate }: ModelInfoViewProps) { const [form] = Form.useForm(); const [localModelData, setLocalModelData] = useState(null); const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const [isCredentialModalOpen, setIsCredentialModalOpen] = useState(false); const [isDirty, setIsDirty] = useState(false); const [isSaving, setIsSaving] = useState(false); const [isEditing, setIsEditing] = useState(false); const [existingCredential, setExistingCredential] = useState(null); const canEditModel = userRole === "Admin" || modelData.model_info.created_by === userID; const isAdmin = userRole === "Admin"; const usingExistingCredential = modelData.litellm_params?.litellm_credential_name != null && modelData.litellm_params?.litellm_credential_name != undefined; console.log("usingExistingCredential, ", usingExistingCredential); console.log("modelData.litellm_params.litellm_credential_name, ", modelData.litellm_params.litellm_credential_name); useEffect(() => { const getExistingCredential = async () => { console.log("accessToken, ", accessToken); if (!accessToken) return; if (usingExistingCredential) return; let existingCredentialResponse = await credentialGetCall(accessToken, null, modelId); console.log("existingCredentialResponse, ", existingCredentialResponse); setExistingCredential({ credential_name: existingCredentialResponse["credential_name"], credential_values: existingCredentialResponse["credential_values"], credential_info: existingCredentialResponse["credential_info"] }); } const getModelInfo = async () => { if (!accessToken) return; let modelInfoResponse = await modelInfoV1Call(accessToken, modelId); console.log("modelInfoResponse, ", modelInfoResponse); let specificModelData = modelInfoResponse.data[0]; setLocalModelData(specificModelData); } getExistingCredential(); getModelInfo(); }, [accessToken, modelId]); const handleReuseCredential = async (values: any) => { console.log("values, ", values); if (!accessToken) return; let credentialItem = { credential_name: values.credential_name, model_id: modelId, credential_info: { "custom_llm_provider": localModelData.litellm_params?.custom_llm_provider, } } message.info("Storing credential.."); let credentialResponse = await credentialCreateCall(accessToken, credentialItem); console.log("credentialResponse, ", credentialResponse); message.success("Credential stored successfully"); } const handleModelUpdate = async (values: any) => { try { if (!accessToken) return; setIsSaving(true); const updateData = { model_name: values.model_name, litellm_params: { ...localModelData.litellm_params, model: values.litellm_model_name, api_base: values.api_base, custom_llm_provider: values.custom_llm_provider, organization: values.organization, tpm: values.tpm, rpm: values.rpm, max_retries: values.max_retries, timeout: values.timeout, stream_timeout: values.stream_timeout, input_cost_per_token: values.input_cost / 1_000_000, output_cost_per_token: values.output_cost / 1_000_000, }, model_info: { id: modelId, } }; await modelUpdateCall(accessToken, updateData); const updatedModelData = { ...localModelData, model_name: values.model_name, litellm_model_name: values.litellm_model_name, litellm_params: updateData.litellm_params }; setLocalModelData(updatedModelData); if (onModelUpdate) { onModelUpdate(updatedModelData); } message.success("Model settings updated successfully"); setIsDirty(false); setIsEditing(false); } catch (error) { console.error("Error updating model:", error); message.error("Failed to update model settings"); } finally { setIsSaving(false); } }; if (!modelData) { return (
Model not found
); } const handleDelete = async () => { try { if (!accessToken) return; await modelDeleteCall(accessToken, modelId); message.success("Model deleted successfully"); if (onModelUpdate) { onModelUpdate({ deleted: true, model_info: { id: modelId } }); } onClose(); } catch (error) { console.error("Error deleting the model:", error); message.error("Failed to delete model"); } }; return (
Public Model Name: {getDisplayModelName(modelData)} {modelData.model_info.id}
{isAdmin && ( setIsCredentialModalOpen(true)} className="flex items-center" > Re-use Credentials )} {canEditModel && ( setIsDeleteModalOpen(true)} className="flex items-center" > Delete Model )}
Overview Raw JSON {/* Overview Grid */} Provider
{modelData.provider && ( {`${modelData.provider} { // Create a div with provider initial as fallback 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 = modelData.provider?.charAt(0) || '-'; parent.replaceChild(fallbackDiv, target); } }} /> )} {modelData.provider || "Not Set"}
LiteLLM Model
                  {modelData.litellm_model_name || "Not Set"}
                
Pricing
Input: ${modelData.input_cost}/1M tokens Output: ${modelData.output_cost}/1M tokens
{/* Audit info shown as a subtle banner below the overview */}
Created At {modelData.model_info.created_at ? new Date(modelData.model_info.created_at).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }) : "Not Set"}
Created By {modelData.model_info.created_by || "Not Set"}
{/* Settings Card */}
Model Settings {canEditModel && !isEditing && ( setIsEditing(true)} className="flex items-center" > Edit Model )}
{localModelData ? (
setIsDirty(true)} >
Model Name {isEditing ? ( ) : (
{localModelData.model_name}
)}
LiteLLM Model Name {isEditing ? ( ) : (
{localModelData.litellm_model_name}
)}
Input Cost (per 1M tokens) {isEditing ? ( ) : (
{localModelData?.litellm_params?.input_cost_per_token ? (localModelData.litellm_params?.input_cost_per_token * 1_000_000).toFixed(4) : localModelData?.model_info?.input_cost_per_token ? (localModelData.model_info.input_cost_per_token * 1_000_000).toFixed(4) : null}
)}
Output Cost (per 1M tokens) {isEditing ? ( ) : (
{localModelData?.litellm_params?.output_cost_per_token ? (localModelData.litellm_params.output_cost_per_token * 1_000_000).toFixed(4) : localModelData?.model_info?.output_cost_per_token ? (localModelData.model_info.output_cost_per_token * 1_000_000).toFixed(4) : null}
)}
API Base {isEditing ? ( ) : (
{localModelData.litellm_params?.api_base || "Not Set"}
)}
Custom LLM Provider {isEditing ? ( ) : (
{localModelData.litellm_params?.custom_llm_provider || "Not Set"}
)}
Organization {isEditing ? ( ) : (
{localModelData.litellm_params?.organization || "Not Set"}
)}
TPM (Tokens per Minute) {isEditing ? ( ) : (
{localModelData.litellm_params?.tpm || "Not Set"}
)}
RPM (Requests per Minute) {isEditing ? ( ) : (
{localModelData.litellm_params?.rpm || "Not Set"}
)}
Max Retries {isEditing ? ( ) : (
{localModelData.litellm_params?.max_retries || "Not Set"}
)}
Timeout (seconds) {isEditing ? ( ) : (
{localModelData.litellm_params?.timeout || "Not Set"}
)}
Stream Timeout (seconds) {isEditing ? ( ) : (
{localModelData.litellm_params?.stream_timeout || "Not Set"}
)}
Team ID
{modelData.model_info.team_id || "Not Set"}
{isEditing && (
{ form.resetFields(); setIsDirty(false); setIsEditing(false); }} > Cancel form.submit()} loading={isSaving} > Save Changes
)}
) : ( Loading... )}
                {JSON.stringify(modelData, null, 2)}
              
{/* Delete Confirmation Modal */} {isDeleteModalOpen && (

Delete Model

Are you sure you want to delete this model?

)} {isCredentialModalOpen && !usingExistingCredential ? ( setIsCredentialModalOpen(false)} onAddCredential={handleReuseCredential} existingCredential={existingCredential} setIsCredentialModalOpen={setIsCredentialModalOpen} /> ): ( setIsCredentialModalOpen(false)} title="Using Existing Credential" > {modelData.litellm_params.litellm_credential_name} )}
); }