view-sdk
v1.0.4
Published
View SDK for JavaScript
Readme
JavaScript SDK for View AI
View AI enables organizations to rapidly deploy conversational AI experiences and yield instant insights. This SDK provides a simplified interface for consuming View AI configuration services in JavaScript applications.
License
View software is licensed under the Fair Core License (FCL) with graduation after two years to an Apache 2.0 license. Use of the software requires acceptance of the license terms found in the file LICENSE.md.
Requirements
- Node.js v18.20.4
- npm
Dependencies
Use the command npm i to install dependencies.
Installation
Install the SDK using npm:
npm install view-sdkGetting Started
Following below is the example of JS code utilizing the sdk:
Basic Configuration
import { ViewConfigurationSdk } from 'view-sdk';
const api = new ViewConfigurationSdk(
'http://view.homedns.org:8000', //endpoint
'<tenantId>', //tenant Id
'******' //access token
);Available Services
The SDK provides access to the following services:
- Assistant: AI assistant management and interactions
- Configuration: System configuration and settings management
- Blobs, Credentials, Data Repositories
- Encryption Keys, Graph Repositories
- Nodes, Tenants, Users
- Vector Repositories, Webhooks
- Lexi: Natural language processing capabilities
- Processor: Data processing and transformation
- Semantic: Semantic analysis and processing
- Storage: Data storage operations
- Vector: Vector operations and similarity search
- IngestQueue: Manage ingest queue operations
- Embeddings: Embedding operations
- Healthcheck: Healthcheck operations
- Crawler: Crawler operations
- Director: Director operations
Example Usage
// region Nodes
const getNode = async () => {
try {
const nodes = await api.Nodes.read('<nodeId>');
console.log(nodes, 'Nodes fetched successfully');
} catch (err) {
console.log('Error fetching Nodes:', err);
}
};
getNode();Example Usage with Tenant
const createTenant = async () => {
try {
const createdTenant = await api.Tenant.create({
Name: 'My tenant',
Region: 'us-west-1',
S3BaseDomain: 'localhost',
RestBaseDomain: 'localhost',
DefaultPoolGUID: '00000000-0000-0000-0000-000000000000',
});
console.log(createdTenant, 'Tenant created successfully');
} catch (err) {
console.log('Error creating Tenant:', err);
}
};
createTenant();Example Usage with Credentials
// region Credentials
export const createCredential = async () => {
try {
const response = await api.Credential.create({
UserGUID: '<userId>',
Name: 'Default credential',
Active: true,
});
console.log(response, 'Credential created successfully');
} catch (err) {
console.log('Error creating Credential:', err);
}
};
createCredential();// region Credentials
export const getAllCredentials = async () => {
try {
const credentials = await api.Credential.readAll();
console.log(credentials, 'All credentials fetched successfully');
} catch (err) {
console.log('Error fetching Credentials:', err);
}
};
getAllCredentials();Example Usage with User
export const createUser = async () => {
try {
const user = await api.User.create({
FirstName: 'John',
LastName: 'Doe',
Notes: 'Default password is password',
Email: '[email protected]',
PasswordSha256: '******',
});
console.log(user, 'User created successfully');
} catch (err) {
console.log('Error creating User:', err);
}
};
createUser();Example Usage with Vector Repository
// region Vector Repositories
const createVectorRepository = async () => {
try {
const response = await api.VectorRepository.create({
Name: 'My vector repository ash 3',
RepositoryType: 'Pgvector' as any,
Model: 'all-MiniLM-L6-v2',
Dimensionality: 384,
DatabaseHostname: 'localhost',
DatabaseName: 'vectordb',
SchemaName: 'public',
DatabaseTable: 'minilm',
DatabasePort: 5432,
DatabaseUser: 'postgres',
DatabasePassword: 'password',
});
console.log(response, 'Vector repository created successfully');
} catch (err) {
console.log('Error creating Vector repository:', err);
}
};
createVectorRepository();Example Usage with Graph Repository
// region Graph Repositories
const createGraphRepository = async () => {
try {
const response = await api.GraphRepository.create({
Name: 'My LiteGraph instance ash 3',
RepositoryType: 'LiteGraph',
EndpointUrl: 'http://localhost:8701/',
ApiKey: 'default',
GraphIdentifier: '00000000-0000-0000-0000-000000000000',
});
console.log(response, 'Graph repository created successfully');
} catch (err) {
console.log('Error creating Graph repository:', err);
}
};
createGraphRepository();const graphRepositoryExists = async () => {
try {
const response = await api.GraphRepository.exists('<graphRepositoryId>');
console.log(response, 'Graph repository exists');
} catch (err) {
console.log('Error checking Graph repository:', err);
}
};
graphRepositoryExists();const readGraphRepository = async () => {
try {
const response = await api.GraphRepository.read('<graphRepositoryId>');
console.log(response, 'Graph repository fetched successfully');
} catch (err) {
console.log('Error fetching Graph repository:', err);
}
};
readGraphRepository();const getAllGraphRepositories = async () => {
try {
const data = await api.GraphRepository.readAll();
console.log(data, 'All graph repositories fetched successfully');
} catch (err) {
console.log('Error fetching Graph repositories:', err);
}
};
getAllGraphRepositories();Contributing
We welcome contributions! Please see our Contributing Guidelines for details.
Support
For support, please:
- Check the documentation
- Open an issue on GitHub
- Contact View AI support
Development
Setting up Pre-commit Hooks
The pre-commit hooks will run automatically on git commit. They help maintain:
- Code formatting (using ruff)
- Import sorting
- Code quality checks
- And other project-specific checks
Running Tests
The project uses jest for running tests in isolated environments. Make sure you have jest installed, which should automatically be there if you have installed dependencies via npm i command:
# Run only the tests
npm run test
# Run tests with coverage report
npm run test:coverage
# Build the package
npm run build
Development Installation
Linking view-sdk dependency locally
To use the library locally without publishing to a remote npm registry, first install the dependencies with the command:
npm installNext, link it globally in local system's npm with the following command:
npm linkTo use the link you just defined in your project, switch to the directory you want to use your view-sdk from, and run:
npm link view-sdkFinally, you need to build the sdk, use command:
npm run buildYou can then import the SDK with either import or require based on the ES Module (esm) or CommonJS (cjs) project, as shown below:
import sdk from 'view-sdk';
//or
var sdk = require('view-sdk');Feedback and Issues
Have feedback or found an issue? Please file an issue in our GitHub repository.
Documentation
For detailed API documentation and examples, visit View Documentation.
Version History
Please refer to CHANGELOG.md for a detailed version history.
