1. Import Langchain Hub and Portkey Libraries
Why not explore the prompts listed on the Prompts Hub? Meanwhile, let’s boot up the NodeJS environment and start importing libraries —langchain
and portkey-ai
2. Pull a Prompt from Langchain Hub
Next up, let’s try to get the Prompt details using thehub
API
Pass the label of the repository on as an argument to pull
method as follows:
3. Make the API Call using Portkey
The model we will request is going to be OpenAI’s GPT4. Sincegpt-4
accepts System and User roles, let’s prepare them.
messages
to the chat completions call as an argument to the response.
4. Explore the Logs
The prompt we used consisted of approximately 1300 tokens and cost around 5.5 cents. This information can be found on Portkey’s Logs page, which provides valuable data such as the time it took for the request to be processed, dates, and a snapshot of the request headers and body. Read about all the observability features you get in the docs. Congratulations! You now have the skills to access a prompt from the Langchain hub through programming and use it to make an API request to GPT4. Try out a quick experiment by tweaking your prompt from the Langchain hub and trying out the Claude2.1 model. You’ll be amazed at what you can achieve!See the full code
See the full code