h2ogpte
v1.6.43
Published
Javascript client for H2OGPTe.
Readme
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 h2ogpteAuth
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>')
// Or setup for Azure only.
h2ogpte.setupForAzure('<endpoint_url>', '<Active Directory token>', '<optional CSRF token>')
// Or setup with JWT token only
h2ogpte.setupForJWT(
'<endpoint_url>',
'<JWT token>',
'<optional CSRF token>',
'<optional session ID>'
)
// 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.
