UNPKG

svector-sdk

Version:

Official JavaScript and TypeScript SDK for accessing SVECTOR APIs.

34 lines (33 loc) 1.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const src_1 = require("../src"); async function streamingChat() { const client = new src_1.SVECTOR({ apiKey: process.env.SVECTOR_API_KEY, }); try { console.log('Starting streaming chat...\n'); const stream = await client.chat.createStream({ model: 'spec-3-turbo', messages: [ { role: 'system', content: 'You are a creative storyteller who writes engaging short stories.' }, { role: 'user', content: 'Tell me a short story about a robot learning to paint' } ], temperature: 0.8, stream: true, }); console.log('Response: '); for await (const event of stream) { if (event.choices?.[0]?.delta?.content) { process.stdout.write(event.choices[0].delta.content); } } console.log('\n\nStreaming completed!'); } catch (error) { console.error('Error:', error); } } if (require.main === module) { streamingChat(); }