import React from "react"; import { Form, Switch, Select, Input, Typography } from "antd"; import { PlusOutlined, MinusCircleOutlined } from '@ant-design/icons'; import NumericalInput from "../shared/numerical_input"; const { Text } = Typography; interface CacheControlInjectionPoint { location: "message"; role?: "user" | "system" | "assistant"; index?: number; } interface CacheControlSettingsProps { form: any; // Form instance from parent showCacheControl: boolean; onCacheControlChange: (checked: boolean) => void; } const CacheControlSettings: React.FC = ({ form, showCacheControl, onCacheControlChange, }) => { const updateCacheControlPoints = (injectionPoints: CacheControlInjectionPoint[]) => { const currentParams = form.getFieldValue('litellm_extra_params'); try { let paramsObj = currentParams ? JSON.parse(currentParams) : {}; if (injectionPoints.length > 0) { paramsObj.cache_control_injection_points = injectionPoints; } else { delete paramsObj.cache_control_injection_points; } if (Object.keys(paramsObj).length > 0) { form.setFieldValue('litellm_extra_params', JSON.stringify(paramsObj, null, 2)); } else { form.setFieldValue('litellm_extra_params', ''); } } catch (error) { console.error('Error updating cache control points:', error); } }; return ( <> {showCacheControl && (
Providers like Anthropic, Bedrock API require users to specify where to inject cache control checkpoints, litellm can automatically add them for you as a cost saving feature. {(fields, { add, remove }) => ( <> {fields.map((field, index) => (
{ const values = form.getFieldValue('cache_control_points'); updateCacheControlPoints(values); }} /> { const values = form.getFieldValue('cache_control_points'); updateCacheControlPoints(values); }} /> {fields.length > 1 && ( { remove(field.name); setTimeout(() => { const values = form.getFieldValue('cache_control_points'); updateCacheControlPoints(values); }, 0); }} /> )}
))} )}
)} ); }; export default CacheControlSettings;