fix endpoint

This commit is contained in:
Ishaan Jaff 2025-03-14 12:26:17 -07:00
parent 33c85825de
commit d67fc03e20
2 changed files with 60 additions and 4 deletions

View file

@ -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(

View file

@ -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<string, any>,
@ -175,4 +176,60 @@ export const handleAddModelSubmit = async (
}
};
export const testModelConnection = async (
formValues: Record<string, any>,
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;
}
};