<aside> ⚠️ Javascript support is experimental and will not be updated as frequently as the Python one. Follow @promptlayer for updates and check back here for Javascript requirements.
</aside>
PromptLayer is available through LangChain’s Javascript library: https://github.com/hwchase17/langchainjs
Learn more at: https://hwchase17.github.io/langchainjs/docs/modules/llms/openai/#promptlayer-openai
To get started, create an account by clicking “Log in” on PromptLayer. Once logged in, click the button to create an API key and save this in a secure location.
We do not have an npm
library yet, but in the meantime we have a wrapper function to our API. You can find it in our github repo under MagnivOrg/promptlayer-js-helper
https://github.com/MagnivOrg/promptlayer-js-helper
To use this function add the file to your workspace and import promptLayer
to wherever you are making an openAI API call.
The promptLayer
function takes the following inputs
promptLayer(
tags, // a list of tags to be used in the promptlayer dashboard
prompt, // the prompt used
engine, // the openAI engine used in the request
requestResponse, // the openAI response (response.data)
requestStartTime, // the start time of the request
requestEndTime // the time the request returned
)
Be sure to set your PromptLayer API key as the environment variable PROMPTLAYER_API_KEY
Here is an end-to-end example:
import promptLayer from './promptlayer.js';
import { Configuration, OpenAIApi } from "openai";
// Create a new OpenAI API client
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
// Make a request to the OpenAI API
const model = "text-davinci-003";
const prompt = "Q: How do I combine arrays in Javascript?\\nA:";
const requestStartTime = Date.now()
const response = await openai.createCompletion({
model: model,
prompt: prompt
});
const requestEndTime = Date.now()
// Log the request in PromptLayer
promptLayer(['js-test'], prompt, model, response.data, requestStartTime, requestEndTime);