uncloseai.com/languages/javascript/openai/nodejs/uncloseai.js

65 lines
1.9 KiB
JavaScript

import OpenAI from 'openai';
import fs from 'fs';
console.log('=== UncloseAI Node.js Client (Official OpenAI SDK) ===\n');
// Non-streaming chat with Hermes
console.log('=== Non-Streaming Chat (Hermes) ===');
const hermesClient = new OpenAI({
apiKey: 'dummy-key',
baseURL: 'https://hermes.ai.unturf.com/v1'
});
const hermesResponse = await hermesClient.chat.completions.create({
model: 'adamo1139/Hermes-3-Llama-3.1-8B-FP8-Dynamic',
messages: [
{ role: 'user', content: 'Give a Python Fizzbuzz solution in one line of code?' }
],
temperature: 0.5,
max_tokens: 150
});
console.log(`Response: ${hermesResponse.choices[0].message.content}\n`);
// Streaming chat with Qwen
console.log('=== Streaming Chat (Qwen) ===');
const qwenClient = new OpenAI({
apiKey: 'dummy-key',
baseURL: 'https://qwen.ai.unturf.com/v1'
});
const qwenStream = await qwenClient.chat.completions.create({
model: 'hf.co/unsloth/Qwen3-Coder-30B-A3B-Instruct-GGUF:Q4_K_M',
messages: [
{ role: 'user', content: 'Give a Python Fizzbuzz solution in one line of code?' }
],
temperature: 0.5,
max_tokens: 150,
stream: true
});
process.stdout.write('Response: ');
for await (const chunk of qwenStream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}
console.log('\n');
// TTS example
console.log('=== TTS Speech Generation ===');
const ttsClient = new OpenAI({
apiKey: 'YOLO',
baseURL: 'https://speech.ai.unturf.com/v1'
});
const mp3 = await ttsClient.audio.speech.create({
model: 'tts-1',
voice: 'alloy',
input: 'I think so therefore, Today is a wonderful day to grow something people love!',
speed: 0.9
});
const buffer = Buffer.from(await mp3.arrayBuffer());
fs.writeFileSync('speech.mp3', buffer);
console.log(`[OK] Speech file created: speech.mp3 (${buffer.length} bytes)\n`);
console.log('=== Examples Complete ===');