forked from microsoft/MinecraftCodex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContentFilter.ts
More file actions
28 lines (22 loc) · 896 Bytes
/
Copy pathContentFilter.ts
File metadata and controls
28 lines (22 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { http, HttpRequest, HttpRequestMethod, HttpHeader } from "@minecraft/server-net";
import { OPENAI_API_KEY } from "./vars.js";
export async function detectSensitiveContent(content: string): Promise<number> {
const req = new HttpRequest("https://api.openai.com/v1/engines/content-filter-alpha/completions");
req.headers = [
new HttpHeader("Content-Type", "application/json"),
new HttpHeader("Accept", "application/json"),
new HttpHeader("Authorization", `Bearer ${OPENAI_API_KEY}`),
];
req.method = HttpRequestMethod.POST;
req.body = JSON.stringify({
prompt: `<|endoftext|>[${content}]\n--\nLabel:`,
temperature: 0,
max_tokens: 1,
top_p: 0,
logprobs: 10,
});
const response = await http.request(req);
const resp = JSON.parse(response.body);
const filterFlag = (resp as any).choices[0].text as string;
return parseInt(filterFlag);
}