npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

privategpt-sdk-web

v0.1.1

Published

The PrivateGPT TypeScript SDK is a powerful open-source library that allows developers to work with AI in a private and secure manner. This SDK provides a set of tools and utilities to interact with the PrivateGPT API and leverage its capabilities.

Downloads

52

Readme

PrivateGPT TypeScript SDK

The PrivateGPT TypeScript SDK is a powerful open-source library that allows developers to work with AI in a private and secure manner. This SDK provides a set of tools and utilities to interact with the PrivateGPT API and leverage its capabilities.

Live demo

Source demo

Installation

npm install privategpt-ts

Usage (plain typescript)

Initialize client

First you need to initalize the PrivategptApiClient:

const pgptApiClient = new PrivategptApiClient({ environment: 'http://localhost:8001' });

Ingest file

import { pgptApiClient } from 'your/path';

const file = getFileFromSomewhere();
const ingestResponse = await pgptApiClient.ingestion.ingestFile(file);

Get ingested files

import { pgptApiClient } from 'your/path';

const ingestResponse = await pgptApiClient.ingestion.listIngested();

Delete ingested file

import { pgptApiClient } from 'your/path';

await pgptApiClient.ingestion.deleteIngested(docId);

Chat completion

import { pgptApiClient } from 'your/path';

// stream way
const stream = await pgptApiClient.completion.chatCompletionStream({
  messages: [
    {
      content: 'How are you',
      role: 'user'
    }
  ],
  includeSources: true,
  useContext: true
});
const readableStream = streamToReadableStream(stream);
const reader = readableStream.getReader();
const decoder = createChunkDecoder();
const loopRunner = true;
let result = '';

while (loopRunner) {
  const { value, done } = await reader.read();
  if (done) {
    break;
  }
  const decodedChunk = decoder(value);
  if (!decodedChunk) continue;
  result += decoder(value);
  onNewMessage?.(result);
}
return result;

// async way
const openAiCompletionResponse = await pgptApiClient.completion.chatCompletionStream({
  messages: [
    {
      content: 'How are you',
      role: 'user'
    }
  ],
  includeSources: true,
  useContext: true
});

Prompt completion

import { pgptApiClient } from 'your/path';

// stream way
const stream = await pgptApiClient.completion.promptCompletionStream({
  promt: 'Hello! Make a joke',
  includeSources: true,
  useContext: true
});
const readableStream = streamToReadableStream(stream);
const reader = readableStream.getReader();
const decoder = createChunkDecoder();
const loopRunner = true;
let result = '';

while (loopRunner) {
  const { value, done } = await reader.read();
  if (done) {
    break;
  }
  const decodedChunk = decoder(value);
  if (!decodedChunk) continue;
  result += decoder(value);
  onNewMessage?.(result);
}
return result;

// async way
const openAiCompletionResponse = await pgptApiClient.completion.promptCompletion({
  promt: 'Hello! Make a joke',
  includeSources: true,
  useContext: true
});

Get ingested files

import { pgptApiClient } from 'your/path';

const ingestResponse = await pgptApiClient.ingestion.listIngested();

Delete ingested file

import { pgptApiClient } from 'your/path';

await pgptApiClient.ingestion.deleteIngested(docId);

Chat completion

import { pgptApiClient } from 'your/path';

// stream way
const stream = await pgptApiClient.completion.chatCompletionStream({
  messages: [
    {
      content: 'How are you',
      role: 'user'
    }
  ],
  includeSources: true,
  useContext: true
});
const readableStream = streamToReadableStream(stream);
const reader = readableStream.getReader();
const decoder = createChunkDecoder();
const loopRunner = true;
let result = '';

while (loopRunner) {
  const { value, done } = await reader.read();
  if (done) {
    break;
  }
  const decodedChunk = decoder(value);
  if (!decodedChunk) continue;
  result += decoder(value);
  onNewMessage?.(result);
}
return result;

// async way
const openAiCompletionResponse = await pgptApiClient.completion.chatCompletionStream({
  messages: [
    {
      content: 'How are you',
      role: 'user'
    }
  ],
  includeSources: true,
  useContext: true
});

Prompt completion

import { pgptApiClient } from 'your/path';

// stream way
const stream = await pgptApiClient.completion.promptCompletionStream({
  promt: 'Hello! Make a joke',
  includeSources: true,
  useContext: true
});
const readableStream = streamToReadableStream(stream);
const reader = readableStream.getReader();
const decoder = createChunkDecoder();
const loopRunner = true;
let result = '';

while (loopRunner) {
  const { value, done } = await reader.read();
  if (done) {
    break;
  }
  const decodedChunk = decoder(value);
  if (!decodedChunk) continue;
  result += decoder(value);
  onNewMessage?.(result);
}
return result;

// async way
const openAiCompletionResponse = await pgptApiClient.completion.promptCompletion({
  promt: 'Hello! Make a joke',
  includeSources: true,
  useContext: true
});

Usage (react adapter)

Initialize client

First you need to initalize the PrivategptApiClient:

const pgptApiClient = new PrivategptApiClient({ environment: 'http://localhost:8001' });

useFiles (ingest file, delete file, get ingested files)

import { pgptApiClient } from 'your/path';

const YourComponent = () => {
  const {
    addFile,
    isUploadingFile,
    isDeletingFile,
    files,
    deleteFile,
    isFetchingFiles,
    errorDeletingFile,
    errorFetchingFiles,
    errorUploadingFile,
  } = useFiles({
    client: pgptApiClient,
    fetchFiles: true // in case you don't want to fetch files automatically when using this hook
  });
}

useChat (chat completion)

import { pgptApiClient } from 'your/path';

const YourComponent = () => {
  const {
    stop,
    isLoading,
    completion,
    setCompletion
  } = useChat({
    messages: [
      {
        content: 'Hello, how are you?',
        role: 'user'
      }
    ],
    includeSources: true,
    useContext: true,
    onFinish: () => {
      console.log('finished streaming');
    },
    client: pgptApiClient,
    systemPrompt: 'You are a character from Battlestar Galactica'
  });
}

usePrompt (prompt completion)

import { pgptApiClient } from 'your/path';

const YourComponent = () => {
  const {
    stop,
    isLoading,
    completion,
    setCompletion
  } = useChat({
    prompt: 'Hello, make a joke in japanese',
    includeSources: true,
    useContext: true,
    onFinish: () => {
      console.log('finished streaming');
    },
    client: pgptApiClient,
    systemPrompt: 'You are a japanese chef'
  });
}