diff --git a/litellm/proxy/health_endpoints/_health_endpoints.py b/litellm/proxy/health_endpoints/_health_endpoints.py index 3383fa753bb..c9b954280d8 100644 --- a/litellm/proxy/health_endpoints/_health_endpoints.py +++ b/litellm/proxy/health_endpoints/_health_endpoints.py @@ -613,7 +613,6 @@ async def health_liveliness_options(): ) async def test_model_connection( request: Request, - model: str = fastapi.Body(..., description="The model to test connection with"), mode: Optional[ Literal[ "chat", @@ -657,7 +656,7 @@ async def test_model_connection( """ try: # Create basic params for the model - model_params = {"model": model} + model_params = await request.json() # Run the health check with timeout result = await run_with_timeout( diff --git a/ui/litellm-dashboard/src/components/add_model/handle_add_model_submit.tsx b/ui/litellm-dashboard/src/components/add_model/handle_add_model_submit.tsx index 4a19653a6ab..e9ea366e87e 100644 --- a/ui/litellm-dashboard/src/components/add_model/handle_add_model_submit.tsx +++ b/ui/litellm-dashboard/src/components/add_model/handle_add_model_submit.tsx @@ -1,7 +1,8 @@ import { message } from "antd"; import { provider_map, Providers } from "../provider_info_helpers"; -import { modelCreateCall, Model } from "../networking"; - +import { modelCreateCall, Model, testConnectionRequest } from "../networking"; +import React, { useState } from 'react'; +import ConnectionErrorDisplay from './ConnectionErrorDisplay'; export const prepareModelAddRequest = async ( formValues: Record, @@ -175,4 +176,60 @@ export const handleAddModelSubmit = async ( } }; +export const testModelConnection = async ( + formValues: Record, + accessToken: string, + testMode: string, + setConnectionError?: (error: Error | string | null) => void +) => { + try { + // Prepare the model data using the existing function + const result = await prepareModelAddRequest(formValues, accessToken, null); + + if (!result) { + throw new Error("Failed to prepare model data"); + } + + const { litellmParamsObj, modelInfoObj } = result; + + // Create the request body for the test connection + const requestBody = { + ...litellmParamsObj, // Unfurl the parameters directly + mode: testMode + }; + + // Call the test connection endpoint + const response = await testConnectionRequest(accessToken, requestBody); + + if (response.status === "success") { + message.success("Connection test successful!"); + // Clear any previous error when successful + if (setConnectionError) { + setConnectionError(null); + } + } else { + // Set the error for ConnectionErrorDisplay instead of showing a message + const errorMessage = response.message || "Unknown error"; + if (setConnectionError) { + setConnectionError(errorMessage); + } else { + message.error("Connection test failed: " + errorMessage); + } + } + + return response; + } catch (error) { + console.error("Test connection error:", error); + + // Set the error for ConnectionErrorDisplay + if (setConnectionError) { + setConnectionError(error); + } else { + message.error("Test connection failed: " + error, 10); + } + + throw error; + } +}; +