Feat ChatGPT LLM Api [Console Log] [Text Moderation] [Azure]

[+] fix(openai.ts): fix parsing error in ChatGPTApi's message handler
[+] feat(openai.ts): add logging for flagged categories in text moderation
This commit is contained in:
H0llyW00dzZ 2023-11-19 19:49:52 +07:00
parent f2485931d9
commit fe0f078353
No known key found for this signature in database
GPG Key ID: 05C7FFFC0845C930

View File

@ -197,19 +197,21 @@ export class ChatGPTApi implements LLMApi {
} }
const text = msg.data; const text = msg.data;
try { try {
const json = JSON.parse(text) as { const json = JSON.parse(text);
choices: Array<{ const choices = json.choices as Array<{ delta: { content: string } }>;
delta: { const delta = choices[0]?.delta?.content;
content: string; const textmoderation = json?.prompt_filter_results;
};
}>;
};
const delta = json.choices[0]?.delta?.content;
if (delta) { if (delta) {
remainText += delta; remainText += delta;
} }
if (textmoderation && textmoderation.length > 0 && ServiceProvider.Azure) {
const contentFilterResults = textmoderation[0]?.content_filter_results;
console.log(`[${ServiceProvider.Azure}] [Text Moderation] flagged categories result:`, contentFilterResults);
}
} catch (e) { } catch (e) {
console.error("[Request] parse error", text); console.error("[Request] parse error", text, msg);
} }
}, },
onclose() { onclose() {