svector-sdk
Version:
Official JavaScript and TypeScript SDK for accessing SVECTOR APIs.
55 lines (51 loc) • 2.16 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const src_1 = require("../src");
async function fileUploadExample() {
const client = new src_1.SVECTOR({
apiKey: process.env.SVECTOR_API_KEY,
});
try {
const sampleContent = `
SVECTOR Corporation Overview
SVECTOR is a leading AI and machine learning company that provides advanced
language models and AI solutions. Our flagship product, Spec-Chat, offers
state-of-the-art conversational AI capabilities with support for:
- Advanced natural language understanding
- Retrieval Augmented Generation (RAG)
- Multi-modal processing
- Enterprise-grade security and scalability
Founded in 2023, SVECTOR has quickly become a trusted partner for businesses
looking to integrate AI into their workflows and applications.
`;
const tempFile = path_1.default.join(__dirname, 'sample-document.txt');
fs_1.default.writeFileSync(tempFile, sampleContent);
console.log('Uploading file...');
const fileResponse = await client.files.create(fs_1.default.createReadStream(tempFile), 'default');
console.log(`File uploaded successfully! File ID: ${fileResponse.file_id}`);
console.log('\nAsking question about the uploaded document...');
const chatResponse = await client.chat.create({
model: 'spec-3-turbo',
messages: [
{ role: 'user', content: 'What is SVECTOR Corporation and what products do they offer?' }
],
files: [
{ type: 'file', id: fileResponse.file_id }
],
});
console.log('\nResponse from document:', chatResponse.choices[0].message.content);
fs_1.default.unlinkSync(tempFile);
console.log('\nCleanup completed!');
}
catch (error) {
console.error('Error:', error);
}
}
if (require.main === module) {
fileUploadExample();
}