add suggestPolicyTemplates networking function

This commit is contained in:
Ishaan Jaffer 2026-02-19 10:59:44 -08:00
parent 3ad577e7f8
commit daf6dec155

View file

@ -5585,6 +5585,41 @@ export const enrichPolicyTemplate = async (
}
};
export const suggestPolicyTemplates = async (
accessToken: string,
attackExamples: string[],
description: string
) => {
try {
const url = proxyBaseUrl
? `${proxyBaseUrl}/policy/templates/suggest`
: `/policy/templates/suggest`;
const response = await fetch(url, {
method: "POST",
headers: {
[globalLitellmHeaderName]: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
attack_examples: attackExamples.filter((e) => e.trim()),
description,
}),
});
if (!response.ok) {
const errorData = await response.json();
const errorMessage = deriveErrorMessage(errorData);
handleError(errorMessage);
throw new Error(errorMessage);
}
return response.json();
} catch (error) {
console.error("Failed to suggest policy templates:", error);
throw error;
}
};
export const createPolicyCall = async (accessToken: string, policyData: any) => {
try {
const url = proxyBaseUrl ? `${proxyBaseUrl}/policies` : `/policies`;