mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
add suggestPolicyTemplates networking function
This commit is contained in:
parent
3ad577e7f8
commit
daf6dec155
1 changed files with 35 additions and 0 deletions
|
|
@ -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`;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue