人群攻击 AIDR 类型脚本 SDK
用于CrowdStrike AIDR的TypeScript SDK.
安装
npm install @crowdstrike/aidr
pnpm add @crowdstrike/aidr
yarn add @crowdstrike/aidr
使用量
import { AIGuard } from "@crowdstrike/aidr";
const client = new AIGuard({
token: "your-api-token",
baseURLTemplate: "https://api.crowdstrike.com/aidr/{SERVICE_NAME}",
});
const response = await client.guardChatCompletions({
guard_input: {
messages: [
{
role: "user",
content: "Hello, how can I help you?",
},
],
},
});
console.log(response);
检索
SDK 支持针对临时故障的自动重试(网络出错或 HTTP/5XX 服务器错误. 它支持在客户端层面配置再试或 按要求计算.
// Set the default number of retries when creating the client.
const client = new AIGuard({
token: "your-api-token",
baseURLTemplate: "https://api.crowdstrike.com/aidr/{SERVICE_NAME}",
maxRetries: 3, // Default is 2.
});
const response = await client.guardChatCompletions(
{
guard_input: {
messages: [{ role: "user", content: "Hello" }],
},
},
{
// Override the default retry count for this specific request.
maxRetries: 5,
}
);
超时
配置请求超时以控制客户端等待响应的时间 时间不早了.
// Set the default timeout (in milliseconds) when creating the client.
const client = new AIGuard({
token: "your-api-token",
baseURLTemplate: "https://api.crowdstrike.com/{SERVICE_NAME}",
timeout: 30000, // 30 seconds (default is 60 seconds).
});
const response = await client.guardChatCompletions(
{
guard_input: {
messages: [{ role: "user", content: "Hello" }],
},
},
{
// Override the default timeout for a specific request.
timeout: 10000, // 10 seconds.
}
);
获取选项
如果你想设置自定义 fetch 选项,而不压倒 fetch
函数,您可以提供 fetchOptions 客户端瞬时对象
或提出要求。 请求特定选项覆盖客户端选项 .
const client = new AIGuard({
fetchOptions: {
// `RequestInit` options.
},
});
配置代理人
要修改代理行为, 您可以提供自定义 fetchOptions 添加
请求的运行时间特定代理选项 :
节点.js
import * as undici from 'undici';
const proxyAgent = new undici.ProxyAgent('http://localhost:8888');
const client = new AIGuard({
fetchOptions: {
dispatcher: proxyAgent,
},
});
阿宝
const client = new AIGuard({
fetchOptions: {
proxy: 'http://localhost:8888',
},
});
德诺
const httpClient = Deno.createHttpClient({ proxy: { url: 'http://localhost:8888' } });
const client = new AIGuard({
fetchOptions: {
client: httpClient,
},
});