Socket
Book a DemoInstallSign in
Socket

h2ogpte

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

h2ogpte

Javascript client for H2OGPTe.

1.6.39
latest
npmnpm
Version published
Maintainers
1
Created
Source

H2OGPTe NodeJS/Typescript client

This client is experimental and subject to change.

Used for connecting to a Generative AI platform called H2OGPTe. See more at h2o.ai.

Installation

npm install h2ogpte

Auth

This client can authenticate in 2 ways.

  • Using H2OGPTE API token (h2ogpte.setup('<endpoint_url>', '<token>')). See <h2ogpteinstance/api>.
  • Using Azure Active Directory token (h2ogpte.setup('<endpoint_url>', '', '', '<azure_token>'))

Usage

import * as h2ogpte from 'h2ogpte'

async function main() {
  // Setup endpoint URL and access token.
  h2ogpte.setup(
    '<endpoint_url>',
    '<token>',
    '<optional CSRF token>',
    '<optional Active Directory token>'
  )

  // Create new collection with English as embedding model.
  const collectionID = await h2ogpte.createCollection(
    'Name',
    'Description',
    'English (bge-large-en-v1.5)'
  )

  // Create dummy File. In real world, it would come from filepicker (browser).
  const blob = new Blob(['This is some text content'], { type: 'text/plain' })

  // Upload the file
  const uploadID = await h2ogpte.uploadFile(
    new File([blob], 'myTextFile.txt', { type: 'text/plain' })
  )

  // Ingest the file.
  await h2ogpte.ingestUploads(
    'Ingesting documents',
    collectionID,
    [uploadID],
    false, // Generate document summaries.
    false // Generate document questions.
  )

  // Create a chat session.
  const { chatID } = await h2ogpte.createChatSession(collectionID)

  const onMessage = message => console.log(message)
  // Prepare a websocket client to start chatting. Pass onMessage callback.
  const socket = h2ogpte.Socket(onMessage)
  // Connect to server.
  const close = socket.connect()

  // Send a message.
  socket.send({
    t: 'cq',
    mode: 's',
    session_id: chatID,
    correlation_id: correlationID,
    body: 'Hello world',
    system_prompt: null,
    pre_prompt_query: null,
    prompt_query: null,
    pre_prompt_summary: null,
    prompt_summary: null,
    llm: null,
    llm_args: null,
    self_reflection_config: null,
    rag_config: null,
  })
  // Close the connection.
  close()

  // Fetch first 100 documents in a collection.
  const docs = await h2ogpte.listDocumentsInCollection(collectionID, 0, 99)
  // Summarize all documents in collection.
  const summaries = await Promise.all(
    docs.map(({ id }) => {
      return h2ogpte.createDocumentSummary(
        'Document summary',
        null,
        id,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null
      )
    })
  )
}

main()

Underlying REST API client

The client utilizes a generated REST API client for establishing communication with the H2OGPTe server. This generated layer is also accessible and documented here.

FAQs

Package last updated on 29 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.