fix: transform_request.tsx

don't hardcode to localhost
This commit is contained in:
Krrish Dholakia 2025-04-09 16:35:07 -07:00
parent 86bfb8cd66
commit a1433da4a7
3 changed files with 199 additions and 15 deletions

View file

@ -1074,6 +1074,38 @@ export const organizationDeleteCall = async (
}
};
export const transformRequestCall = async (accessToken: String, request: object) => {
/**
* Transform request
*/
try {
let url = proxyBaseUrl ? `${proxyBaseUrl}/utils/transform_request` : `/utils/transform_request`;
const response = await fetch(url, {
method: "POST",
headers: {
[globalLitellmHeaderName]: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify(request),
});
if (!response.ok) {
const errorData = await response.text();
handleError(errorData);
throw new Error("Network response was not ok");
}
const data = await response.json();
return data;
} catch (error) {
console.error("Failed to create key:", error);
throw error;
}
}
export const userDailyActivityCall = async (accessToken: String, startTime: Date, endTime: Date, page: number = 1) => {
/**

View file

@ -2,7 +2,7 @@ import React, { useState } from 'react';
import { Button, Select, Tabs, message } from 'antd';
import { CopyOutlined } from '@ant-design/icons';
import { Title } from '@tremor/react';
import { transformRequestCall } from './networking';
interface TransformRequestPanelProps {
accessToken: string | null;
}
@ -79,22 +79,13 @@ ${formattedBody}
};
// Make the API call using fetch
const response = await fetch('http://0.0.0.0:4000/utils/transform_request', {
method: 'POST',
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
if (!response.ok) {
throw new Error(`HTTP error ${response.status}`);
if (!accessToken) {
message.error('No access token found');
setIsLoading(false);
return;
}
// Parse the response as JSON
const data = await response.json();
console.log("API response:", data);
const data = await transformRequestCall(accessToken, payload);
// Check if the response has the expected fields
if (data.raw_request_api_base && data.raw_request_body) {