BREAKING CHANGE(platformservice): Remove deprecated AIBridge module and update email service to use the MTA connector; update dependency versions and adjust build scripts in package.json.
This commit is contained in:
@ -1,50 +0,0 @@
|
||||
import * as plugins from './aibridge.plugins.js';
|
||||
import * as paths from './aibridge.paths.js';
|
||||
import { AiBridgeDb } from './aibridge.classes.aibridgedb.js';
|
||||
import { OpenAiBridge } from './aibridge.classes.openaibridge.js';
|
||||
|
||||
export class AiBridge {
|
||||
public projectinfo: plugins.projectinfo.ProjectInfo;
|
||||
public serverInstance: plugins.loleServiceserver.ServiceServer;
|
||||
public serviceQenv = new plugins.qenv.Qenv('./', './.nogit');
|
||||
public aibridgeDb: AiBridgeDb;
|
||||
|
||||
public openAiBridge: OpenAiBridge;
|
||||
|
||||
public typedrouter = new plugins.typedrequest.TypedRouter();
|
||||
|
||||
public async start() {
|
||||
this.aibridgeDb = new AiBridgeDb(this);
|
||||
await this.aibridgeDb.start();
|
||||
this.projectinfo = new plugins.projectinfo.ProjectInfo(paths.packageDir);
|
||||
this.openAiBridge = new OpenAiBridge(this);
|
||||
await this.openAiBridge.start();
|
||||
|
||||
// server
|
||||
this.serverInstance = new plugins.loleServiceserver.ServiceServer({
|
||||
serviceDomain: 'aibridge.lossless.one',
|
||||
serviceName: 'aibridge',
|
||||
serviceVersion: this.projectinfo.npm.version,
|
||||
addCustomRoutes: async (serverArg) => {
|
||||
// any custom route configs go here
|
||||
},
|
||||
});
|
||||
|
||||
// lets implemenet the actual typedrequest functions
|
||||
this.typedrouter.addTypedHandler<plugins.lointAiBridge.requests.IReq_Chat>(new plugins.typedrequest.TypedHandler('chat', async reqArg => {
|
||||
const resultChat = await this.openAiBridge.chat(reqArg.chat.systemMessage, reqArg.chat.messages[reqArg.chat.messages.length - 1].content, reqArg.chat.messages);
|
||||
return {
|
||||
chat: reqArg.chat,
|
||||
latestMessage: resultChat.message.content,
|
||||
}
|
||||
}))
|
||||
|
||||
await this.serverInstance.start();
|
||||
this.serverInstance.typedServer.typedrouter.addTypedRouter(this.typedrouter);
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
await this.serverInstance.stop();
|
||||
await this.aibridgeDb.stop();
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
import * as plugins from './aibridge.plugins.js';
|
||||
import { AiBridge } from './aibridge.classes.aibridge.js';
|
||||
|
||||
export class AiBridgeDb {
|
||||
public smartdataDb: plugins.smartdata.SmartdataDb;
|
||||
public aibridgeRef: AiBridge;
|
||||
|
||||
constructor(aibridgeRefArg: AiBridge) {
|
||||
this.aibridgeRef = aibridgeRefArg;
|
||||
}
|
||||
|
||||
public async start() {
|
||||
this.smartdataDb = new plugins.smartdata.SmartdataDb({
|
||||
mongoDbUser: await this.aibridgeRef.serviceQenv.getEnvVarOnDemand('MONGO_DB_USER'),
|
||||
mongoDbName: await this.aibridgeRef.serviceQenv.getEnvVarOnDemand('MONGO_DB_NAME'),
|
||||
mongoDbPass: await this.aibridgeRef.serviceQenv.getEnvVarOnDemand('MONGO_DB_PASS'),
|
||||
mongoDbUrl: await this.aibridgeRef.serviceQenv.getEnvVarOnDemand('MONGO_DB_URL'),
|
||||
});
|
||||
await this.smartdataDb.init();
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
await this.smartdataDb.close();
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
import { AiBridge } from './aibridge.classes.aibridge.js';
|
||||
import * as plugins from './aibridge.plugins.js';
|
||||
import * as paths from './aibridge.paths.js';
|
||||
|
||||
export class OpenAiBridge {
|
||||
public aiBridgeRef: AiBridge;
|
||||
public openAiApiClient: plugins.openai.default;
|
||||
constructor(aiBridgeRefArg: AiBridge) {
|
||||
this.aiBridgeRef = aiBridgeRefArg;
|
||||
}
|
||||
|
||||
public async start() {
|
||||
const openAiToken = await this.aiBridgeRef.serviceQenv.getEnvVarOnDemand('OPENAI_TOKEN');
|
||||
this.openAiApiClient = new plugins.openai.default({
|
||||
apiKey: openAiToken,
|
||||
dangerouslyAllowBrowser: true,
|
||||
});
|
||||
}
|
||||
|
||||
public async stop() {}
|
||||
|
||||
public async chat(
|
||||
systemMessage: string,
|
||||
userMessage: string,
|
||||
messageHistory: {
|
||||
role: 'assistant' | 'user';
|
||||
content: string;
|
||||
}[]
|
||||
) {
|
||||
const result = await this.openAiApiClient.chat.completions.create({
|
||||
model: 'gpt-4-turbo-preview',
|
||||
messages: [
|
||||
{ role: 'system', content: systemMessage },
|
||||
...messageHistory,
|
||||
{ role: 'user', content: userMessage },
|
||||
],
|
||||
});
|
||||
return {
|
||||
message: result.choices[0].message,
|
||||
};
|
||||
}
|
||||
|
||||
public async audio(messageArg: string) {
|
||||
const done = plugins.smartpromise.defer();
|
||||
const result = await this.openAiApiClient.audio.speech.create({
|
||||
model: 'tts-1-hd',
|
||||
input: messageArg,
|
||||
voice: 'nova',
|
||||
response_format: 'mp3',
|
||||
speed: 1,
|
||||
});
|
||||
const stream = result.body.pipe(plugins.smartfile.fsStream.createWriteStream(plugins.path.join(paths.nogitDir, 'output.mp3')));
|
||||
stream.on('finish', () => {
|
||||
done.resolve();
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
import * as plugins from './aibridge.plugins.js';
|
||||
|
||||
export const packageDir = plugins.path.join(
|
||||
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
||||
'../'
|
||||
);
|
||||
|
||||
export const assetsDir = plugins.path.join(
|
||||
packageDir,
|
||||
'./assets/'
|
||||
);
|
||||
|
||||
export const nogitDir = plugins.path.join(
|
||||
packageDir,
|
||||
'./.nogit/'
|
||||
);
|
@ -1,32 +0,0 @@
|
||||
// node native
|
||||
import * as path from 'path';
|
||||
|
||||
export { path };
|
||||
|
||||
// @losslessone_private scope
|
||||
import * as loleServiceserver from '@losslessone_private/lole-serviceserver';
|
||||
import * as lointAiBridge from '@losslessone_private/loint-aibridge';
|
||||
|
||||
export { loleServiceserver, lointAiBridge };
|
||||
|
||||
// apiglobal scope
|
||||
import * as typedrequest from '@api.global/typedrequest';
|
||||
|
||||
export {
|
||||
typedrequest,
|
||||
}
|
||||
|
||||
// pushrocks scope
|
||||
import * as projectinfo from '@push.rocks/projectinfo';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
import * as smartdata from '@push.rocks/smartdata';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
|
||||
export { projectinfo, qenv, smartdata, smartfile, smartpath, smartpromise };
|
||||
|
||||
// thirdparty scope
|
||||
import * as antrophic from '@anthropic-ai/sdk';
|
||||
import * as openai from 'openai';
|
||||
export { antrophic as anthropic, openai };
|
@ -1,17 +0,0 @@
|
||||
import { AiBridge } from './aibridge.classes.aibridge.js';
|
||||
|
||||
export {
|
||||
AiBridge,
|
||||
}
|
||||
|
||||
let aibridgeInstance: AiBridge;
|
||||
export const runCli = async () => {
|
||||
aibridgeInstance = new AiBridge();
|
||||
await aibridgeInstance.start();
|
||||
};
|
||||
|
||||
export const stop = async () => {
|
||||
if (aibridgeInstance) {
|
||||
await aibridgeInstance.stop();
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user