- Add IOllamaModelOptions interface for runtime options (num_ctx, temperature, etc.) - Extend IOllamaProviderOptions with defaultOptions and defaultTimeout - Add IOllamaChatOptions for per-request overrides - Add IOllamaStreamChunk and IOllamaChatResponse interfaces - Add chatStreamResponse() for async iteration with options - Add collectStreamResponse() for streaming with progress callback - Add chatWithOptions() for non-streaming with full options - Update chat() to use defaultOptions and defaultTimeout
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
|
import * as qenv from '@push.rocks/qenv';
|
|
import { SmartFs, SmartFsProviderNode } from '@push.rocks/smartfs';
|
|
|
|
const testQenv = new qenv.Qenv('./', './.nogit/');
|
|
const smartfs = new SmartFs(new SmartFsProviderNode());
|
|
|
|
import * as smartai from '../ts/index.js';
|
|
|
|
let testSmartai: smartai.SmartAi;
|
|
|
|
tap.test('OpenAI Audio: 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 Audio: should create audio response', async () => {
|
|
// Call the audio method with a sample message.
|
|
const audioStream = await testSmartai.openaiProvider.audio({
|
|
message: 'This is a test of audio generation.',
|
|
});
|
|
// Read all chunks from the stream.
|
|
const chunks: Uint8Array[] = [];
|
|
for await (const chunk of audioStream) {
|
|
chunks.push(chunk as Uint8Array);
|
|
}
|
|
const audioBuffer = Buffer.concat(chunks);
|
|
await smartfs.file('./.nogit/testoutput.mp3').write(audioBuffer);
|
|
console.log(`Audio Buffer length: ${audioBuffer.length}`);
|
|
// Assert that the resulting buffer is not empty.
|
|
expect(audioBuffer.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
tap.test('OpenAI Audio: should stop the smartai instance', async () => {
|
|
await testSmartai.stop();
|
|
});
|
|
|
|
export default tap.start();
|