JavaScript
PromptDesk Javascript SDK
Install PromptDesk
To install PromptDesk, use npm:
npm install promptdesk
Initialization
You can call the prompt you build in the application by using the generate method.
import { PromptDesk } from 'promptdesk'; //ES6
//const { PromptDesk } = require('promptdesk'); //CommonJS
const pd = new PromptDesk({
apiKey: "YOUR_PROMPTDESK_API_KEY", //find in /settings
serviceUrl: "http://localhost"
})
You can find your API key in the application under Settings > Organization Information > API Key.
You can test out the service by pinging it:
console.log(pd.ping())
A successful ping will return "pong".
JavaScript SDK Walkthrough (6 minutes)
Usage
No variables
const yoda_response = pd.generate("yoda-test")
console.log(yoda_response)
With variables
const story = pd.generate("short-story-test", {
"setting": "dark and stormy night",
"character": "lonely farmer",
"plot": "visited by a stranger"
})
console.log(story)
Logs
You can view the logs of your prompt calls in the PromptDesk OS -> Logs. If you are having trouble, check the logs to see if there are any errors.