Skip to content

hasura/promptql-nodejs-sdk

Repository files navigation

PromptQL NodeJS SDK

A Node.js SDK for PromptQL API.

Install

Run the following command:

npm install @hasura/promptql

Get started

Prerequisite

Use PromptQL SDK

Create the PromptQL client with required configurations:

import { createPromptQLClient } from '@hasura/promptql';

const client = createPromptQLClient({
    apiKey: '<your-promptql-api-key>',
    ddn: {
        url: '<your-project-endpoint>',
        headers: {
            'Authorization': '<credential>'
        }
    },
    // You can define a lazy function for the ddn options.
    //
    // ddn: () => {{ 
    //     url: '<your-project-endpoint>',
    //     headers: {
    //         'Authorization': '<credential>'
    //     }
    // }}  
});

const runQuery = (text: string) => {
    return client.query({
        artifacts: [],
        interactions: [
            {
                user_message: {
                    text,
                }
            }
        ],
        ddn: {
            // you can override the default ddn config, 
            // for example, dynamic auth credentials
            headers: {}
        }
    });

    return response.
}

runQuery('what can you do?').then((response) => {
    console.log(response)
});

Reference

Natural Language

The Natural Language Query API allows you to interact with PromptQL directly, sending messages and receiving responses.

Non-Streaming

function query(body: PromptQLQueryRequest, queryOptions?: FetchOptions) => Promise<QueryResponse>

Streaming

The streaming response sends chunks of data in Server-Sent Events (SSE) format. If the callback isn't set the client returns the raw response and you need to handle the response manually.

function queryStream: (body: PromptQLQueryRequest, callback?: (data: QueryResponseChunk) => void | Promise<void>, queryOptions?: FetchOptions) Promise<Response>;

Example:

client
    .queryStream({
        artifacts: [],
        interactions: [
            user_message: {
                text: 'what can you do?',
            }
        ],
    },
    async (chunk) => {
        console.error(chunk);
    },
);

Execute Program

Execute a PromptQL program with your data.

function executeProgram: (body: PromptQLExecuteRequest, executeOptions?: FetchOptions) Promise<PromptQlExecutionResult>;

About

A Node.js SDK for PromptQL API

Resources

License

Stars

Watchers

Forks

Packages

No packages published