35 lines
1021 B
TypeScript
35 lines
1021 B
TypeScript
|
import { expect, tap } from '@push.rocks/tapbundle';
|
||
|
import * as qenv from '@push.rocks/qenv';
|
||
|
|
||
|
const testQenv = new qenv.Qenv('./', './.nogit/');
|
||
|
|
||
|
import * as smartai from '../ts/index.js';
|
||
|
|
||
|
let testSmartai: smartai.SmartAi;
|
||
|
|
||
|
tap.test('OpenAI Chat: should create a smartai instance with OpenAI provider', async () => {
|
||
|
testSmartai = new smartai.SmartAi({
|
||
|
openaiToken: await testQenv.getEnvVarOnDemand('OPENAI_TOKEN'),
|
||
|
});
|
||
|
await testSmartai.start();
|
||
|
});
|
||
|
|
||
|
tap.test('OpenAI Chat: should create chat response', async () => {
|
||
|
const userMessage = 'How are you?';
|
||
|
const response = await testSmartai.openaiProvider.chat({
|
||
|
systemMessage: 'Hello',
|
||
|
userMessage: userMessage,
|
||
|
messageHistory: [],
|
||
|
});
|
||
|
console.log(`userMessage: ${userMessage}`);
|
||
|
console.log(response.message);
|
||
|
expect(response.role).toEqual('assistant');
|
||
|
expect(response.message).toBeTruthy();
|
||
|
});
|
||
|
|
||
|
tap.test('OpenAI Chat: should stop the smartai instance', async () => {
|
||
|
await testSmartai.stop();
|
||
|
});
|
||
|
|
||
|
export default tap.start();
|