dev: allow extensions to audit prompts

This commit is contained in:
KernelDeimos 2024-11-24 16:28:24 -05:00
parent df42d433c9
commit ef7047ede4
2 changed files with 28 additions and 2 deletions

View File

@ -83,8 +83,19 @@ class AIChatService extends BaseService {
},
async complete (parameters) {
const client_driver_call = Context.get('client_driver_call');
const { test_mode } = client_driver_call;
let { intended_service } = client_driver_call;
let { test_mode, intended_service } = client_driver_call;
this.log.noticeme('AIChatService.complete', { intended_service, parameters, test_mode });
const svc_event = this.services.get('event');
const event = {
allow: true,
intended_service,
parameters
};
await svc_event.emit('ai.prompt.validate', event);
if ( ! event.allow ) {
test_mode = true;
}
if ( test_mode ) {
intended_service = 'fake-chat';

View File

@ -30,6 +30,21 @@ class OpenAICompletionService extends BaseService {
];
},
async complete ({ messages, test_mode, stream, model }) {
// for now this code (also in AIChatService.js) needs to be
// duplicated because this hasn't been moved to be under
// the centralised controller yet
const svc_event = this.services.get('event');
const event = {
allow: true,
intended_service: 'openai',
parameters: { messages }
};
await svc_event.emit('ai.prompt.validate', event);
if ( ! event.allow ) {
test_mode = true;
}
if ( test_mode ) {
const { LoremIpsum } = require('lorem-ipsum');
const li = new LoremIpsum({