mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
workign ui
This commit is contained in:
parent
595b7b42da
commit
fc6c1f0de6
3 changed files with 89 additions and 2 deletions
|
|
@ -9546,3 +9546,33 @@ export const checkGdprCompliance = async (
|
|||
}
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const provisionPartnerGuardrailCall = async (
|
||||
accessToken: string,
|
||||
data: {
|
||||
guardrail_name: string;
|
||||
provider: string;
|
||||
credential_name: string;
|
||||
provision_config: Record<string, any>;
|
||||
aws_region_name?: string;
|
||||
mode?: string;
|
||||
default_on?: boolean;
|
||||
}
|
||||
) => {
|
||||
const url = proxyBaseUrl
|
||||
? `${proxyBaseUrl}/guardrails/provision_partner`
|
||||
: `/guardrails/provision_partner`;
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
[globalLitellmHeaderName]: `Bearer ${accessToken}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
throw new Error(deriveErrorMessage(errorData));
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -26,7 +26,9 @@ import {
|
|||
createPolicyAttachmentCall,
|
||||
createGuardrailCall,
|
||||
enrichPolicyTemplate,
|
||||
provisionPartnerGuardrailCall,
|
||||
} from "../networking";
|
||||
import { PartnerGuardrailSelection } from "./guardrail_selection_modal";
|
||||
import {
|
||||
Policy,
|
||||
PolicyAttachment,
|
||||
|
|
@ -281,7 +283,10 @@ const PoliciesPanel: React.FC<PoliciesPanelProps> = ({
|
|||
setPendingTemplate(null);
|
||||
};
|
||||
|
||||
const handleGuardrailSelectionConfirm = async (selectedGuardrailDefinitions: any[]) => {
|
||||
const handleGuardrailSelectionConfirm = async (
|
||||
selectedGuardrailDefinitions: any[],
|
||||
partnerGuardrails?: PartnerGuardrailSelection[]
|
||||
) => {
|
||||
if (!accessToken || !selectedTemplate) return;
|
||||
|
||||
setIsCreatingGuardrails(true);
|
||||
|
|
@ -293,7 +298,7 @@ const PoliciesPanel: React.FC<PoliciesPanelProps> = ({
|
|||
// Create selected guardrails
|
||||
for (const guardrailDef of selectedGuardrailDefinitions) {
|
||||
const guardrailName = guardrailDef.guardrail_name;
|
||||
|
||||
|
||||
try {
|
||||
await createGuardrailCall(accessToken, guardrailDef);
|
||||
createdGuardrails.push(guardrailName);
|
||||
|
|
@ -304,6 +309,28 @@ const PoliciesPanel: React.FC<PoliciesPanelProps> = ({
|
|||
}
|
||||
}
|
||||
|
||||
// Provision partner guardrails
|
||||
if (partnerGuardrails && partnerGuardrails.length > 0) {
|
||||
for (const pg of partnerGuardrails) {
|
||||
const partnerName = `${selectedTemplate.id}-${pg.provider}`;
|
||||
try {
|
||||
await provisionPartnerGuardrailCall(accessToken, {
|
||||
guardrail_name: partnerName,
|
||||
provider: pg.provider,
|
||||
credential_name: pg.credential_name,
|
||||
provision_config: pg.provision_config,
|
||||
aws_region_name: pg.aws_region_name,
|
||||
mode: "pre_call",
|
||||
default_on: true,
|
||||
});
|
||||
createdGuardrails.push(`${partnerName} (partner)`);
|
||||
} catch (error) {
|
||||
console.error(`Failed to provision partner guardrail "${pg.provider}":`, error);
|
||||
failedGuardrails.push(`${partnerName} (partner)`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh guardrails list
|
||||
await fetchGuardrails();
|
||||
|
||||
|
|
@ -520,6 +547,7 @@ const PoliciesPanel: React.FC<PoliciesPanelProps> = ({
|
|||
onCancel={handleGuardrailSelectionCancel}
|
||||
isLoading={isCreatingGuardrails}
|
||||
progressInfo={templateQueueProgress}
|
||||
accessToken={accessToken || undefined}
|
||||
/>
|
||||
|
||||
<TemplateParameterModal
|
||||
|
|
|
|||
|
|
@ -9,6 +9,11 @@ import {
|
|||
} from "@heroicons/react/outline";
|
||||
import { getPolicyTemplates } from "../networking";
|
||||
|
||||
interface PartnerGuardrailInfo {
|
||||
provider: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
interface PolicyTemplateCardProps {
|
||||
title: string;
|
||||
description: string;
|
||||
|
|
@ -19,9 +24,14 @@ interface PolicyTemplateCardProps {
|
|||
tags: string[];
|
||||
inherits?: string;
|
||||
complexity: "Low" | "Medium" | "High";
|
||||
partnerGuardrails?: PartnerGuardrailInfo[];
|
||||
onUseTemplate: () => void;
|
||||
}
|
||||
|
||||
const partnerProviderLogoMap: Record<string, string> = {
|
||||
bedrock: "../ui/assets/logos/bedrock.svg",
|
||||
};
|
||||
|
||||
const PolicyTemplateCard: React.FC<PolicyTemplateCardProps> = ({
|
||||
title,
|
||||
description,
|
||||
|
|
@ -32,6 +42,7 @@ const PolicyTemplateCard: React.FC<PolicyTemplateCardProps> = ({
|
|||
tags,
|
||||
inherits,
|
||||
complexity,
|
||||
partnerGuardrails,
|
||||
onUseTemplate,
|
||||
}) => {
|
||||
const getComplexityStyle = () => {
|
||||
|
|
@ -86,6 +97,23 @@ const PolicyTemplateCard: React.FC<PolicyTemplateCardProps> = ({
|
|||
</div>
|
||||
)}
|
||||
|
||||
{partnerGuardrails && partnerGuardrails.length > 0 && (
|
||||
<div className="mb-4 flex items-center gap-2 px-2.5 py-1.5 rounded-md bg-orange-50 border border-orange-200">
|
||||
{partnerProviderLogoMap[partnerGuardrails[0].provider] && (
|
||||
<img
|
||||
src={partnerProviderLogoMap[partnerGuardrails[0].provider]}
|
||||
alt={partnerGuardrails[0].provider}
|
||||
style={{ height: "16px", width: "16px", objectFit: "contain" }}
|
||||
onError={(e) => { e.currentTarget.style.display = "none"; }}
|
||||
/>
|
||||
)}
|
||||
<span className="text-xs font-medium text-orange-800">
|
||||
Partner guardrail available
|
||||
</span>
|
||||
<span className="text-[10px] text-orange-500 ml-auto">Optional</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="mb-6">
|
||||
<span className="text-xs font-medium text-gray-500 uppercase tracking-wider block mb-2">
|
||||
Included Guardrails
|
||||
|
|
@ -290,6 +318,7 @@ const PolicyTemplates: React.FC<PolicyTemplatesProps> = ({ onUseTemplate, onOpen
|
|||
tags={template.tags || []}
|
||||
inherits={template.inherits}
|
||||
complexity={template.complexity}
|
||||
partnerGuardrails={template.partnerGuardrails}
|
||||
onUseTemplate={() => onUseTemplate(template)}
|
||||
/>
|
||||
))}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue