A Node.js SDK for PromptQL API.
Run the following command:
npm install @hasura/promptql
- If you are new with PromptQL, follow the quickstart guide of PromptQL to create a project.
- Create a PromptQL API Key in project settings tab on https://console.hasura.io.
- Your Project API endpoint and security headers.
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)
});
The Natural Language Query API allows you to interact with PromptQL directly, sending messages and receiving responses.
function query(body: PromptQLQueryRequest, queryOptions?: FetchOptions) => Promise<QueryResponse>
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 a PromptQL program with your data.
function executeProgram: (body: PromptQLExecuteRequest, executeOptions?: FetchOptions) Promise<PromptQlExecutionResult>;