1.0.12 • Published 9 months ago

castleguard-sdk v1.0.12

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

CastleGuard SDK

The castleguard-sdk is a TypeScript/JavaScript SDK designed to interact with CastleGuard AI's APIs. It provides functionalities such as chat, translation, transcription, named entity recognition (NER), and more. This SDK enables seamless integration of CastleGuard AI capabilities into your applications.


Features

  • Authentication: Simplified authentication with CastleGuard AI APIs.
  • Chat: Interact with AI chat models, including context-based conversations using collections.
  • Translation: Translate text between languages with high accuracy.
  • Named Entity Recognition (NER): Extract structured entities like names, organizations, and locations from text.
  • Transcription: Upload audio files and retrieve high-quality transcriptions.
  • Collections: Manage document collections for organized data querying.
  • Vision: Perform AI-powered vision tasks such as image analysis.
  • Heartbeat: Monitor the system health and component status.
  • Text Extraction: Extract text from raw input or binary documents.

Installation

Install the SDK via NPM:

npm install castleguard-sdk

Getting Started

Import the SDK

Start by importing the CastleGuard class and initializing it with your API credentials:

import { CastleGuard } from 'castleguard-sdk';

const sdk = new CastleGuard('https://api.castleguard.com', 'your-username', 'your-password');

Usage Examples

1. Log a Message

Send logs to the CastleGuard logging endpoint:

sdk.log('This is a test log message', 1);

2. Chat with the Model

Send a prompt to the AI model and receive a response:

(async () => {
  const [response, chatId] = await sdk.chat('What is the capital of Canada?');
  console.log(response); // Expected output: "Ottawa"
})();

3. Chat with a Collection

Send a prompt to the AI model using a specific collection of documents:

(async () => {
  const collectionId = 'your-collection-id';
  const [response, chatId] = await sdk.chatWithCollection('Summarize this collection.', collectionId);
  console.log(response);
})();

4. Translate Text

Translate text from English to French:

(async () => {
  const translation = await sdk.translateText('Hello, world!', 'en', 'fr');
  console.log(translation); // Expected output: "Bonjour, le monde!"
})();

5. Perform Named Entity Recognition (NER)

Extract entities from a text:

(async () => {
  const entities = await sdk.namedEntityRecognition('John works at Microsoft in Seattle.');
  console.log(entities);
})();

6. Transcribe an Audio File

Upload an audio file and retrieve the transcription:

(async () => {
  const documentId = await sdk.transcribe('/path/to/audio/file.mp3');
  console.log(documentId);
})();

7. Create a Collection

Create a new collection for organizing documents:

(async () => {
  const collectionId = await sdk.createCollection('Test Collection', 'A collection for testing purposes');
  console.log(`Collection ID: ${collectionId}`);
})();

8. Upload a File to a Collection

Upload a document to an existing collection:

(async () => {
  const success = await sdk.uploadToCollection('your-collection-id', '/path/to/file.pdf');
  console.log(`File upload successful: ${success}`);
})();

9. Extract Text from Raw Input

Extract structured paragraphs from raw text:

(async () => {
  const paragraphs = await sdk.textExtraction('This is a test paragraph.\n\nAnother test paragraph.');
  console.log(paragraphs);
})();

10. Monitor System Health

Check the health status of system components:

(async () => {
  const healthStatus = await sdk.heartbeat();
  console.log(healthStatus);
})();

API Reference

CastleGuard Class

Constructor

new CastleGuard(baseUrl: string, username: string, password: string, defaultVersion: string = "v1")
  • baseUrl: The base URL of the CastleGuard API.
  • username: Your username for authentication.
  • password: Your password for authentication.
  • defaultVersion: (Optional) The default API version. Defaults to v1.

Methods

  • log(message: string, logLevel: number): Promise<void>
    Logs a message to the CastleGuard logging endpoint.

  • chat(prompt: string, chatId?: string): Promise<[string | null, string | null]>
    Sends a prompt to the chat endpoint and retrieves a response.

  • chatWithCollection(prompt: string, collectionId: string): Promise<[string | null, string | null]>
    Sends a prompt to the chat endpoint with a specific collection.

  • translateText(text: string, sourceLang: string, targetLang: string): Promise<string | null>
    Translates text from one language to another.

  • namedEntityRecognition(text: string): Promise<any>
    Performs named entity recognition on the input text.

  • transcribe(filePath: string): Promise<string | null>
    Uploads an audio file and retrieves a transcription.

  • createCollection(name: string, description: string): Promise<string | null>
    Creates a new document collection.

  • uploadToCollection(collectionId: string, filePath: string): Promise<boolean>
    Uploads a file to a specified collection.

  • heartbeat(): Promise<any>
    Checks the health status of system components.

  • textExtraction(rawText: string): Promise<string[] | null>
    Extracts paragraphs from raw text.

  • textExtractionFromDocument(filePath: string): Promise<any>
    Extracts text from a binary document file.

  • vision(prompt: string, filePath: string): Promise<any>
    Performs vision-related tasks.


Development

Prerequisites

  • Node.js 16+
  • TypeScript 4.5+

Build

Compile the TypeScript code into JavaScript:

npm run build

Test

Run tests (if applicable):

npm test

Contributing

Contributions are welcome! Feel free to submit a pull request or open an issue.


License

This project is licensed under the MIT License. See the LICENSE file for details.


Support

For support or questions, please contact support@castleguard.com.

1.0.12

9 months ago

1.0.11

9 months ago

1.0.10

9 months ago