mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 11:14:04 +00:00
Merge pull request #9272 from BerriAI/litellm_add_test_connection_button
[Feat] UI - Add Test Connection
This commit is contained in:
commit
0d8a2c0bae
10 changed files with 730 additions and 184 deletions
|
@ -2313,6 +2313,63 @@ export const keyInfoCall = async (accessToken: String, keys: String[]) => {
|
|||
};
|
||||
|
||||
|
||||
export const testConnectionRequest = async (
|
||||
accessToken: string,
|
||||
litellm_params: Record<string, any>,
|
||||
mode: string,
|
||||
) => {
|
||||
try {
|
||||
console.log("Sending model connection test request:", JSON.stringify(litellm_params));
|
||||
|
||||
// Construct the URL based on environment
|
||||
const url = proxyBaseUrl ? `${proxyBaseUrl}/health/test_connection` : `/health/test_connection`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
[globalLitellmHeaderName]: `Bearer ${accessToken}`
|
||||
},
|
||||
body: JSON.stringify(
|
||||
{
|
||||
litellm_params: litellm_params,
|
||||
mode: mode,
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
// Check for non-JSON responses first
|
||||
const contentType = response.headers.get('content-type');
|
||||
if (!contentType || !contentType.includes('application/json')) {
|
||||
const text = await response.text();
|
||||
console.error("Received non-JSON response:", text);
|
||||
throw new Error(`Received non-JSON response (${response.status}: ${response.statusText}). Check network tab for details.`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok || data.status === "error") {
|
||||
// Return the error response instead of throwing an error
|
||||
// This allows the caller to handle the error format properly
|
||||
if (data.status === "error") {
|
||||
return data; // Return the full error response
|
||||
} else {
|
||||
return {
|
||||
status: "error",
|
||||
message: data.error?.message || `Connection test failed: ${response.status} ${response.statusText}`
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Model connection test error:", error);
|
||||
// For network errors or other exceptions, still throw
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// ... existing code ...
|
||||
export const keyInfoV1Call = async (accessToken: string, key: string) => {
|
||||
try {
|
||||
let url = proxyBaseUrl ? `${proxyBaseUrl}/key/info` : `/key/info`;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue